예제 #1
0
        public Task <DownloadResult> DownloadSong(AudicaSong song, string downloadFolder)
        {
            string downloadPath = Path.Combine(downloadFolder, song.Filename);

            return(DownloadSong(song.DownloadUrl, song.SongId, downloadPath));
        }
예제 #2
0
        public async Task <DownloadResult[]> DownloadSongs(IList <AudicaSong> songs)
        {
            string tempFolder = DownloadFolder;
            string gameFolder = GameDirectory;

            try
            {
                //Directory.CreateDirectory(tempFolder);
                Directory.CreateDirectory(gameFolder);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error creating DownloadFolder or GameDirectory folder.");
                Console.WriteLine(ex);
                return(Array.Empty <DownloadResult>());
            }
            List <DownloadResult> downloadResults = new List <DownloadResult>();

            for (int i = 0; i < songs.Count; i++)
            {
                AudicaSong song = songs[i];
                Console.Write($"({i + 1}/{songs.Count}) Downloading {song.Filename}...");
                if (File.Exists(Path.Combine(gameFolder, song.Filename)))
                {
                    Console.WriteLine("Skipped (already exists)");
                    continue;
                }
                DownloadResult result = await DownloadSong(song, gameFolder);

                if (result.Successful)
                {
                    Console.WriteLine("Done");
                }
                else
                {
                    string message = "Failed";
                    if (result.Exception != null)
                    {
                        message += ": ";
                        if (result.Exception is HttpRequestException httpRequestException)
                        {
                            message += httpRequestException.Message;
                        }
                        else if (result.Exception is IOException ioException)
                        {
                            message += ioException.Message;
                        }
                        else
                        {
                            Console.WriteLine(result.Exception);
                        }
                    }

                    Console.WriteLine(message);
                }

                downloadResults.Add(result);
            }

            return(downloadResults.ToArray());
        }
예제 #3
0
 public static string CreateSongId(AudicaSong song)
 {
     return(string.Join("", $"{song.Title}-{song.Artist}-{song.Author}".Split(Path.GetInvalidFileNameChars())).Replace(" ", ""));
 }