/// <summary> /// Attempts to find a song with the provided hash. If there's no matching /// song in the ScrapedData and searchOnline is true, it searches Beat Saver. If a match is found /// online, it adds the SongInfo to the ScrapedData. Returns true if a SongInfo is found. /// </summary> /// <param name="hash"></param> /// <param name="song"></param> /// <param name="searchOnline"></param> /// <returns></returns> public static bool TryGetSongByHash(string hash, out SongInfo song, bool searchOnline = true) { hash = hash.ToUpper(); song = Songs.ContainsKey(hash) ? Songs[hash] : null; if (song?.BeatSaverInfo == null && searchOnline) { Logger.Info($"Song with hash: {hash}, not in scraped data, searching Beat Saver..."); song = BeatSaverReader.Search(hash, BeatSaverReader.SearchType.hash).FirstOrDefault(); if (song != null) { song.BeatSaverInfo.ScrapedAt = DateTime.Now; TryAddToScrapedData(song); } else { Logger.Warning($"Unable to find song with hash {hash} on Beat Saver, skipping."); } } return(song != null); }
private static void Tests() { var thing = new ScrappedSong(); Web.HttpClientWrapper.Initialize(5); List <ScrappedSong> scrapedDict; using (StreamReader file = File.OpenText(@"C:\Users\Jared\source\repos\SyncSaberService\SyncSaberService\bin\Debug\ScrapedData\combinedScrappedData.json")) { JsonSerializer serializer = new JsonSerializer(); scrapedDict = (List <ScrappedSong>)serializer.Deserialize(file, typeof(List <ScrappedSong>)); } DownloadJob testJob = new DownloadJob(new SongInfo("111-111", "testName", "", "testAuthor"), "temp", "CustomSongs"); var testTask = testJob.RunJobAsync(); testTask.Wait(); var searchTest = BeatSaverReader.Search("6A097D39A5FA94F3B736E6EEF5A519A2", BeatSaverReader.SearchType.hash); var testReader = new ScoreSaberReader(); var sssongs = testReader.GetSSSongsFromPage(HttpClientWrapper.GetPageText("https://scoresaber.com/api.php?function=get-leaderboards&cat=3&limit=5&page=39&ranked=1")); foreach (var sssong in sssongs) { sssong.PopulateFields(); } var songs = testReader.GetSongsFromFeed(new ScoreSaberFeedSettings(0) { MaxPages = 10 }); SongInfo song = new SongInfo("18750-20381", "test", "testUrl", "testAuthor"); song.PopulateFields(); var test = song["key"]; var test2 = song["id"]; var test3 = song["uploaderId"]; }