|
@@ -1,62 +1,77 @@
|
|
using System;
|
|
using System;
|
|
-using System.Collections.Generic;
|
|
|
|
-using System.Linq;
|
|
|
|
-using System.Text;
|
|
|
|
-using SimpleJSON;
|
|
|
|
|
|
+using Newtonsoft.Json;
|
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
|
|
|
namespace SongBrowser.DataAccess.BeatSaverApi
|
|
namespace SongBrowser.DataAccess.BeatSaverApi
|
|
{
|
|
{
|
|
public enum SongQueueState { Queued, Downloading, Downloaded, Error };
|
|
public enum SongQueueState { Queued, Downloading, Downloaded, Error };
|
|
-
|
|
|
|
[Serializable]
|
|
[Serializable]
|
|
- public class DifficultyLevel
|
|
|
|
|
|
+ public class Metadata
|
|
{
|
|
{
|
|
- public string difficulty;
|
|
|
|
- public int difficultyRank;
|
|
|
|
- public string jsonPath;
|
|
|
|
- public int? offset;
|
|
|
|
-
|
|
|
|
- //bananbread api
|
|
|
|
- // public DifficultyLevel(CustomSongInfo.DifficultyLevel difficultyLevel)
|
|
|
|
- // {
|
|
|
|
- // difficulty = difficultyLevel.difficulty;
|
|
|
|
- // difficultyRank = difficultyLevel.difficultyRank;
|
|
|
|
- // jsonPath = difficultyLevel.jsonPath;
|
|
|
|
- // }
|
|
|
|
|
|
+ public string[] characteristics;
|
|
|
|
+ public Difficulties difficulties;
|
|
|
|
|
|
- public DifficultyLevel(string Difficulty, int DifficultyRank, string JsonPath, int Offset = 0)
|
|
|
|
|
|
+ public Metadata()
|
|
{
|
|
{
|
|
- difficulty = Difficulty;
|
|
|
|
- difficultyRank = DifficultyRank;
|
|
|
|
- jsonPath = JsonPath;
|
|
|
|
- offset = Offset;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ [JsonConstructor]
|
|
|
|
+ public Metadata(string[] characteristics, Difficulties difficulties)
|
|
|
|
+ {
|
|
|
|
+ this.characteristics = characteristics;
|
|
|
|
+ this.difficulties = difficulties;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ [Serializable]
|
|
|
|
+ public class Difficulties
|
|
|
|
+ {
|
|
|
|
+ public bool easy = false;
|
|
|
|
+ public bool normal = false;
|
|
|
|
+ public bool hard = false;
|
|
|
|
+ public bool expert = false;
|
|
|
|
+ public bool expertPlus = false;
|
|
|
|
+ [JsonConstructor]
|
|
|
|
+ public Difficulties(bool easy, bool normal, bool hard, bool expert, bool expertPlus)
|
|
|
|
+ {
|
|
|
|
+ this.easy = easy;
|
|
|
|
+ this.normal = normal;
|
|
|
|
+ this.hard = hard;
|
|
|
|
+ this.expert = expert;
|
|
|
|
+ this.expertPlus = expertPlus;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
[Serializable]
|
|
[Serializable]
|
|
public class Song
|
|
public class Song
|
|
{
|
|
{
|
|
- public string id;
|
|
|
|
- public string beatname;
|
|
|
|
- public string ownerid;
|
|
|
|
- public string downloads;
|
|
|
|
- public string upvotes;
|
|
|
|
- public string plays;
|
|
|
|
- public string description;
|
|
|
|
- public string uploadtime;
|
|
|
|
|
|
+ public Metadata metadata;
|
|
|
|
+ public string levelAuthorName;
|
|
|
|
+ public string songAuthorName;
|
|
public string songName;
|
|
public string songName;
|
|
public string songSubName;
|
|
public string songSubName;
|
|
- public string authorName;
|
|
|
|
- public string beatsPerMinute;
|
|
|
|
- public string downvotes;
|
|
|
|
- public string coverUrl;
|
|
|
|
- public string downloadUrl;
|
|
|
|
- public DifficultyLevel[] difficultyLevels;
|
|
|
|
- public string img;
|
|
|
|
|
|
+ public float bpm;
|
|
|
|
+ public int downloads;
|
|
|
|
+ public int plays;
|
|
|
|
+ public int upVotes;
|
|
|
|
+ public int downVotes;
|
|
|
|
+ public float rating;
|
|
|
|
+ public float heat;
|
|
|
|
+ public string description;
|
|
|
|
+ public string _id;
|
|
|
|
+ public string key;
|
|
|
|
+ public string name;
|
|
|
|
+ public string ownerid;
|
|
|
|
+ public string ownerName;
|
|
public string hash;
|
|
public string hash;
|
|
|
|
+ public string uploaded;
|
|
|
|
+ public string downloadURL;
|
|
|
|
+ public string coverURL;
|
|
|
|
+ public string img;
|
|
|
|
+
|
|
|
|
|
|
public string path;
|
|
public string path;
|
|
|
|
+ public bool scoreSaber;
|
|
|
|
|
|
public SongQueueState songQueueState = SongQueueState.Queued;
|
|
public SongQueueState songQueueState = SongQueueState.Queued;
|
|
|
|
|
|
@@ -67,112 +82,101 @@ namespace SongBrowser.DataAccess.BeatSaverApi
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public Song(JSONNode jsonNode)
|
|
|
|
|
|
+ public Song(JObject jsonNode, bool scoreSaber)
|
|
{
|
|
{
|
|
- id = jsonNode["key"];
|
|
|
|
- beatname = jsonNode["name"];
|
|
|
|
- ownerid = jsonNode["uploaderId"];
|
|
|
|
- downloads = jsonNode["downloadCount"];
|
|
|
|
- upvotes = jsonNode["upVotes"];
|
|
|
|
- downvotes = jsonNode["downVotes"];
|
|
|
|
- plays = jsonNode["playedCount"];
|
|
|
|
- description = jsonNode["description"];
|
|
|
|
- uploadtime = jsonNode["createdAt"];
|
|
|
|
- songName = jsonNode["songName"];
|
|
|
|
- songSubName = jsonNode["songSubName"];
|
|
|
|
- authorName = jsonNode["authorName"];
|
|
|
|
- beatsPerMinute = jsonNode["bpm"];
|
|
|
|
- coverUrl = jsonNode["coverUrl"];
|
|
|
|
- downloadUrl = jsonNode["downloadUrl"];
|
|
|
|
- hash = jsonNode["hashMd5"];
|
|
|
|
- hash = hash.ToUpper();
|
|
|
|
-
|
|
|
|
- var difficultyNode = jsonNode["difficulties"];
|
|
|
|
-
|
|
|
|
- difficultyLevels = new DifficultyLevel[difficultyNode.Count];
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < difficultyNode.Count; i++)
|
|
|
|
|
|
+ if (scoreSaber)
|
|
{
|
|
{
|
|
- difficultyLevels[i] = new DifficultyLevel(difficultyNode[i]["difficulty"], difficultyNode[i]["difficultyRank"], difficultyNode[i]["audioPath"], difficultyNode[i]["jsonPath"]);
|
|
|
|
|
|
+ this.scoreSaber = scoreSaber;
|
|
|
|
+ ConstructFromScoreSaber(jsonNode);
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
+ metadata = jsonNode["metadata"].ToObject<Metadata>();
|
|
|
|
+ levelAuthorName = (string)jsonNode["metadata"]["levelAuthorName"];
|
|
|
|
+ songAuthorName = (string)jsonNode["metadata"]["songAuthorName"];
|
|
|
|
+ songName = (string)jsonNode["metadata"]["songName"];
|
|
|
|
+ songSubName = (string)jsonNode["metadata"]["songSubName"];
|
|
|
|
+ bpm = (float)jsonNode["metadata"]["bpm"];
|
|
|
|
+ downloads = (int)jsonNode["stats"]["downloads"];
|
|
|
|
+ plays = (int)jsonNode["stats"]["plays"];
|
|
|
|
+ upVotes = (int)jsonNode["stats"]["upVotes"];
|
|
|
|
+ downVotes = (int)jsonNode["stats"]["downVotes"];
|
|
|
|
+ rating = (float)jsonNode["stats"]["rating"];
|
|
|
|
+ heat = (float)jsonNode["stats"]["heat"];
|
|
|
|
+ description = (string)jsonNode["description"];
|
|
|
|
+ _id = (string)jsonNode["_id"];
|
|
|
|
+ key = (string)jsonNode["key"];
|
|
|
|
+ name = (string)jsonNode["name"];
|
|
|
|
+ ownerid = (string)jsonNode["uploader"]["_id"];
|
|
|
|
+ ownerName = (string)jsonNode["uploader"]["username"];
|
|
|
|
+ hash = (string)jsonNode["hash"];
|
|
|
|
+ hash = hash.ToLower();
|
|
|
|
+ uploaded = (string)jsonNode["uploaded"];
|
|
|
|
+ downloadURL = PluginConfig.beatsaverURL + (string)jsonNode["downloadURL"];
|
|
|
|
+ coverURL = PluginConfig.beatsaverURL + (string)jsonNode["coverURL"];
|
|
}
|
|
}
|
|
|
|
|
|
- public static Song FromSearchNode(JSONNode mainNode)
|
|
|
|
|
|
+ public void ConstructFromScoreSaber(JObject jsonNode)
|
|
{
|
|
{
|
|
- Song buffer = new Song();
|
|
|
|
- buffer.id = mainNode["key"];
|
|
|
|
- buffer.beatname = mainNode["name"];
|
|
|
|
- buffer.ownerid = mainNode["uploaderId"];
|
|
|
|
- buffer.downloads = mainNode["downloadCount"];
|
|
|
|
- buffer.upvotes = mainNode["upVotes"];
|
|
|
|
- buffer.downvotes = mainNode["downVotes"];
|
|
|
|
- buffer.plays = mainNode["playedCount"];
|
|
|
|
- buffer.uploadtime = mainNode["createdAt"];
|
|
|
|
- buffer.songName = mainNode["songName"];
|
|
|
|
- buffer.songSubName = mainNode["songSubName"];
|
|
|
|
- buffer.authorName = mainNode["authorName"];
|
|
|
|
- buffer.beatsPerMinute = mainNode["bpm"];
|
|
|
|
- buffer.coverUrl = mainNode["coverUrl"];
|
|
|
|
- buffer.downloadUrl = mainNode["downloadUrl"];
|
|
|
|
- buffer.hash = mainNode["hashMd5"];
|
|
|
|
-
|
|
|
|
- var difficultyNode = mainNode["difficulties"];
|
|
|
|
-
|
|
|
|
- buffer.difficultyLevels = new DifficultyLevel[difficultyNode.Count];
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < difficultyNode.Count; i++)
|
|
|
|
- {
|
|
|
|
- buffer.difficultyLevels[i] = new DifficultyLevel(difficultyNode[i]["difficulty"], difficultyNode[i]["difficultyRank"], difficultyNode[i]["audioPath"], difficultyNode[i]["jsonPath"]);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return buffer;
|
|
|
|
|
|
+ _id = "";
|
|
|
|
+ ownerid = "";
|
|
|
|
+ downloads = 0;
|
|
|
|
+ upVotes = 0;
|
|
|
|
+ downVotes = 0;
|
|
|
|
+ plays = 0;
|
|
|
|
+ description = "";
|
|
|
|
+ uploaded = "";
|
|
|
|
+ rating = 0;
|
|
|
|
+ heat = 0f;
|
|
|
|
+ key = "";
|
|
|
|
+ name = "";
|
|
|
|
+ ownerName = "";
|
|
|
|
+ downloadURL = "";
|
|
|
|
+ songName = (string)jsonNode["name"];
|
|
|
|
+ songSubName = (string)jsonNode["songSubName"];
|
|
|
|
+ levelAuthorName = (string)jsonNode["levelAuthorName"];
|
|
|
|
+ songAuthorName = (string)jsonNode["songAuthorName"];
|
|
|
|
+ bpm = (int)jsonNode["bpm"];
|
|
|
|
+ coverURL = PluginConfig.scoresaberURL + jsonNode["image"];
|
|
|
|
+ hash = (string)jsonNode["id"];
|
|
|
|
+ hash = hash.ToLower();
|
|
|
|
+ metadata = new Metadata() { characteristics = new string[] { "Standard" }, difficulties = new Metadata.Difficulties(true, false, false, false, false) };
|
|
|
|
+ // difficultyLevels = new DifficultyLevel[1];
|
|
|
|
+ // difficultyLevels[0] = new DifficultyLevel("Easy", 4, "", 0);
|
|
}
|
|
}
|
|
|
|
|
|
- public Song(JSONNode jsonNode, JSONNode difficultyNode)
|
|
|
|
|
|
+ public static Song FromSearchNode(JObject jsonNode)
|
|
{
|
|
{
|
|
-
|
|
|
|
- id = jsonNode["key"];
|
|
|
|
- beatname = jsonNode["name"];
|
|
|
|
- ownerid = jsonNode["uploaderId"];
|
|
|
|
- downloads = jsonNode["downloadCount"];
|
|
|
|
- upvotes = jsonNode["upVotes"];
|
|
|
|
- downvotes = jsonNode["downVotes"];
|
|
|
|
- plays = jsonNode["playedCount"];
|
|
|
|
- description = jsonNode["description"];
|
|
|
|
- uploadtime = jsonNode["createdAt"];
|
|
|
|
- songName = jsonNode["songName"];
|
|
|
|
- songSubName = jsonNode["songSubName"];
|
|
|
|
- authorName = jsonNode["authorName"];
|
|
|
|
- beatsPerMinute = jsonNode["bpm"];
|
|
|
|
- coverUrl = jsonNode["coverUrl"];
|
|
|
|
- downloadUrl = jsonNode["downloadUrl"];
|
|
|
|
- hash = jsonNode["hashMd5"];
|
|
|
|
-
|
|
|
|
- difficultyLevels = new DifficultyLevel[difficultyNode.Count];
|
|
|
|
-
|
|
|
|
- for (int i = 0; i < difficultyNode.Count; i++)
|
|
|
|
- {
|
|
|
|
- difficultyLevels[i] = new DifficultyLevel(difficultyNode[i]["difficulty"], difficultyNode[i]["difficultyRank"], difficultyNode[i]["audioPath"], difficultyNode[i]["jsonPath"]);
|
|
|
|
- }
|
|
|
|
|
|
+ Song buffer = new Song();
|
|
|
|
+ buffer.metadata = jsonNode["metadata"].ToObject<Metadata>();
|
|
|
|
+ buffer.levelAuthorName = (string)jsonNode["metadata"]["levelAuthorName"];
|
|
|
|
+ buffer.songAuthorName = (string)jsonNode["metadata"]["songAuthorName"];
|
|
|
|
+ buffer.songName = (string)jsonNode["metadata"]["songName"];
|
|
|
|
+ buffer.songSubName = (string)jsonNode["metadata"]["songSubName"];
|
|
|
|
+ buffer.bpm = (float)jsonNode["metadata"]["bpm"];
|
|
|
|
+ buffer.downloads = (int)jsonNode["stats"]["downloads"];
|
|
|
|
+ buffer.plays = (int)jsonNode["stats"]["plays"];
|
|
|
|
+ buffer.upVotes = (int)jsonNode["stats"]["upVotes"];
|
|
|
|
+ buffer.downVotes = (int)jsonNode["stats"]["downVotes"];
|
|
|
|
+ buffer.rating = (float)jsonNode["stats"]["rating"];
|
|
|
|
+ buffer.heat = (float)jsonNode["stats"]["heat"];
|
|
|
|
+ buffer.description = (string)jsonNode["description"];
|
|
|
|
+ buffer._id = (string)jsonNode["_id"];
|
|
|
|
+ buffer.key = (string)jsonNode["key"];
|
|
|
|
+ buffer.name = (string)jsonNode["name"];
|
|
|
|
+ buffer.ownerid = (string)jsonNode["uploader"]["_id"];
|
|
|
|
+ buffer.ownerName = (string)jsonNode["uploader"]["username"];
|
|
|
|
+ buffer.hash = (string)jsonNode["hash"];
|
|
|
|
+ buffer.hash = buffer.hash.ToLower();
|
|
|
|
+ buffer.uploaded = (string)jsonNode["uploaded"];
|
|
|
|
+ buffer.downloadURL = PluginConfig.beatsaverURL + (string)jsonNode["downloadURL"];
|
|
|
|
+ buffer.coverURL = PluginConfig.beatsaverURL + (string)jsonNode["coverURL"];
|
|
|
|
+ return buffer;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
public bool Compare(Song compareTo)
|
|
public bool Compare(Song compareTo)
|
|
{
|
|
{
|
|
- if (compareTo != null && songName == compareTo.songName)
|
|
|
|
- {
|
|
|
|
- if (difficultyLevels != null && compareTo.difficultyLevels != null)
|
|
|
|
- {
|
|
|
|
- return (songSubName == compareTo.songSubName && authorName == compareTo.authorName && difficultyLevels.Length == compareTo.difficultyLevels.Length);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- return (songSubName == compareTo.songSubName && authorName == compareTo.authorName);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ return compareTo.hash == hash;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -181,11 +185,12 @@ namespace SongBrowser.DataAccess.BeatSaverApi
|
|
{
|
|
{
|
|
songName = _data.songName;
|
|
songName = _data.songName;
|
|
songSubName = _data.songSubName;
|
|
songSubName = _data.songSubName;
|
|
- authorName = _data.songAuthorName;
|
|
|
|
- difficultyLevels = ConvertDifficultyLevels(_data.standardLevelInfoSaveData.difficultyBeatmapSets.SelectMany(x => x.difficultyBeatmaps).ToArray());
|
|
|
|
|
|
+ songAuthorName = _data.songAuthorName;
|
|
|
|
+ levelAuthorName = _data.levelAuthorName;
|
|
|
|
+ // difficultyLevels = ConvertDifficultyLevels(_data.standardLevelInfoSaveData.difficultyBeatmapSets.SelectMany(x => x.difficultyBeatmaps).ToArray());
|
|
path = _data.customLevelPath;
|
|
path = _data.customLevelPath;
|
|
//bananabread id hash
|
|
//bananabread id hash
|
|
- hash = SongCore.Collections.hashForLevelID(_data.levelID);
|
|
|
|
|
|
+ hash = SongCore.Collections.hashForLevelID(_data.levelID).ToLower();
|
|
// hash = SongCore.Utilities.Utils.GetCustomLevelHash(_data);
|
|
// hash = SongCore.Utilities.Utils.GetCustomLevelHash(_data);
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
@@ -214,6 +219,7 @@ namespace SongBrowser.DataAccess.BeatSaverApi
|
|
//bananbread api
|
|
//bananbread api
|
|
public Song(CustomSongInfo _song)
|
|
public Song(CustomSongInfo _song)
|
|
{
|
|
{
|
|
|
|
+
|
|
songName = _song.songName;
|
|
songName = _song.songName;
|
|
songSubName = _song.songSubName;
|
|
songSubName = _song.songSubName;
|
|
authorName = _song.songAuthorName;
|
|
authorName = _song.songAuthorName;
|
|
@@ -229,10 +235,13 @@ namespace SongBrowser.DataAccess.BeatSaverApi
|
|
if (_difficultyLevels != null && _difficultyLevels.Length > 0)
|
|
if (_difficultyLevels != null && _difficultyLevels.Length > 0)
|
|
{
|
|
{
|
|
DifficultyLevel[] buffer = new DifficultyLevel[_difficultyLevels.Length];
|
|
DifficultyLevel[] buffer = new DifficultyLevel[_difficultyLevels.Length];
|
|
|
|
+
|
|
for (int i = 0; i < _difficultyLevels.Length; i++)
|
|
for (int i = 0; i < _difficultyLevels.Length; i++)
|
|
{
|
|
{
|
|
buffer[i] = new DifficultyLevel(_difficultyLevels[i]);
|
|
buffer[i] = new DifficultyLevel(_difficultyLevels[i]);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
return buffer;
|
|
return buffer;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -241,7 +250,7 @@ namespace SongBrowser.DataAccess.BeatSaverApi
|
|
}
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
-
|
|
|
|
|
|
+ /*
|
|
public DifficultyLevel[] ConvertDifficultyLevels(IDifficultyBeatmap[] _difficultyLevels)
|
|
public DifficultyLevel[] ConvertDifficultyLevels(IDifficultyBeatmap[] _difficultyLevels)
|
|
{
|
|
{
|
|
if (_difficultyLevels != null && _difficultyLevels.Length > 0)
|
|
if (_difficultyLevels != null && _difficultyLevels.Length > 0)
|
|
@@ -261,6 +270,8 @@ namespace SongBrowser.DataAccess.BeatSaverApi
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ */
|
|
|
|
+ /*
|
|
public DifficultyLevel[] ConvertDifficultyLevels(StandardLevelInfoSaveData.DifficultyBeatmap[] _difficultyLevels)
|
|
public DifficultyLevel[] ConvertDifficultyLevels(StandardLevelInfoSaveData.DifficultyBeatmap[] _difficultyLevels)
|
|
{
|
|
{
|
|
if (_difficultyLevels != null && _difficultyLevels.Length > 0)
|
|
if (_difficultyLevels != null && _difficultyLevels.Length > 0)
|
|
@@ -280,7 +291,7 @@ namespace SongBrowser.DataAccess.BeatSaverApi
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ */
|
|
}
|
|
}
|
|
[Serializable]
|
|
[Serializable]
|
|
public class RootObject
|
|
public class RootObject
|