forked from rambo412/SyncSaber
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f53e80b
commit de51591
Showing
6 changed files
with
42 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,49 @@ | ||
using SyncSaber.NetWorks; | ||
using SyncSaber.SimpleJSON; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SyncSaber.ScoreSabers | ||
{ | ||
public static class ScoreSaberManager | ||
{ | ||
public const string BASEURL = "https://scoresaber.com/api.php"; | ||
|
||
public const string BASEURL = "https://scoresaber.com"; | ||
public static async Task<JSONArray> Ranked(int songcouts, RankSort sort) | ||
{ | ||
var url = $"/api.php?function=get-leaderboards&cat={(int)sort}&ranked=1&limit={songcouts}&page=1&unique=1"; | ||
var buff = await WebClient.GetAsync($"{BASEURL}{url}", new CancellationTokenSource().Token); | ||
if (buff == null) { | ||
return null; | ||
} | ||
var json = JSON.Parse(buff.ContentToString()); | ||
if (json["songs"] == null) { | ||
return null; | ||
} | ||
|
||
return json["songs"] as JSONArray; | ||
var pageCount = 0; | ||
var results = new JSONArray(); | ||
do { | ||
var url = $"/api/leaderboards?ranked=true&category={(int)sort}&sort=0&unique=true&page={pageCount}"; | ||
var buff = await WebClient.GetAsync($"{BASEURL}{url}", new CancellationTokenSource().Token); | ||
if (buff == null) { | ||
return null; | ||
} | ||
var json = JSON.Parse(buff.ContentToString()); | ||
if (json["leaderboards"] == null || !json["leaderboards"].IsArray) { | ||
return null; | ||
} | ||
var rankSongs = json["leaderboards"].AsArray; | ||
foreach (var song in rankSongs.Values) { | ||
results.Add(song.AsObject); | ||
if (songcouts <= results.Count) { | ||
break; | ||
} | ||
} | ||
pageCount++; | ||
} while (results.Count < songcouts); | ||
return results; | ||
} | ||
|
||
/// <summary> | ||
/// Which category to sort by (0 = trending, date ranked = 1, scores set = 2, star difficulty = 3, author = 4) | ||
/// </summary> | ||
public enum RankSort | ||
{ | ||
DateRanked = 1, | ||
Difficurity = 3 | ||
Trending, | ||
DateRanked, | ||
ScoreSet, | ||
StarDifficulity, | ||
Author | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters