private void ButtonSearchClick(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(Query)) { MessageBox.Show("Query cannot be empty"); return; } int numberOfResults; if (!int.TryParse(NumberOfResultsInput, out numberOfResults) || numberOfResults < 1) { MessageBox.Show("Number of pages is not a valid number"); } IEnumerable <YoutubeLink> youtubeLinks = YoutubeSearcher.GetYoutubeLinks(Query, numberOfResults); if (PlayList == INSTRUCTIONS) { PlayList = ""; } foreach (YoutubeLink link in youtubeLinks) { PlayList += link.Label + "\n"; //TODO store urls of songs in cache => quicker to download, no need for lookup on youtube } }
public async Task <string> DownloadPlaylistItem(PlaylistItem item) { string destinationFilePathWithoutExtension = null; string tempFilePathWithoutExtension = null; item.DownloadProgress = 5; if (!string.IsNullOrWhiteSpace(item.Name)) { YoutubeLink youtubeLink = YoutubeSearcher.GetYoutubeLinks(item.Name).FirstOrDefault(); item.FileName = MakeValidFileName(youtubeLink.Label); item.FileName = string.Concat(youtubeLink.Label.Split(Path.GetInvalidFileNameChars())).Trim().Replace('–', '-'); var workingFolder = Path.GetTempPath(); tempFilePathWithoutExtension = Path.Combine(Path.GetTempPath(), item.FileName); destinationFilePathWithoutExtension = Path.Combine(_runSettings.SongsFolder, item.FileName); if (!File.Exists(destinationFilePathWithoutExtension + ".mp3")) { item.DownloadProgress = 10; if (youtubeLink == null) { item.SetDownloadStatus(false); } else { // Download videoand extract the mp3 file await StartProcess( _runSettings.YoutubeDlPath, string.Format(" --ffmpeg-location \"{0}\"" + " --format bestaudio[ext=mp3]/best" + " --audio-quality 0" + " --no-part" + " --extract-audio" + " --audio-format mp3" + " --output \"{1}\"" + " {2}", _runSettings.FfmpegPath, tempFilePathWithoutExtension + "-raw.%(ext)s", youtubeLink.Url), item, ParseYoutubeDlProgress); // -o "c:\Users\Julian\Music\PlaylistDownloader\\%(title)s.%(ext)s" // Normalize audio file after the youtube-dl process has exited await StartProcess(_runSettings.FfmpegPath, string.Format(" -i \"{0}\"" + " -af loudnorm=I=-16:TP=-1.5:LRA=11" + //" -ar 48k" + " -y" + " \"{1}\"", tempFilePathWithoutExtension + "-raw.mp3", tempFilePathWithoutExtension + _runSettings.NormalizedSuffix + ".mp3"), item, ParseYoutubeDlProgress); // move to destination File.Move(tempFilePathWithoutExtension + _runSettings.NormalizedSuffix + ".mp3", destinationFilePathWithoutExtension + _runSettings.NormalizedSuffix + ".mp3"); // Delete the non normalized file after completion if not in debug mode File.Delete(Path.Combine(_runSettings.SongsFolder, item.FileName + "-raw.mp3")); } } } item.DownloadProgress = 100; _progress++; OnProgressChanged(new ProgressChangedEventArgs(_progress * 100 / _totalSongs, null)); return(destinationFilePathWithoutExtension); }