public static void ProcessQueue() { bool addedAny = false; MelonLogger.Log(requestQueue.Count + " in queue."); if (requestQueue.Count != 0) { foreach (string str in requestQueue) { QueryData data = new QueryData(str); SongList.SongData result = SearchSong(data, out bool foundExactMatch); if ((!hasCompatibleSongBrowser || foundExactMatch) && result != null) { // if we have web search we want to make sure we prioritize exact matches // over partial local ones MelonLogger.Log("Result: " + result.songID); if (!requestList.Contains(result.songID)) { requestList.Add(result.songID); addedAny = true; } } else if (hasCompatibleSongBrowser) { StartWebSearch(data); } else { MelonLogger.Log($"Found no match for \"{str}\""); } } requestQueue.Clear(); } if (addedAny && MenuState.GetState() == MenuState.State.SongPage) { RequestUI.UpdateFilter(); } RequestUI.UpdateButtonText(); }
private static void ProcessWebSearchResult(string query, APISongList response) { QueryData data = webSearchQueryData[query]; bool addedLocalMatch = false; if (response.song_count > 0) { Song bestMatch = null; bool foundAny = false; bool foundBetter = false; bool foundExact = false; foreach (Song s in response.songs) { if ((data.Artist == null || s.artist.ToLowerInvariant().Replace(" ", "").Contains(data.Artist)) && (data.Mapper == null || s.author.ToLowerInvariant().Replace(" ", "").Contains(data.Mapper)) && (s.title.ToLowerInvariant().Contains(data.Title) || s.song_id.ToLowerInvariant().Contains(data.Title.Replace(" ", "")))) { if (LookForMatch(data.Title, s.title, ref foundAny, ref foundBetter, ref foundExact)) { bestMatch = s; if (foundExact) { break; } } } } if (bestMatch != null) { // check if we already have that file downloaded QueryData matchData = new QueryData($"{bestMatch.title} -artist {bestMatch.artist} -mapper {bestMatch.author}"); SongList.SongData s = SearchSong(matchData, out bool isExactMatch); if (isExactMatch) { MelonLogger.Log("Result: " + s.songID); if (!requestList.Contains(s.songID)) { requestList.Add(s.songID); addedLocalMatch = true; } } else if (!missingSongs.ContainsKey(bestMatch.song_id)) { missingSongs.Add(bestMatch.song_id, bestMatch); MelonLogger.Log("Result (missing): " + bestMatch.song_id); } } else { MelonLogger.Log($"Found no match for \"{data.FullQuery}\""); } } else { // check if we have a local match (can happen if // this particular map hasn't been uploaded or was taken down) SongList.SongData s = SearchSong(data, out bool _); if (s != null) { MelonLogger.Log("Result: " + s.songID); if (!requestList.Contains(s.songID)) { requestList.Add(s.songID); addedLocalMatch = true; } } else { MelonLogger.Log($"Found no match for \"{data.FullQuery}\""); } } if (addedLocalMatch && MenuState.GetState() == MenuState.State.SongPage) { RequestUI.UpdateFilter(); } webSearchQueryData.Remove(query); if (GetActiveWebSearchCount() == 0) { RequestUI.UpdateButtonText(); } }