private void VideoData(string link, bool playlist = false) { var video = youTube.GetAllVideos(link); // gets a Video object with info about the video var resolutions = video.Where(j => j.AdaptiveKind == AdaptiveKind.Video && j.Format == VideoFormat.Mp4).Select(j => j.Resolution); var bitRates = video.Where(j => j.AdaptiveKind == AdaptiveKind.Audio).Select(j => j.AudioBitrate); foreach (var val in resolutions) { Quality.Invoke((MethodInvoker)(() => Quality.Items.Add(val))); } foreach (var val in bitRates) { AudioQuality.Invoke((MethodInvoker)(() => AudioQuality.Items.Add(val))); } if (Quality.Items.Count > 0) { Quality.Invoke((MethodInvoker)(() => Quality.Sorted = true)); Quality.Invoke((MethodInvoker)(() => Quality.SelectedIndex = 0)); AudioQuality.Invoke((MethodInvoker)(() => AudioQuality.Sorted = true)); AudioQuality.Invoke((MethodInvoker)(() => AudioQuality.SelectedIndex = 0)); Vid.Invoke((MethodInvoker)(() => Vid.Enabled = true)); VidTitle.Invoke((MethodInvoker)(() => VidTitle.Text = video.ToList()[0].Title)); } if (playlist) { Status.Text = listVidsIds.Count + " Videos"; } else { Status.Text = "Single Video"; } }
private void DownloadBtnClick(object sender, RoutedEventArgs e) { Regex YtRegex = new Regex(@"http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-_]*)(&(amp;)?[\w\?=]*)?"); if (!YtRegex.IsMatch(YoutubeBrowser.Address)) { MessageBox.Show("올바른 유튜브 영상 링크가 아닙니다."); return; } new Action(async() => { YouTube yt = YouTube.Default; var items = yt.GetAllVideos(YoutubeBrowser.Address).ToList(); items = items.OrderByDescending(item => item.AudioBitrate).ToList(); foreach (var item in items) { Debug.WriteLine(item.FullName + " - " + item.AudioBitrate); } File.WriteAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\musics\" + items[0].FullName, await items[0].GetBytesAsync()); var inputFile = new MediaFile { Filename = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\musics\" + items[0].FullName }; var outputFile = new MediaFile { Filename = $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\musics\" + items[0].FullName}.mp3" }; using (var engine = new Engine()) { engine.GetMetadata(inputFile); engine.Convert(inputFile, outputFile); File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\musics\" + items[0].FullName); Refresh(); } }).Invoke(); }
public static IEnumerable <VideoInfo> GetDownloadUrls(string videoUrl, bool decryptSignature = true) { Require.NotNull(videoUrl, nameof(videoUrl)); // GetAllVideos normalizes the URL as of libvideo v0.4.1, // don't call TryNormalizeYoutubeUrl here. return(Service.GetAllVideos(videoUrl).Select(v => new VideoInfo(v))); }
private YouTubeVideo getVideo(string url) { var videos = youtubeService.GetAllVideos(url); ListBoxItem selectedRes = (ListBoxItem)resolutionBox.SelectedItem; string resolution = selectedRes.Content.ToString(); bool highest = resolution == "highest" ? true : false; YouTubeVideo selectVideo = null; YouTubeVideo highestVideo = null; foreach (var v in videos) { string currentFormat = v.Format.ToString().ToLower(); if (currentFormat == defaultFormat && highestVideo == null) { highestVideo = v; } else if (currentFormat == defaultFormat && highestVideo.Resolution < v.Resolution) { highestVideo = v; if (highest) { selectVideo = highestVideo; } } if (currentFormat == defaultFormat && v.Resolution.ToString() == resolution) { selectVideo = v; } } if (selectVideo == null) { MessageBox.Show("No video found with the selected resolution. Use resolution " + highestVideo.Resolution.ToString() + " instead."); selectVideo = highestVideo; } return(selectVideo); }
void GetVideos() { var youtubeDownloader = new YouTube(); foreach (var url in videoDownloadUrls) { var videos = youtubeDownloader.GetAllVideos(url); var video = videos.Where(c => c.Resolution == 240); if (video.Any()) { var first = video.First(); var videoBytes = first.GetBytes(); var videoName = first.FullName; File.WriteAllBytes(@"C:\YoutubeDownloads\" + videoName, videoBytes); } } }
private void linkButton_Click(object sender, EventArgs e) { Program.Log($"\t{sender} Button pressed"); try { YouTube youTube = YouTube.Default; IEnumerable <YouTubeVideo> video = youTube.GetAllVideos(linkTextBox.Text); AddNewDownloadJob(video); } catch (ArgumentException ae) { Program.Log($"\tLink not correct or couldn't find the video location.\n\t{ae.Message}", true, DisplayError); } catch (UnauthorizedAccessException uae) { Program.Log("\tCan't put file in that directory." + "Hopefully you're ok with the default location.\n" + $"\t{uae.Message}", true, DisplayError); } }
private void getMetaData() { YouTube youtube = YouTube.Default; ReturnError results = new ReturnError(); try { YouTubeVideo audio = youtube.GetAllVideos(_link) //.Where(e => e.AudioFormat == AudioFormat.Aac && e.AdaptiveKind == AdaptiveKind.Audio) .ToList() .FirstOrDefault(); string filename = audio.FullName.Replace(" - YouTube", ""); filename = filename.Replace(".mp4", ""); MediaFile inputFile = new MediaFile { Filename = audio.GetUri() }; using (Engine engine = new Engine()) { engine.GetMetadata(inputFile); video.VideoName = filename; if (inputFile.Metadata.Duration.ToString().StartsWith("00")) { video.Length = inputFile.Metadata.Duration.ToString().Substring(3, 5); } else { video.Length = inputFile.Metadata.Duration.ToString().Substring(0, 8); } } } catch (NullReferenceException e) { results.errorNumber++; results.errorLinks.Add(_link); } }
/// <summary> /// Method to get all data of the video /// </summary> /// <param name="link"></param> private void GetVideoData(string link) { var videoData = youtube.GetAllVideos(link); var resolution = videoData.Where(r => r.AdaptiveKind == AdaptiveKind.Video && r.Format == VideoFormat.Mp4) .Select(r => r.Resolution); var bitRate = videoData.Where(r => r.AdaptiveKind == AdaptiveKind.Audio).Select(r => r.AudioBitrate); foreach (var item in resolution) { cmbQuality.Invoke((MethodInvoker)(() => cmbQuality.Items.Add(item))); } foreach (var item in bitRate) { cmbQuality.Invoke((MethodInvoker)(() => cmbQuality.Items.Add(item))); } if (cmbQuality.Items.Count > 0) { cmbQuality.Invoke((MethodInvoker)(() => cmbQuality.Sorted = true)); cmbQuality.Invoke((MethodInvoker)(() => cmbQuality.SelectedIndex = 0)); txtTitle.Invoke((MethodInvoker)(() => txtTitle.Text = videoData.ToList()[0].Title)); } }
public ReturnError DownloadMP3(List <string> links, string destPath) { _songCount = links.Count; if (_songCount == 0) { throw new Exception("No links available."); } if (!Directory.Exists(destPath)) { throw new DirectoryNotFoundException("Destination path does not exist."); } YouTube youtube = YouTube.Default; convertedSong = 0; ReturnError results = new ReturnError(); results.errorNumber = 0; results.errorLinks = new List <string>(); foreach (string link in links) { if (link.Contains("&list=")) { downloadPlaylist(link, destPath, "", 0); } else { try { YouTubeVideo audio = youtube.GetAllVideos(link) .Where(e => e.AudioFormat == AudioFormat.Aac && e.AdaptiveKind == AdaptiveKind.Audio) .ToList() .FirstOrDefault(); string filename = Path.ChangeExtension( Path.Combine(destPath, Path.GetFileNameWithoutExtension(audio.FullName)), "mp3"); filename = filename.Replace(" - YouTube", ""); MediaFile inputFile = new MediaFile { Filename = audio.GetUri() }; MediaFile outputFile = new MediaFile { Filename = filename }; getThumbnail(link); using (Engine engine = new Engine()) { engine.GetMetadata(inputFile); engine.Convert(inputFile, outputFile); engine.ConvertProgressEvent += engine_ConvertProgressEvent; } } catch (NullReferenceException e) { results.errorNumber++; results.errorLinks.Add(link); } } } return(results); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs evt) { try { YouTube youtube = YouTube.Default; var backgroundWorker = sender as BackgroundWorker; backgroundWorker1.ReportProgress(10); if (betterAudioQualityToolStripMenuItem.Checked) { var vid = youtube.GetAllVideos(this.txtLink.Text); var audio = vid .Where(e => e.AudioFormat == AudioFormat.Aac && e.AdaptiveKind == AdaptiveKind.Audio) .ToList(); this.videoTitle = audio[0].Title; if (audio.Count > 0) { backgroundWorker1.ReportProgress(10); System.IO.File.WriteAllBytes(Path.Combine(folderName, audio[0].FullName), audio[0].GetBytes()); backgroundWorker1.ReportProgress(30); var inputFile = new MediaFile { Filename = Path.Combine(folderName, audio[0].FullName) }; var outputFile = new MediaFile { Filename = $"{Path.Combine(folderName, audio[0].FullName)}.mp3" }; backgroundWorker1.ReportProgress(20); using (var engine = new Engine()) { backgroundWorker1.ReportProgress(10); engine.Convert(inputFile, outputFile); backgroundWorker1.ReportProgress(10); } File.Delete(Path.Combine(folderName, audio[0].FullName)); backgroundWorker1.ReportProgress(10); } } else { YouTubeVideo audio = youtube.GetVideo(this.txtLink.Text); this.videoTitle = audio.Title; backgroundWorker1.ReportProgress(10); File.WriteAllBytes(Path.Combine(folderName, audio.FullName), audio.GetBytes()); backgroundWorker1.ReportProgress(30); var inputFile = new MediaFile { Filename = Path.Combine(folderName, audio.FullName) }; var outputFile = new MediaFile { Filename = $"{Path.Combine(folderName, audio.FullName)}.mp3" }; backgroundWorker1.ReportProgress(20); using (var engine = new Engine()) { backgroundWorker1.ReportProgress(10); engine.Convert(inputFile, outputFile); backgroundWorker1.ReportProgress(10); } File.Delete(Path.Combine(folderName, audio.FullName)); backgroundWorker1.ReportProgress(10); } if (backgroundWorker1.CancellationPending) { evt.Cancel = true; } } catch (ThreadAbortException ex) { } catch (Exception e) { this.Invoke((Func <DialogResult>)(() => MessageBox.Show(this, "No se puede descargar el vídeo.\nCompruebe el enlace."))); } }