//public Stream GetFileData() //{ //} public async Task <Stream> GetYoutubeData(string url) { var youtube = new YoutubeClient(); var memoryStream = new MemoryStream(); var videoId = new VideoId(url); var streams = await youtube.Videos.Streams.GetManifestAsync(videoId); var streamInfo = streams.GetAudioOnly(); var mp4Stream = streamInfo.SingleOrDefault(x => x.Container.Name == "mp4"); return(await youtube.Videos.Streams.GetAsync(mp4Stream)); }
public static async Task <string> New_Pull(string vidId) { YoutubeClient client = new YoutubeClient(); MediaStreamInfoSet videoInfo = await client.GetVideoMediaStreamInfosAsync(vidId); string RS = null; try { RS = videoInfo.Audio.OrderBy(p => p.Bitrate).First().Url; } catch (Exception ex) { } return(RS); }
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; }
internal static async Task <VideoInfo> CreateVideoInfo(YoutubeClient client, IMusicEncoderService encoder, string videoId) { var info = new VideoInfo() { client = client, encoder = encoder, videoId = videoId }; await info.GetMetadata(); return(info); }
public async Task <String> GetAudioStream(String youtubeURL) { var client = new YoutubeClient(); // Get stream manifest var manifest = await client.Videos.Streams.GetManifestAsync(youtubeURL); // Get Audio stream with highest Bitrate var streamInfo = manifest.GetAudioOnly().OrderByDescending(x => x.Bitrate).FirstOrDefault(); return(streamInfo.Url); }
public async Task YoutubeClient_GetPlaylistAsync_Truncated_Test(string playlistId) { const int pageLimit = 1; var client = new YoutubeClient(); var playlist = await client.GetPlaylistAsync(playlistId, pageLimit); Assert.That(playlist, Is.Not.Null); Assert.That(playlist.Id, Is.EqualTo(playlistId)); Assert.That(playlist.Videos, Is.Not.Null); Assert.That(playlist.Videos.Count, Is.LessThanOrEqualTo(200 * pageLimit)); }
public async Task I_can_get_videos_uploaded_by_any_available_YouTube_channel(string channelId) { // Arrange var youtube = new YoutubeClient(); // Act var videos = await youtube.Channels.GetUploadsAsync(channelId); // Assert videos.Should().NotBeEmpty(); videos.Select(v => v.ChannelId).Should().OnlyContain(i => i == channelId); }
public void YoutubeClient_TryParseVideoId_Invalid_Test() { var data = File.ReadAllLines("Data\\InvalidVideoUrls.txt"); foreach (string datastr in data) { string url = datastr; bool success = YoutubeClient.TryParseVideoId(url, out _); Assert.IsFalse(success); } }
public MainForm() { InitializeComponent(); BassNet.Registration("*****@*****.**", "2X11233721152222"); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_DEV_DEFAULT, 1); Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); InitialiseDeviceCombo(); client = new YoutubeClient(); RegisterHotKey(this.Handle, 1, (uint)0, (uint)Keys.MediaPreviousTrack); RegisterHotKey(this.Handle, 2, (uint)0, (uint)Keys.MediaNextTrack); RegisterHotKey(this.Handle, 3, (uint)0, (uint)Keys.MediaPlayPause); }
public async Task User_cannot_get_HTTP_live_stream_URL_from_an_unplayable_video() { // Arrange var youtube = new YoutubeClient(); // Act & assert var ex = await Assert.ThrowsAsync <VideoUnplayableException>(async() => await youtube.Videos.Streams.GetHttpLiveStreamUrlAsync(VideoIds.RequiresPurchase) ); _testOutput.WriteLine(ex.Message); }
public async Task User_cannot_get_HTTP_live_stream_URL_from_a_non_live_video() { // Arrange var youtube = new YoutubeClient(); // Act & assert var ex = await Assert.ThrowsAsync <YoutubeExplodeException>(async() => await youtube.Videos.Streams.GetHttpLiveStreamUrlAsync(VideoIds.Normal) ); _testOutput.WriteLine(ex.Message); }
public async Task YoutubeClient_GetPlaylistInfoAsync_Test() { var id = (string)TestContext.DataRow["Id"]; var minVideoCount = (int)TestContext.DataRow["MinVideoCount"]; var client = new YoutubeClient(); var playlistInfo = await client.GetPlaylistInfoAsync(id); Assert.That.IsSet(playlistInfo); Assert.AreEqual(id, playlistInfo.Id); Assert.IsTrue(minVideoCount <= playlistInfo.Videos.Count); }
public async Task User_cannot_get_the_list_of_available_streams_on_a_non_existing_video() { // Arrange var youtube = new YoutubeClient(); // Act & assert var ex = await Assert.ThrowsAsync <VideoUnavailableException>(async() => await youtube.Videos.Streams.GetManifestAsync(VideoIds.NonExisting) ); _testOutput.WriteLine(ex.Message); }
public async Task YoutubeClient_GetClosedCaptionTrackAsync_Test() { var id = (string)TestContext.DataRow["Id"]; var client = new YoutubeClient(); var videoInfo = await client.GetVideoInfoAsync(id); var trackInfo = videoInfo.ClosedCaptionTracks.First(); var track = await client.GetClosedCaptionTrackAsync(trackInfo); Assert.That.IsSet(track); }
public async Task YoutubeClient_GetPlaylistInfoAsync_Truncated_Test() { var id = (string)TestContext.DataRow["Id"]; var pageLimit = 1; var client = new YoutubeClient(); var playlistInfo = await client.GetPlaylistInfoAsync(id, pageLimit); Assert.That.IsSet(playlistInfo); Assert.AreEqual(id, playlistInfo.Id); Assert.IsTrue(200 * pageLimit >= playlistInfo.Videos.Count); }
public override async Task <bool> Download(Archive a, AbsolutePath destination) { try { using var queue = new WorkQueue(); await using var folder = await TempFolder.Create(); folder.Dir.Combine("tracks").CreateDirectory(); var client = new YoutubeClient(Common.Http.ClientFactory.Client); var meta = await client.Videos.GetAsync(Key); var video = await client.Videos.Streams.GetManifestAsync(Key); var stream = video.Streams.OfType <AudioOnlyStreamInfo>().Where(f => f.AudioCodec.StartsWith("mp4a")).OrderByDescending(a => a.Bitrate) .ToArray().First(); var initialDownload = folder.Dir.Combine("initial_download"); var trackFolder = folder.Dir.Combine("tracks"); await using (var fs = initialDownload.Create()) { await client.Videos.Streams.CopyToAsync(stream, fs, new Progress($"Downloading {a.Name}"), CancellationToken.None); } await initialDownload.CopyToAsync(destination.WithExtension(new Extension(".dest_stream"))); await Tracks.PMap(queue, async track => { Utils.Status($"Extracting track {track.Name}"); await ExtractTrack(initialDownload, trackFolder, track); }); await using var dest = destination.Create(); using var ar = new ZipArchive(dest, ZipArchiveMode.Create); foreach (var track in trackFolder.EnumerateFiles().OrderBy(e => e)) { Utils.Status($"Adding {track.FileName} to archive"); var entry = ar.CreateEntry(Path.Combine("Data", "tracks", (string)track.RelativeTo(trackFolder)), CompressionLevel.NoCompression); entry.LastWriteTime = meta.UploadDate; await using var es = entry.Open(); await using var ins = track.OpenRead(); await ins.CopyToAsync(es); } return(true); } catch (VideoUnavailableException) { return(false); } }
public static async Task <MediaStreamInfoSet> GetMediaStreamInfoAsync(Video video) { if (video == null) { return(null); } using HttpClient httpClient = new HttpClient(); YoutubeClient client = new YoutubeClient(httpClient); return(await client.GetVideoMediaStreamInfosAsync(video.Id)); }
public YtService(string key) { this.key = key; this.ytExplode = new YoutubeClient(); if (!string.IsNullOrWhiteSpace(key)) { this.yt = new YouTubeService(new BaseClientService.Initializer { ApiKey = key, ApplicationName = TheGodfather.ApplicationName }); } }
static async Task getplaylist(string channelid, string path) { var client = new YoutubeClient(); YoutubeExplode.Models.Playlist video = null; int retry2 = 10; bool Bretry = false; Console.WriteLine("Downloading playlist started " + channelid); while (video == null) { if (retry2 == 0) { Bretry = true; break; } try { video = await client.GetPlaylistAsync(channelid); } catch (Exception e) { Console.WriteLine("Retrying playlist download " + (11 - retry2) + " attempt"); } retry2--; if (video == null) { Thread.Sleep(1000); } else { break; } } // var video = await client.GetChannelUploadsAsync(channelid); if (video != null) { try { foreach (var x in video.Videos) { await getshit(x.Id, path, false, null); } } catch (Exception x) { Console.WriteLine(x); } // Console.WriteLine("Downloading channel finished " + channelid); } }
public static async Task DownloadPlayListInformationOneAtATime(string playlistUrl, string path, int count = 0, int waitTime = 500) { var youtube = new YoutubeClient(); // Get playlist metadata var playlist = await youtube.Playlists.GetAsync(playlistUrl); var title = playlist.Title; Console.WriteLine($"Downloading Playlist: {title}"); var author = playlist.Author; var description = playlist.Description; IReadOnlyList <YoutubeExplode.Videos.Video> somePlayListVideos = default; // /* * It is possible to just call the playlist onetime and use the GetAsyncEnumerator * then using that count/length property to figure which is smaller. * The lazy option was choosen instead */ try { //if the count is equal to zero move to the catch to get all the videos if (count == 0) { throw new Exception(); } // Get videos from 0 to the count somePlayListVideos = await youtube.Playlists .GetVideosAsync(playlist.Id) .BufferAsync(count); } catch { somePlayListVideos = await youtube.Playlists.GetVideosAsync(playlist.Id); } finally { string newPath = $"{path}/{title}/"; System.IO.FileInfo file = new System.IO.FileInfo(newPath); file.Directory.Create(); // If the directory already exists, this method does nothing. _ = File.WriteAllLinesAsync($"{file.FullName}/playlist-info.txt", new string[] { title, author, description }); List <Task> tempTaskList = new List <Task>(); for (int i = 0; i < somePlayListVideos.Count; i++) { Console.WriteLine($"Starting videos {i+1} of {somePlayListVideos.Count}"); YoutubeVideo.DownloadAudioVideoMuxButNoCaption(somePlayListVideos[i], newPath).Wait(); System.Threading.Thread.Sleep(waitTime); } }; }
public async Task I_can_get_a_subset_videos_uploaded_by_any_available_YouTube_channel(string channelId) { // Arrange const int maxVideoCount = 50; var youtube = new YoutubeClient(); // Act var videos = await youtube.Channels.GetUploadsAsync(channelId).BufferAsync(maxVideoCount); // Assert videos.Should().NotBeEmpty(); videos.Should().HaveCountLessOrEqualTo(maxVideoCount); }
Task <FileStreamResult> DownloadAsync(string id) { var YT = new YoutubeClient(); var videoname0 = await YT.Videos.GetAsync(id); var strs = await YT.Videos.Streams.GetManifestAsync(id); var high = strs.GetMuxedStreams().GetWithHighestVideoQuality(); string sanitized = fixstr(videoname0.Title); return(File(YT.Videos.Streams.GetAsync(high).Result, $"video/{high.Container.Name}", $"{sanitized}.{high.Container.Name}", true)); }
public async Task <IActionResult> SearchAsync(string id) { var YT = new YoutubeClient(); var vids1 = YT.Search.GetVideosAsync(id); string s = ""; await vids1.ForEachAsync((v) => { s += $"{v.Id}\n"; }); return(File(ASCIIEncoding.Default.GetBytes(s), "text/plain", "query.txt", true)); }
public async Task I_can_search_for_YouTube_videos_and_get_a_subset_of_results() { // Arrange const int maxVideoCount = 50; var youtube = new YoutubeClient(); // Act var videos = await youtube.Search.GetVideosAsync("billie eilish").BufferAsync(maxVideoCount); // Assert videos.Should().NotBeEmpty(); videos.Should().HaveCountLessOrEqualTo(maxVideoCount); }
[InlineData("OLAK5uy_mtOdjCW76nDvf5yOzgcAVMYpJ5gcW5uKU")] // large 2 public async Task I_can_get_a_subset_of_videos_included_in_any_available_YouTube_playlist(string playlistId) { // Arrange const int maxVideoCount = 50; var youtube = new YoutubeClient(); // Act var videos = await youtube.Playlists.GetVideosAsync(playlistId).BufferAsync(maxVideoCount); // Assert videos.Should().NotBeEmpty(); videos.Should().HaveCountLessOrEqualTo(maxVideoCount); }
public YoutubeFeed() { _youtubeClient = new YoutubeClient(); _youtubeService = new YouTubeService( new BaseClientService.Initializer { ApiKey = "AIzaSyD0E4ozDor6cgdyQKHvOgLCrrQMEX226Qc", ApplicationName = "YouCast2", }); Logger.Info($"{nameof(YoutubeFeed)} created"); }
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 async Task YoutubeClient_GetChannelUploadsAsync_Test() { string id = (string)TestContext.DataRow["Id"]; var client = new YoutubeClient(); var videos = await client.GetChannelUploadsAsync(id); Assert.IsNotNull(videos); foreach (var video in videos) { Assert.That.IsSet(video); } }
public async Task User_can_get_the_highest_resolution_thumbnail_from_a_video() { // Arrange var youtube = new YoutubeClient(); // Act var video = await youtube.Videos.GetAsync(VideoIds.Normal); var thumbnail = video.Thumbnails.GetWithHighestResolution(); // Assert thumbnail.Url.Should().NotBeNullOrWhiteSpace(); }
public async Task I_can_get_videos_uploaded_by_a_YouTube_channel() { // Arrange const string channelUrl = "https://www.youtube.com/channel/UCEnBXANsKmyj2r9xVyKoDiQ"; var youtube = new YoutubeClient(); // Act var videos = await youtube.Channels.GetUploadsAsync(channelUrl); // Assert videos.Should().HaveCountGreaterOrEqualTo(80); videos.Select(v => v.ChannelId).Should().OnlyContain(i => i == "UCEnBXANsKmyj2r9xVyKoDiQ"); }
public async void TestGet() { var api = new YoutubeClient(); await api.Execute(api => api.Channles.List().WithOptional(new Model.Optional.BaseOptional { })); }