Пример #1
0
        public async Task <AudicaSongList> FetchSongPage(int page)
        {
            if (page < 1)
            {
                throw new ArgumentException($"Page cannot be less than 1");
            }
            AudicaSongList songList = null;

            try
            {
                HttpResponseMessage response = await HttpClient.GetAsync(FetchUrl.Replace(PAGEKEY, page.ToString())).ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    songList = AudicaSongList.FromJson(await response.Content.ReadAsStringAsync().ConfigureAwait(false));
                }
                else
                {
                    Console.WriteLine($"Http failed retrieving song list: {response.StatusCode}: {response.ReasonPhrase}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error retrieving song list: {ex.Message}");
                Console.WriteLine(ex);
            }
            return(songList);
        }
Пример #2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Starting AudicaDownloader..."); Config config = new Config()
            {
                AudicaGameDirectory = Path.Combine(Environment.CurrentDirectory, "GameDirectory"),
                TempDirectory       = Path.Combine(Environment.CurrentDirectory, "Temp")
            };
            Console.WriteLine("Fetching song list...");
            Downloader     downloader = new Downloader(config);
            int            pageIndex  = 1;
            AudicaSongList songList   = await downloader.FetchSongPage(pageIndex).ConfigureAwait(false);

            List <AudicaSong> songs = new List <AudicaSong>(songList.SongCount);

            songs.AddRange(songList.Songs);
            int totalPages = songList.TotalPages;
            int songCount  = songList.Songs.Count;

            while (pageIndex < totalPages)
            {
                pageIndex++;
                songList = await downloader.FetchSongPage(pageIndex).ConfigureAwait(false);

                songs.AddRange(songList.Songs);
                songCount += songList.Songs.Count;
            }
            var songsToDownload = songs.GroupBy(s => s.Filename).Select(g => g.OrderByDescending(g => g.UploadTime).First()).ToList(); // Remove duplicate IDs, choose latest

            Console.WriteLine($"Found {songsToDownload.Count} songs");
            var downloadResults = await downloader.DownloadSongs(songsToDownload).ConfigureAwait(false);

            var successfulDownloads = downloadResults.Where(r => r.Successful).Count();
            var failedDownloads     = downloadResults.Where(r => !r.Successful).ToList();

            Console.WriteLine($"Downloaded {successfulDownloads} songs.");
            if (failedDownloads.Count > 0)
            {
                Console.WriteLine($"Failed to download {failedDownloads.Count} songs");
            }
            Console.Read();
        }
Пример #3
0
 public static string ToJson(this AudicaSongList self) => JsonConvert.SerializeObject(self, AudicaDownloader.Converter.Settings);