public void YoutubeClient_ParseVideoId_Invalid_Test() { var data = File.ReadAllLines("Data\\InvalidVideoUrls.txt"); foreach (string datastr in data) { string url = datastr; Assert.ThrowsException <FormatException>(() => YoutubeClient.ParseVideoId(url)); } }
private async void DownloadButton_Click(object sender, RoutedEventArgs e) { DownloadButton.IsEnabled = false; //wybieranie ścieżki zapisu pliku FolderBrowserDialog FBD = new FolderBrowserDialog(); if (FBD.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (tbURL.Text != "") { var id = YoutubeClient.ParseVideoId(tbURL.Text); var client = new YoutubeClient(); if (FBD.SelectedPath != @"C:\") { // DownloadButton.Content = "Pobieranie video..."; var video = await client.GetVideoAsync(id.ToString()); pbDownloadProgress.Visibility = Visibility.Visible; tbInfoProgress.Visibility = Visibility.Visible; tbInfoProgress.Text = "Pobieranie..."; var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id.ToString()); var streamInfo = streamInfoSet.Muxed.WithHighestVideoQuality(); if (ExtensionList.SelectedValue != null) { string ext = ExtensionList.SelectedValue.ToString(); await client.DownloadMediaStreamAsync(streamInfo, GetFullPath(FBD.SelectedPath, video.Title, ext)); DownloadButton.Background = Brushes.LightGreen; //DownloadButton.Content = "Video pobrano pomyślnie!"; pbDownloadProgress.Visibility = Visibility.Hidden; tbInfoProgress.Visibility = Visibility.Hidden; } else { System.Windows.MessageBox.Show("Nie wybrano rozszerzenia pliku!"); } } else { System.Windows.MessageBox.Show("Niepoprawna ściażka do zapisu pliku!"); } } else { System.Windows.MessageBox.Show("Nie podałeś ścieżki URL do pliku!"); } } DownloadButton.IsEnabled = true; }
private async void descargarSoloVideo() { string link = "https://www.youtube.com/watch?v=fJ9rUzIMcZQ"; var url = link; var id = YoutubeClient.ParseVideoId(url); var client = new YoutubeClient(); var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id); var streamInfo = streamInfoSet.Video.WithHighestVideoQuality(); var ext = streamInfo.Container.GetFileExtension(); await client.DownloadMediaStreamAsync(streamInfo, $"downloaded_video.{ext}"); }
public void YoutubeClient_ParseVideoId_Valid_Test() { var data = File.ReadAllLines("Data\\ValidVideoUrls.txt"); foreach (string datastr in data) { string url = datastr.SubstringUntil(";"); string id = datastr.SubstringAfter(";"); string actualId = YoutubeClient.ParseVideoId(url); Assert.AreEqual(id, actualId); } }
private async void downloadMethod(object sender) { var id = YoutubeClient.ParseVideoId(Url); var client = new YoutubeClient(); var video = await client.GetVideoAsync(id); var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id); var streamInfo = streamInfoSet.Muxed.WithHighestVideoQuality(); var ext = streamInfo.Container.GetFileExtension(); string title = video.Title.Replace("/", "").Replace("\\", ""); await client.DownloadMediaStreamAsync(streamInfo, "D:\\" + title + ".mp4"); }
// Asynchronous method for obtaining video information private async Task LoadInfoVideoAsync() { try { string idVideo = YoutubeClient.ParseVideoId(this.url); var client = new YoutubeClient(); this.info = await client.GetVideoAsync(idVideo); } catch { this.info = null; } }
private string GetVideoTitle(string url) { try { var id = YoutubeClient.ParseVideoId(url); var yt = new YoutubeClient(); var video = yt.GetVideoAsync(id).Result; return(video.Title); } catch { return("Not a valid video."); } }
private async void QueryVideoEvent(object sender, RoutedEventArgs e) { try { string url = VideoPanel.UrlInput.Text; _model.Video = await _model.Client.GetVideoAsync(YoutubeClient.ParseVideoId(url)); VideoInfoPanel.SyncInfoToPanel(_model.Video, url, _model.Client, _model.MediaStreamInfos); PlayList.InitPlayListFromUrl(url, _model.Client); } catch (Exception ex) { // ignored } }
public YoutubeVideo(string Link) { this.Link = Link; videoID = YoutubeClient.ParseVideoId(Link); var client = new YoutubeClient(); // Get metadata for all streams in this video - now done at download time //this.StreamInfoSet = client.GetVideoMediaStreamInfosAsync(videoID).Result; // Get title of video, etc var videoTask = client.GetVideoAsync(videoID); videoTask.Wait(); this.Video = videoTask.Result; }
private async void LoadData() { try { currentId = YoutubeClient.ParseVideoId(currentUrl); currentUrl = urlTextBox.Text; var video = await client.GetVideoAsync(currentId); messageTxt.Text = video.Title; } catch (System.FormatException) { messageTxt.Text = "Couldn't parse URL"; } }
public async void SetMedia(Model.Medya medya) { vlcControl1.Visible = true; panel2.Visible = true; axVLCPlugin21.Visible = false; this.medya = medya; if (MedyaKontrol.ResimKontrol(medya.Path) && !medya.Path.StartsWith("http")) //TODO buraya bak. { vlcControl1.SetMedia(new FileInfo(@medya.Path)); panel2.Visible = false; vlcControl1.Play(); } else if (MedyaKontrol.VideoKontrol(medya.Path) && !medya.Path.StartsWith("http")) { vlcControl1.SetMedia(new FileInfo(@medya.Path)); panel2.Visible = true; vlcControl1.Play(); } else if (medya == null || medya.Path == null || medya.Path == "" || medya.Path == "-1") { MessageBox.Show("Medya boş veya hatalı!"); } else { _url = medya.Path; btnLink.Visible = true; if (YoutubeVideoID != String.Empty) { var url = medya.Path; var youtubeVidId = YoutubeClient.ParseVideoId(url); var yt = new YoutubeClient(); var video = await yt.GetVideoMediaStreamInfosAsync(youtubeVidId); var muxed = video.Muxed.WithHighestVideoQuality(); vlcControl1.SetMedia(new Uri(muxed.Url)); vlcControl1.Play(); } else { vlcControl1.Visible = false; panel2.Visible = false; axVLCPlugin21.Visible = true; axVLCPlugin21.playlist.add(medya.Path); axVLCPlugin21.playlist.play(); } } }
public static async Task <MuxedStreamInfo> GetInfoAsync(string url) { /* * print("URL2||||" + url); * * * YoutubeClient client = new YoutubeClient(); * * var id = YoutubeClient.ParseVideoId(url); * print("ID2::::" + id); * * var mediaStreamInfoSet = await client.GetVideoMediaStreamInfosAsync(id); * * // Select audio stream * var audioStreamInfo = mediaStreamInfoSet.Audio.WithHighestBitrate(); * * // Select video stream * var videoStreamInfo = mediaStreamInfoSet.Video.OrderBy(t => (t.Resolution.Height * t.Resolution.Width * t.Framerate)).First();//.FirstOrDefault(s => s.VideoQualityLabel == "1080p60"); * * // Combine them into a collection * var mediaStreamInfos = new MediaStreamInfo[] { audioStreamInfo, videoStreamInfo }; * print("LEN:" + mediaStreamInfos.Length); * return mediaStreamInfos;*/ var client = new YoutubeClient(); var id = YoutubeClient.ParseVideoId(url); // Get metadata for all streams in this video var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id); // Select one of the streams, e.g. highest quality muxed stream var streamInfo = streamInfoSet.Muxed.WithHighestVideoQuality(); // ...or highest bitrate audio stream // var streamInfo = streamInfoSet.Audio.WithHighestBitrate(); // ...or highest quality & highest framerate MP4 video stream // var streamInfo = streamInfoSet.Video // .Where(s => s.Container == Container.Mp4) // .OrderByDescending(s => s.VideoQuality) // .ThenByDescending(s => s.Framerate) // .First(); // Get file extension based on stream's container var ext = streamInfo.Container.GetFileExtension(); print("EXTENTION:" + ext); return(streamInfo); }
public VideoInfoPage(string url) { InitializeComponent(); isDone = false; var id = YoutubeClient.ParseVideoId(url); YoutubeClient client = new YoutubeClient(); Task.Run(async() => video = await client.GetVideoAsync(id)).Wait(); string title = video.Title; TimeSpan duration = video.Duration; string author = video.Author; browser.Source = new Uri(video.GetEmbedUrl()); }
private async Task <StreamInfo> GetSavePath(VideoModel video) { string videoId = YoutubeClient.ParseVideoId(video.VideoUrl); var streamInfo = await youtubeClient.GetVideoMediaStreamInfosAsync(videoId); var extension = streamInfo.Muxed[0].Container.GetFileExtension(); var thisVideo = await youtubeClient.GetVideoAsync(videoId); string newTitle = Extensions.RemoveInvalidChars(GetTrackFormat(video)); string savePath = Path.Combine(GetMusicDirectory(), $"{newTitle}.{extension}"); return(new StreamInfo() { StreamInfoSet = streamInfo, SavePath = savePath }); }
public async Task Download(string url, string destination) { var client = new YoutubeClient(); string id = YoutubeClient.ParseVideoId(url); var meta = await client.GetVideoAsync(id); var mediaStreamInfo = await client.GetVideoMediaStreamInfosAsync(id); var audioStreamInfo = mediaStreamInfo.Audio[0]; string fullPath = $"{destination}\\{Regex.Replace(meta.Title, @"[\/\\]+", "&")}.mp3"; await client.DownloadMediaStreamAsync(audioStreamInfo, fullPath); }
private async void downloadButton_Click(object sender, EventArgs e) { string id = YoutubeClient.ParseVideoId(youtubeURL.Text); Video video = await m_youtubeClient.GetVideoAsync(id); string name = video.Title; string filepath = await DownloadAudio(id); AddSound(id, name, filepath); if (string.IsNullOrEmpty(filepath) == false) { PlaySound(filepath); } }
private static async Task <bool> DownloadAlternate(Item itemToDownload, string targetPath, Progress <double> progress = null) { FileDownload fileDownload = null; try { if (File.Exists(targetPath)) { File.Delete(targetPath); } string youTubeVideoId = YoutubeClient.ParseVideoId(itemToDownload.PocketItem.Uri.ToString()); string saveMediaURL = $"https://dev.invidio.us/watch?v={youTubeVideoId}"; //"https://odownloader.com/download?q=" + HttpUtility.UrlEncode(itemToDownload.PocketItem.Uri.ToString()); using (WebClient client = new WebClient()) { client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); string html = client.DownloadString(saveMediaURL); string videoSources = Regex.Match(html, @"<source.*>").Value; string downloadURLWithHighestQuality = "https://www.invidio.us" + Regex.Match(videoSources, @"src=""([^""]*)""").Groups[1].Value; downloadURLWithHighestQuality = Utilities.GetRedirectURL(downloadURLWithHighestQuality); fileDownload = new FileDownload(downloadURLWithHighestQuality, targetPath, progress: progress); FilesDownloading.Add(fileDownload); await fileDownload.Start(); } FilesDownloading.Remove(fileDownload); //Remove download once it is completed return(true); } catch (Exception ex) { itemToDownload.Progress = -1; if (fileDownload != null) { FilesDownloading.Remove(fileDownload); } if (File.Exists(targetPath)) { File.Delete(targetPath); } } return(false); }
async private void getYoutubeFileProps(Stream stream) { var url = UrlText.Text; //var url = "https://www.youtube.com/watch?v=bnsUkE8i0tU"; var id = YoutubeClient.ParseVideoId(url); // "bnsUkE8i0tU" var client = new YoutubeClient(); var video = await client.GetVideoAsync(id); var title = video.Title; // "Infected Mushroom - Spitfire [Monstercat Release]" // StatusText.Text = String.Format("{0} ", title); var author = video.Author; // "Monstercat" var duration = video.Duration; // 00:07:14 var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id); var streamInfo = streamInfoSet.Muxed.WithHighestVideoQuality(); var ext = streamInfo.Container.GetFileExtension(); string displayName = Regex.Replace(title.ToString(), @"[^0-9a-zA-Z]+", "-"); var progressHandler = new Progress <double>(p => { Progress = p; StatusText1.Text = String.Format("{0}% of {1}% complete.", Convert.ToInt32(Math.Floor(p * 100)), 100); Debug.WriteLine(progress); if (p == 1) { MediaSource mediaSource = MediaSource.CreateFromStream(stream.AsRandomAccessStream(), "video/MPEG-4"); mediaPlayerElement.Source = mediaSource; mediaPlayerElement.AutoPlay = true; } }); try { await client.DownloadMediaStreamAsync(streamInfo, stream, progressHandler); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); StatusText1.Text = "Cannot download"; } }
private async Task <bool> GetVideoData() { var client = new YoutubeClient(); string id = Source; //Convert it to a regular ID if it is a youtube link try { id = YoutubeClient.ParseVideoId(Source); } catch { } //Get the video try { videoStreams = await client.GetVideoMediaStreamInfosAsync(id); } catch { return(false); } //Store the video urls and info Constants.videoInfo = videoStreams; return(true); }
public static string EmbedLink(string Link) { if (Link != "") { try { return("https://www.youtube.com/embed/" + YoutubeClient.ParseVideoId(Link)); } catch (FormatException) //link was invalid { return(""); } } else { return(""); } }
public async Task <VideoContentInfoDto> GetVideoInfoAsync(string url) { var client = new YoutubeClient(); var videoId = YoutubeClient.ParseVideoId(url); var video = await client.GetVideoAsync(videoId); var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(videoId); var videoInfo = _mapper.Map <VideoContentInfoDto>(video); _mapper.Map(streamInfoSet, videoInfo); //videoInfo.DownloadVideoUrls.ForEach(x => x.DownloadUrl = x.DownloadUrl.Replace("?", $"?title={videoInfo.Name.Replace(" ", "_")}&")); return(videoInfo); }
private void SetVideo(songreq request) { try { vlc.Position = 0; var id = YoutubeClient.ParseVideoId(request.ytlink); lblRequester.Text = request.requester; var yt = new YoutubeClient(); var video = yt.GetVideoMediaStreamInfosAsync(id).Result; var muxed = video.Muxed.WithHighestVideoQuality(); lblTitle.Text = GetVideoTitle(request.ytlink); vlc.SetMedia(new Uri(muxed.Url)); vlc.Play(); } catch { } }
public async Task <IList <FileInformation> > GetFileInformation(string[] urls) { var idList = urls.Select(url => YoutubeClient.ParseVideoId(url)).ToList(); var response = new List <FileInformation>(); foreach (var item in idList) { var vid = await YoutubeClient.GetVideoAsync(item); response.Add(new FileInformation { Tittle = vid.Title, Id = vid.Id, Thumbnails = vid.Thumbnails }); } return(response); }
public async void DownloadAsyncAudio(string url, Label labelLoadBar) { try { labelLoadBar.Content = "Starting Download"; var id = YoutubeClient.ParseVideoId(url); var client = new YoutubeClient(); var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id); var video = await client.GetVideoAsync(id); var mp4FileTitle = video.Title; var streamInfo = streamInfoSet.Muxed.FirstOrDefault(quality => quality.VideoQualityLabel == "360p"); var ext = streamInfo.Container.GetFileExtension(); string mp4Path = Directory.GetCurrentDirectory() + "\\Download\\" + mp4FileTitle + "." + ext; await client.DownloadMediaStreamAsync(streamInfo, mp4Path); labelLoadBar.Content = "Starting cover to mp3"; var convert = new NReco.VideoConverter.FFMpegConverter(); string mp3Path = Directory.GetCurrentDirectory() + "\\Download\\" + mp4FileTitle + ".mp3"; convert.ConvertMedia(mp4Path.Trim(), mp3Path.Trim(), "mp3"); labelLoadBar.Content = "Saving Url"; TagFile(url, mp3Path); labelLoadBar.Content = "Tmp File Removing"; System.IO.File.Delete(mp4Path); labelLoadBar.Content = "Audio is Ready"; } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private async void LoadInfo_TextChanged(object sender, TextChangedEventArgs e) { Info.Visibility = Visibility.Collapsed; IEnumerable <string> listOfExtension = new List <string>(); var client = new YoutubeClient(); var id = ""; try { id = YoutubeClient.ParseVideoId(tbURL.Text); pbDownloadProgress.Visibility = Visibility.Visible; tbInfoProgress.Visibility = Visibility.Visible; tbInfoProgress.Text = "Przetwarzanie..."; var video = await client.GetVideoAsync(id.ToString()); tbInfoProgress.Text = "Przetworzono!"; //Lista rozszerzeń plików var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id.ToString()); listOfExtension = streamInfoSet.GetAll().Select(s => s.Container.GetFileExtension()).Distinct(); ExtensionList.ItemsSource = listOfExtension; // Dane o filmie lblTitle.Text = video.Title; lblDescription.Text = video.Description; lblAuthor.Text = video.Author; lblDuration.Text = video.Duration.ToString(); Info.Visibility = Visibility.Visible; DownloadButton.Background = Brushes.Transparent; pbDownloadProgress.Visibility = Visibility.Hidden; tbInfoProgress.Visibility = Visibility.Hidden; }catch (FormatException) { System.Windows.MessageBox.Show("Niepoprawny format ścieżki! Nastąpi zakończenie działania programu.", "Uwaga", MessageBoxButton.OK, MessageBoxImage.Error); System.Diagnostics.Process.GetCurrentProcess().Kill(); } }
protected override void ProcessLinks(string[] links, string format) { var tasksToWait = new List <Task>(); long counter = 0; foreach (var link in links) { counter++; var client = new YoutubeClient(); uiService.WriteHeader($@"[{counter}] Processing link ""{link}"""); var id = YoutubeClient.ParseVideoId(link); var directoryToSaveVideo = $"../{_downloadFolderName}/{_downloadSubFolderName}"; ProcessVideo(format, id, client, $"{counter}", ref tasksToWait, directoryToSaveVideo); } uiService.WriteOutput($"Converting files, please wait..."); Task.WaitAll(tasksToWait.ToArray()); uiService.WriteOutput($"Converting files done."); }
public static async void CheckBitRate(string address, NSTextField infoLabelOne, NSTextField infoLabelTwo) { var client = new YoutubeClient(); var id = YoutubeClient.ParseVideoId(address); var video = await client.GetVideoAsync(id); var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id); var audioStream = streamInfoSet.Audio.WithHighestBitrate(); var encoding = audioStream.AudioEncoding.ToString(); var bitRate = audioStream.Bitrate.ToString(); var videoInfo = video.Author + "-" + video.Title; infoLabelOne.StringValue = videoInfo; infoLabelTwo.StringValue = encoding + ":" + bitRate; infoLabelOne.Hidden = false; infoLabelTwo.Hidden = false; }
private async void getVideo(string address, string saveLocation, bool video) { var client = new YoutubeClient(); var id = YoutubeClient.ParseVideoId(address); var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id); var streamInfo = streamInfoSet.Muxed.WithHighestVideoQuality(); var ext = streamInfo.Container.GetFileExtension(); if (video) { await client.DownloadMediaStreamAsync(streamInfo, saveLocation + "." + ext); } if (!video) { await client.DownloadMediaStreamAsync(streamInfo, saveLocation + "." + "mp3"); // var idMatch = } }
public static bool DownloadVideoViaYoutubeExplode(string url, string successPath, string failurePath, Action <double> progressHandler = null) { try { string id = YoutubeClient.ParseVideoId(url); YoutubeClient client = new YoutubeClient(); MediaStreamInfoSet streamInfoSet = client.GetVideoMediaStreamInfosAsync(id).Result; MuxedStreamInfo streamInfo = streamInfoSet.Muxed.First(m => m.Container.GetFileExtension().ToLower() == "mp4"); //string ext = streamInfo.Container.GetFileExtension(); client.DownloadMediaStreamAsync(streamInfo, successPath, progressHandler == null ? null : new Progress <double>(progressHandler)).Wait(); return(true); } catch (Exception exception) { Debug.WriteLine(exception); File.Create(failurePath).Close(); return(false); } }
public void AddYoutubeDetailPipeline(string urlField, string detailField, string videoField, string streamField, string captionField) { this.AddPipeline(it => { JObject obj = JObject.FromObject(it); var urlVideo = obj[urlField].ToString(); var client = new YoutubeClient(); var id = YoutubeClient.ParseVideoId(urlVideo); // "bnsUkE8i0tU" obj[detailField] = new JObject(); if (!string.IsNullOrEmpty(videoField)) { var video = client.GetVideoAsync(id).Result; var json1 = JsonConvert.SerializeObject(video, new StringEnumConverter()); obj[detailField][videoField] = JObject.Parse(json1); } if (!string.IsNullOrEmpty(streamField)) { var streamInfoSet = client.GetVideoMediaStreamInfosAsync(id).Result; var json2 = JsonConvert.SerializeObject(streamInfoSet, new StringEnumConverter()); obj[detailField][streamField] = JObject.Parse(json2); } if (!string.IsNullOrEmpty(captionField)) { var caption = client.GetVideoClosedCaptionTrackInfosAsync(id).Result; var json3 = JsonConvert.SerializeObject(caption, new StringEnumConverter()); obj[detailField][captionField] = JArray.Parse(json3); } //var streamInfo = (YoutubeExplode.Models.MediaStreams.MuxedStreamInfo)streamInfoSet.Muxed.OrderByDescending(o => o.Size).FirstOrDefault(); //var tmp = $"{Path.GetTempFileName()}.{streamInfo.Container.ToString().ToLower().Trim()}"; //var tas = client.DownloadMediaStreamAsync(streamInfo, tmp); //tas.Wait(); return(obj); }); }