Skip to content

Commit

Permalink
Fix new scoresaber api
Browse files Browse the repository at this point in the history
  • Loading branch information
denpadokei committed Nov 22, 2021
1 parent f53e80b commit de51591
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
3 changes: 3 additions & 0 deletions SyncSaber/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using IPA.Config.Stores;
using IPA.Config.Stores.Attributes;
using IPA.Config.Stores.Converters;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo(GeneratedStore.AssemblyVisibilityTarget)]
Expand All @@ -14,6 +16,7 @@ internal class PluginConfig
public virtual int MaxBookmarksPages { get; set; } = 3;
public virtual int MaxCuratorRecommendedPages { get; set; } = 3;
public virtual int MaxPPSongsCount { get; set; } = 500;
[UseConverter(typeof(EnumConverter<ScoreSabers.ScoreSaberManager.RankSort>))]
public virtual ScoreSabers.ScoreSaberManager.RankSort RankSort { get; set; } = ScoreSabers.ScoreSaberManager.RankSort.DateRanked;
public virtual bool DeleteOldVersions { get; set; } = false;
public virtual bool SyncBookmarksFeed { get; set; } = true;
Expand Down
4 changes: 2 additions & 2 deletions SyncSaber/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.2.2")]
[assembly: AssemblyFileVersion("3.2.2")]
[assembly: AssemblyVersion("3.2.3")]
[assembly: AssemblyFileVersion("3.2.3")]
48 changes: 32 additions & 16 deletions SyncSaber/ScoreSabers/ScoreSaberManager.cs
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
}
}
}
4 changes: 2 additions & 2 deletions SyncSaber/SyncSaber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private async Task DownloadPPSongs()
{
this.DisplayNotification("Download PPSongs.");

var songlist = await ScoreSaberManager.Ranked(PluginConfig.Instance.MaxPPSongsCount, PluginConfig.Instance.RankSort); //SongDataCore.Plugin.Songs.Data.Songs?.Where(x => x.Value.diffs.Max(y => y.pp) > 0d).OrderByDescending(x => x.Value.diffs.Max(y => y.pp))?.ToList();
var songlist = await ScoreSaberManager.Ranked(PluginConfig.Instance.MaxPPSongsCount, PluginConfig.Instance.RankSort);
if (songlist == null) {
return;
}
Expand All @@ -530,7 +530,7 @@ private async Task DownloadPPSongs()
while (Plugin.Instance?.IsInGame != false) {
await Task.Delay(200);
}
var hash = ppMap["id"].Value.ToLower();
var hash = ppMap["songHash"].Value.ToLower();
var beatmap = Loader.GetLevelByHash(hash);
if (beatmap != null) {
this.UpdatePlaylist(this._syncSaberSongs, hash, beatmap.songName);
Expand Down
4 changes: 2 additions & 2 deletions SyncSaber/UI/SettingViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public object CurrentMode
case ScoreSabers.ScoreSaberManager.RankSort.DateRanked:
return this.SortModes[0];
break;
case ScoreSabers.ScoreSaberManager.RankSort.Difficurity:
case ScoreSabers.ScoreSaberManager.RankSort.StarDifficulity:
return this.SortModes[1];
break;
default:
Expand All @@ -99,7 +99,7 @@ public object CurrentMode
PluginConfig.Instance.RankSort = ScoreSabers.ScoreSaberManager.RankSort.DateRanked;
}
else {
PluginConfig.Instance.RankSort = ScoreSabers.ScoreSaberManager.RankSort.Difficurity;
PluginConfig.Instance.RankSort = ScoreSabers.ScoreSaberManager.RankSort.StarDifficulity;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion SyncSaber/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "SyncSaber",
"name": "SyncSaber",
"author": "denpadokei",
"version": "3.2.2",
"version": "3.2.3",
"description": "",
"gameVersion": "1.16.4",
"dependsOn": {
Expand Down

0 comments on commit de51591

Please sign in to comment.