private YouTubeVideo.DownloadInfo GetDownloadInfo(YouTubeVideo ytv, string format, string quality) { YouTubeVideo.DownloadInfo dl = null; foreach (var dlInfo in ytv.AvailableDownloads) { if (dlInfo.Resolution.Height.ToString() == quality && dlInfo.Format == format) { dl = dlInfo; } } return(dl); }
private void btnCopyLink_Click(object sender, RoutedEventArgs e) { YouTubeVideo.DownloadInfo dl = GetDownloadInfo(ytVideo, cbxFormat.SelectedValue as string, cbxResolution.SelectedValue as string); if (dl == null) { return; } string link = dl.DownloadUrl; Clipboard.SetText(link); MessageBox.Show("Copied download link to the clipboard. You can paste it anywhere.", "Copied link", MessageBoxButton.OK, MessageBoxImage.Information); }
private async void btnDownload_Click(object sender, RoutedEventArgs e) { string saveTo = null; YouTubeVideo.DownloadInfo info = GetDownloadInfo(ytVideo, cbxFormat.SelectedValue as string, cbxResolution.SelectedValue as string); if (info == null) { ClearUIText(); txtblTitle.Text = "Oops! Download information is unavailable. Refresh and try again..."; return; } UIEnabled(false); DownloadTask dl = null; await Task.Run(() => { dl = new DownloadTask(info.DownloadUrl) { FileName = ytVideo.Title + "." + info.Format }.Initialize(); }); downloadWindow.DlQueue.Add(dl); if (downloadWindow.chkStartNow.IsChecked.HasValue && downloadWindow.chkStartNow.IsChecked.Value) { saveTo = getSaveLocation(ytVideo); if (saveTo != null) { dl.DownloadAsync(saveTo); this.Close(); } UIEnabled(true); } else { this.Close(); } }
private async void RetrieveVideoSize(YouTubeVideo ytv) { cbxFormat.IsEnabled = false; cbxResolution.IsEnabled = false; lblVideoSize.Content = "Getting size..."; try { YouTubeVideo.DownloadInfo dlInfo = GetDownloadInfo(ytv, cbxFormat.SelectedValue as string, cbxResolution.SelectedValue as string); FileSize sz = await YouTubeVideo.GetVideoSizeAsync(dlInfo); lblVideoSize.Content = sz.ToString(); } catch { lblVideoSize.Content = "Unable to get size."; } finally { cbxFormat.IsEnabled = true; cbxResolution.IsEnabled = true; } }