Beispiel #1
0
 internal static void StartNewPageSearch()
 {
     SongDownloaderUI.ResetScrollPosition();
     MelonCoroutines.Start(DoSongWebSearch(searchString, (query, result) => {
         songlist = result;
         if (SongDownloaderUI.songItemPanel != null)
         {
             SongDownloaderUI.AddSongItems(SongDownloaderUI.songItemMenu, songlist);
         }
     }, SongDownloaderUI.difficultyFilter, SongDownloaderUI.popularity, page, false));
 }
Beispiel #2
0
        public static IEnumerator StartSongSearchCoroutine(string search, string difficulty = null, int page = 1, bool total = false)
        {
            string webSearch     = search == null || search == "" ? "" : "&search=" + WebUtility.UrlEncode(search);
            string webPage       = page == 1 ? "" : "&page=" + page.ToString();
            string webDifficulty = difficulty == "All" || difficulty == "" ? "" : "&" + difficulty.ToLower() + "=true";
            string webCurated    = SongDownloaderUI.curated ? "&curated=true" : "";
            string webPlaycount  = SongDownloaderUI.popularity ? "&sort=leaderboards" : "";
            string concatURL     = !total ? apiURL + webSearch + webDifficulty + webPage + webCurated + webPlaycount : "http://www.audica.wiki:5000/api/customsongs?pagesize=all";
            WWW    www           = new WWW(concatURL);

            yield return(www);

            songlist = JSON.Load(www.text).Make <APISongList>();
            if (SongDownloaderUI.songItemPanel != null)
            {
                SongDownloaderUI.AddSongItems(SongDownloaderUI.songItemMenu, songlist);
            }
        }
 public void OnWebSearchDone(string search, APISongList result)
 {
     if (result is null)
     {
         if (IsDownloadingMissing && prepareDownloadMissing)
         {
             IsDownloadingMissing   = false;
             prepareDownloadMissing = false;
         }
         return;
     }
     if (result.song_count == 1)
     {
         Song song = result.songs[0];
         ActiveDownloads++;
         MelonCoroutines.Start(SongDownloader.DownloadSong(song.song_id, song.download_url, OnDownloadComplete));
     }
 }
Beispiel #4
0
        public static void AddSongItems(OptionsMenu optionsMenu, APISongList songlist)
        {
            CleanUpPage(optionsMenu);
            activeSongList = songlist;
            optionsMenu.screenTitle.text = "Displaying page " + SongBrowser.page.ToString() + " out of " + songlist.total_pages.ToString();

            var pageHeader = optionsMenu.AddHeader(0, "Listing " + songlist.song_count.ToString() + " songs");

            optionsMenu.scrollable.AddRow(pageHeader.gameObject);

            AddPageButtons(optionsMenu);

            foreach (var song in songlist.songs)
            {
                CreateSongItem(song, optionsMenu);
            }

            AddPageButtons(optionsMenu);
        }
 public void OnWebSearchDone(string search, APISongList result)
 {
     if (result is null)
     {
         /*if (IsDownloadingMissing && prepareDownloadMissing)
          * {
          *  IsDownloadingMissing = false;
          *  prepareDownloadMissing = false;
          * }*/
         MelonLogger.Msg("search returned no matches.");
         return;
     }
     if (result.song_count == 1)
     {
         Song song = result.songs[0];
         ActiveDownloads++;
         MelonLogger.Msg("Downloading " + song.song_id);
         MelonCoroutines.Start(SongDownloader.DownloadSong(song.song_id, song.download_url, OnDownloadComplete));
     }
 }
Beispiel #6
0
        internal static void ConvertAPIList(NewAPISongList from, APISongList to, int startIdx)
        {
            for (int idx = 0; idx < from.maps.Length; idx++)
            {
                Song   newSong = new Song();
                SongV2 song    = from.maps[idx];
                newSong.title  = song.title;
                newSong.artist = song.artist;
                newSong.author = song.author;
                for (int diffIdx = 0; diffIdx < song.difficulties.Length; diffIdx++)
                {
                    if (song.difficulties[diffIdx] == "beginner")
                    {
                        newSong.beginner = true;
                    }
                    else if (song.difficulties[diffIdx] == "moderate")
                    {
                        newSong.standard = true;
                    }
                    else if (song.difficulties[diffIdx] == "advanced")
                    {
                        newSong.advanced = true;
                    }
                    else if (song.difficulties[diffIdx] == "expert")
                    {
                        newSong.expert = true;
                    }
                }
                newSong.download_url = string.Format(downloadUrlFormat, song.id);
                newSong.upload_time  = song.created_at;
                newSong.update_time  = song.updated_at;
                newSong.video_url    = song.embed_url;
                newSong.filename     = song.filename;
                newSong.song_id      = song.filename.Remove(song.filename.Length - 7); // remove the .audica from the filename to get the hash-less ID
                newSong.preview_url  = string.Format(previewUrlFormat, song.id);

                to.songs[startIdx + idx] = newSong;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Coroutine that searches for songs using the web API
        /// </summary>
        /// <param name="search">Query text, e.g. song name, artist or mapper (partial matches possible)</param>
        /// <param name="onSearchComplete">Called with search result once search is completed, use to process search result</param>
        /// <param name="difficulty">Only find songs with given difficulty</param>
        /// <param name="curated">Only find songs that are curated</param>
        /// <param name="sortByPlayCount">Sort result by play count</param>
        /// <param name="page">Page to return (see APISongList.total_pages after initial search (page = 1) to check if multiple pages exist)</param>
        /// <param name="total">Bypasses all query and filter limitations and just returns entire song list (or max page size)</param>
        public static IEnumerator DoSongWebSearch(string search, Action <string, APISongList> onSearchComplete, DifficultyFilter difficulty, bool curated = false,
                                                  bool sortByPlayCount = false, int page = 1, bool total = false, bool searchIsFilename = false)
        {
            if (UseNewAPI)
            {
                if (total)
                {
                    string webSearch = "https://beta.maudica.com/api/maps?per_page=100&page={0}";

                    // initial search to initialize result list
                    WWW www = new WWW(string.Format(webSearch, 1));
                    yield return(www);

                    NewAPISongList list = JSON.Load(www.text).Make <NewAPISongList>();

                    APISongList result = new APISongList();
                    result.song_count  = list.count;
                    result.page        = 1;
                    result.pagesize    = list.count;
                    result.total_pages = 1;
                    result.songs       = new Song[list.count];

                    int numPages = (int)Math.Ceiling((double)list.count / 100);
                    int currPage = 1;
                    ConvertAPIList(list, result, 0);
                    while (currPage <= numPages)
                    {
                        currPage++;
                        www = new WWW(string.Format(webSearch, currPage));
                        yield return(www);

                        list = JSON.Load(www.text).Make <NewAPISongList>();
                        ConvertAPIList(list, result, 100 * (currPage - 1));
                    }
                    onSearchComplete(search, result);
                }
                else
                {
                    string webSearch;
                    string concatURL;
                    if (searchIsFilename)
                    {
                        webSearch = search == null || search == "" ? "" : "&filename=" + WebUtility.UrlEncode(search);
                        concatURL = newApiUrl + webSearch;
                    }
                    else
                    {
                        webSearch = search == null || search == "" ? "" : "&search=" + WebUtility.UrlEncode(search);
                        string webPage       = page == 1 ? "" : "&page=" + page.ToString();
                        string webDifficulty = difficulty == DifficultyFilter.All ? "" : "&difficulties%5B%5D=" + DifficultyToNewAPIValue(difficulty);
                        string webDownloads  = sortByPlayCount ? "&sort=downloads" : "";
                        concatURL = newApiUrl + webSearch + webDifficulty + webPage + webDownloads;
                    }
                    WWW www = new WWW(concatURL);
                    yield return(www);

                    NewAPISongList list = JSON.Load(www.text).Make <NewAPISongList>();

                    // convert to existing SongList format, then return
                    APISongList result = new APISongList();
                    result.song_count  = list.count;
                    result.page        = page;
                    result.pagesize    = 14;
                    result.total_pages = (int)Math.Ceiling(result.song_count / (double)result.pagesize);
                    result.songs       = new Song[list.maps.Length];
                    ConvertAPIList(list, result, 0);
                    onSearchComplete(search, result);
                }
            }
            else
            {
                string webSearch     = search == null || search == "" ? "" : "&search=" + WebUtility.UrlEncode(search);
                string webPage       = page == 1 ? "" : "&page=" + page.ToString();
                string diff          = difficulty.ToString();
                string webDifficulty = diff == "All" ? "" : "&" + diff.ToLower() + "=true";
                string webCurated    = curated ? "&curated=true" : "";
                string webPlaycount  = sortByPlayCount ? "&sort=leaderboards" : "";
                string concatURL     = !total ? apiURL + webSearch + webDifficulty + webPage + webCurated + webPlaycount : "http://www.audica.wiki:5000/api/customsongs?pagesize=all";
                WWW    www           = new WWW(concatURL);
                yield return(www);

                onSearchComplete(search, JSON.Load(www.text).Make <APISongList>());
            }
        }
        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();
            }
        }