예제 #1
0
        private async Task <JObject> GetResults(string term)
        {
            var resultLimit = Configuration.GetValue <int>("maxSearchResults");

            if (resultLimit <= 0)
            {
                resultLimit = 40;
            }
            else if (resultLimit > 500)
            {
                resultLimit = 500;
            }


            JObject searchResults = await _deezerHttp.HitUnofficialApi("deezer.pageSearch", new JObject
            {
                ["query"]          = term,
                ["start"]          = 0,
                ["nb"]             = resultLimit,
                ["suggest"]        = false,
                ["artist_suggest"] = false,
                ["top_tracks"]     = false
            });

            searchResults.DisplayDeezerErrors("Search");

            if (searchResults?["results"] == null)
            {
                Helpers.RedMessage("Results object was null");
                return(null);
            }

            return(searchResults);
        }
예제 #2
0
        public async Task <bool> ProcessArtist(string id)
        {
            JObject discographyInfo = await _deezerHttp.HitUnofficialApi("album.getDiscography", new JObject
            {
                ["art_id"]         = id,
                ["filter_role_id"] = new JArray("0"),
                ["lang"]           = "us",
                ["nb"]             = 500,
                ["nb_songs"]       = -1,
                ["start"]          = 0
            });

            discographyInfo.DisplayDeezerErrors("Discography");

            if (discographyInfo["results"]?["data"] == null || discographyInfo["results"]["count"].Value <int>() <= 0)
            {
                Helpers.RedMessage("No items found in artist discography");
                return(false);
            }

            var discographyItems = (JArray)discographyInfo["results"]["data"];

            var artistResults = new List <bool>();

            foreach (JObject discographyItem in discographyItems.Children <JObject>())
            {
                var albumId = discographyItem["ALB_ID"].Value <string>();

                bool albumDownloadResults = await ProcessAlbum(albumId);

                artistResults.Add(albumDownloadResults);
            }

            int artistDownloadsFailed = artistResults.Count(x => x);

            if (artistDownloadsFailed != artistResults.Count)
            {
                Helpers.GreenMessage("Artist download successful");
            }
            else
            {
                Helpers.RedMessage($"{artistDownloadsFailed}/{artistResults.Count} Downloaded");
            }

            return(true);
        }