· 6 years ago · Feb 07, 2020, 11:34 PM
1// Get your API key from https://osu.ppy.sh/p/api
2var token = "API_Key_Here"
3var ss = SpreadsheetApp.getActiveSpreadsheet();
4// The placeholder here is for the name of the specific page on your sheet where your qualifier MP links are listed.
5var qualsheet = ss.getSheetByName("placeholder");
6var linksheet = ss.getSheetByName("placeholder");
7
8// This function retrieves MP data from the osu! get_match API endpoint.
9function getMatchData(matchID) {
10 var url = "https://osu.ppy.sh/api/get_match?k=" + token + "&mp=" + matchID;
11 var response = UrlFetchApp.fetch(url);
12 var json = response.getContentText();
13 return JSON.parse(json);
14}
15
16function updateSheet() {
17 var row = 1;
18 // The following line assumes your MP links are in column A; change that reference if they're in a different column.
19 var mplinks = linksheet.getRange("A1:A").getValues().filter(String);
20 mplinks.forEach(function(link){
21 // slice(37) to remove the parts of the MP link that are before the actual match ID. This requires use of new MP links (https://osu.ppy.sh/community/matches/12345678).
22 var matchID = link.toString().slice(37);
23 var results = getMatchData(matchID);
24 results["games"].forEach(function(game){
25 game["scores"].forEach(function(score){
26 if(score["score"]){
27 qualsheet.getRange(row, 2, 1, 3).setValues(
28 [[
29 game["beatmap_id"],
30 score["user_id"],
31 score["score"]
32 // This returns beatmap ID, user ID, and score for every map played in an MP link. If you're familiar with the get_match API you can add other data to return (such as accuracy components -- be aware those have to be parsed on your end because it's not stored as its own integer); you'll just need to adjust the range you're returning the data to (in line 27).
33 ]]);
34 row++;
35 }
36 });
37 });
38 });
39}