//Returns VideoInfo object (Only for audio model) public static VideoInfo GetVideoInfoAudioOnly(YouTubeAudioModel audioModel) { //We want the first extractable video with the highest audio quality. VideoInfo video = audioModel.VideoInfo .Where(info => info.CanExtractAudio) .OrderByDescending(info => info.AudioBitrate) .First(); return video; }
//Returns AudioDownloader object (Only for audio model) public static AudioDownloader GetAudioDownloader(YouTubeAudioModel audioModel) { //Create AudioDownloader object return new AudioDownloader(audioModel.Video, audioModel.FilePath); }
private void Download(string validatedLink) { if (cmb_FileType.SelectedIndex == 0) { YouTubeVideoModel VideoDownloader = new YouTubeVideoModel(); VideoDownloader.Link = validatedLink; VideoDownloader.FolderPath = tb_DownloadPath.Text; DownloadVideo(VideoDownloader); } else { YouTubeAudioModel AudioDownloader = new YouTubeAudioModel(); AudioDownloader.Link = validatedLink; AudioDownloader.FolderPath = tb_DownloadPath.Text; DownloadAudio(AudioDownloader); } }
//Downloads Audio (Only for Audio model) public static void DownloadAudio(YouTubeAudioModel audioModel) { Task.Run(() => audioModel.AudioDownloaderType.Execute()); }
private void DownloadAudio(YouTubeAudioModel audioDownloader) { try { //Store VideoInfo object in model audioDownloader.VideoInfo = FileDownloader.GetVideoInfos(audioDownloader); //Stores VideoInfo object in model audioDownloader.Video = FileDownloader.GetVideoInfoAudioOnly(audioDownloader); //Update label within console UpdateLable(audioDownloader.Video.Title + audioDownloader.Video.AudioExtension); //Stores FilePath in model audioDownloader.FilePath = FileDownloader.GetPath(audioDownloader); audioDownloader.FilePath += audioDownloader.Video.VideoExtension; //Stores VideoDownloaderType object in model audioDownloader.AudioDownloaderType = FileDownloader.GetAudioDownloader(audioDownloader); //Stop time after download is complete audioDownloader.AudioDownloaderType.DownloadFinished += (sender, args) => timer1.Stop(); //Enable controls once download is complete audioDownloader.AudioDownloaderType.DownloadFinished += (sender, args) => EnableAccessAbility(); //Open folder with downloaded file selected audioDownloader.AudioDownloaderType.DownloadFinished += (sender, args) => OpenFolder(audioDownloader.FilePath); //Link progress bar up to download progress audioDownloader.AudioDownloaderType.DownloadProgressChanged += (sender, args) => pg_Download.Value = (int)args.ProgressPercentage; CheckForIllegalCrossThreadCalls = false; //Download Video FileDownloader.DownloadAudio(audioDownloader); } catch (Exception) { MessageBox.Show("Download cancelled"); EnableAccessAbility(); } }