public bool DownloadTrackAndTag(ref Track song) { if (!ManifestUtil.ProgressUtil.IsActive) { return(false); } if (song?.LocalPath == null) { return(false); } Directory.CreateDirectory(Path.GetDirectoryName(song.LocalPath)); using (var client = new WebClient()) { if (song.IsHD) { string extension = DetermineExtension(song); //1MB 씩 다운로드 하고 Taglib 로 분석하기. if (ConvertToMp3 && Highqualitysong && DetermineAllowedFormats().Contains(extension)) { //get the wav song as byte data, as we won't store it just yet var soundbytes = client.DownloadData(song.EffectiveDownloadUrl + $"?client_id={ClientIDsUtil.ClientIdCurrentValue}"); //convert to mp3 & then write bytes to file var succesfulConvert = AudioConverterUtils.ConvertAllTheThings(soundbytes, ref song, extension); if (!succesfulConvert) //something has gone wrong, download the stream url instead of download url { song.LocalPath += ".mp3"; client.DownloadFile(song.stream_url + $"?client_id={ClientIDsUtil.ClientIdCurrentValue}", song.LocalPath); } } else if (extension == ".mp3") //get the high res mp3 without converting { song.LocalPath += extension; client.DownloadFile(song.EffectiveDownloadUrl + $"?client_id={ClientIDsUtil.ClientIdCurrentValue}", song.LocalPath); } else //get the low res mp3 if all above not possible { song.LocalPath += ".mp3"; client.DownloadFile(song.stream_url + $"?client_id={ClientIDsUtil.ClientIdCurrentValue}", song.LocalPath); } } else { song.LocalPath += ".mp3"; client.DownloadFile(song.stream_url + $"?client_id={ClientIDsUtil.ClientIdCurrentValue}", song.LocalPath); } } MetadataTaggingUtils.TagIt(song); Interlocked.Increment(ref ManifestUtil.ProgressUtil.SongsDownloaded); return(true); }
public bool DownloadTrackAndTag(ref Track song) { if (!ManifestUtil.ProgressUtil.IsActive) { return(false); } if (song?.LocalPath == null) { return(false); } Directory.CreateDirectory(Path.GetDirectoryName(song.LocalPath)); song.EffectiveDownloadUrl = GetEffectiveDownloadUrlForHQ(song.download_url, song.downloadable); string extension = DetermineExtension(song); var allowedExtension = DetermineAllowedFormats().Contains(extension); bool succesfulConvert = false; if (!string.IsNullOrWhiteSpace(song.EffectiveDownloadUrl) && song.IsHD && ConvertToMp3 && allowedExtension) { //get the wav song as byte data, as we won't store it just yet var soundbytes = httpClient.GetByteArrayAsync(song.EffectiveDownloadUrl).Result; //convert to mp3 & then write bytes to file succesfulConvert = AudioConverterUtils.ConvertAllTheThings(soundbytes, ref song, extension); } if (!succesfulConvert) { song.EffectiveDownloadUrl = GetEffectiveDownloadUrlForStream(song.id); if (string.IsNullOrWhiteSpace(song.EffectiveDownloadUrl)) { return(false); } song.LocalPath += ".mp3"; using (var download = httpClient.GetAsync(song.EffectiveDownloadUrl).Result) using (var fs = new FileStream(song.LocalPath, FileMode.Create)) { download.Content.CopyToAsync(fs).GetAwaiter().GetResult(); } } MetadataTaggingUtils.TagIt(song); Interlocked.Increment(ref ManifestUtil.ProgressUtil.SongsDownloaded); return(true); }