Esempio n. 1
0
        public static ScoreSaberSong GetScoreSaberSongFromJson(JToken song)
        {
            //JSONObject song = (JSONObject) aKeyValue;
            //string songIndex = song["key"]?.Value<string>();
            string songHash = song["id"]?.Value <string>();
            string songName = song["name"]?.Value <string>();
            string author   = song["author"]?.Value <string>();
            //string songUrl = "https://beatsaver.com/download/" + songIndex;
            ScoreSaberSong newSong = null;

            if (ScoreSaberSong.TryParseScoreSaberSong(song, ref newSong))
            {
                //newSong.Feed = "followings";
                newSong.ScrapedAt = DateTime.Now;
                ScrapedDataProvider.GetOrCreateSong(newSong, true);
                return(newSong);
            }
            else
            {
                if (!(string.IsNullOrEmpty(songName)))
                {
                    Logger.Warning($"Couldn't parse song {songName}, using sparse definition.");
                    //songs.Add(new ScoreSaberSong("", songName, "", author));
                }
                else
                {
                    Logger.Error("Unable to identify song, skipping");
                }
            }
            return(null);
        }
Esempio n. 2
0
        public List <ScoreSaberSong> GetSSSongsFromPage(string pageText)
        {
            JObject result = new JObject();

            try
            {
                result = JObject.Parse(pageText);
            }
            catch (Exception ex)
            {
                Logger.Exception("Unable to parse JSON from text", ex);
            }
            List <ScoreSaberSong> songs = new List <ScoreSaberSong>();

            var songJSONAry = result["songs"]?.ToArray();

            if (songJSONAry == null)
            {
                Logger.Error("Invalid page text: 'songs' field not found.");
            }
            foreach (var song in songJSONAry)
            {
                //JSONObject song = (JSONObject) aKeyValue;
                //string songIndex = song["key"]?.Value<string>();
                string songHash = song["id"]?.Value <string>();
                string songName = song["name"]?.Value <string>();
                string author   = song["author"]?.Value <string>();
                //string songUrl = "https://beatsaver.com/download/" + songIndex;

                if (ScoreSaberSong.TryParseScoreSaberSong(song, out ScoreSaberSong newSong))
                {
                    //newSong.Feed = "followings";
                    songs.Add(newSong);
                }
                else
                {
                    if (!(string.IsNullOrEmpty(songName)))
                    {
                        Logger.Warning($"Couldn't parse song {songName}, using sparse definition.");
                        //songs.Add(new ScoreSaberSong("", songName, "", author));
                    }
                    else
                    {
                        Logger.Error("Unable to identify song, skipping");
                    }
                }
            }
            return(songs);
        }