async public Task DownloadChannel(string channelId) { try { var channelInfo = await client.GetChannelAsync(channelId); Console.WriteLine(channelInfo.Title); var channelUploads = await client.GetChannelUploadsAsync(channelId); var folder = $@"F:\Videos\Youtube\{channelInfo.Title} [{channelId}]"; System.IO.Directory.CreateDirectory(folder); var downloadedVideos = System.IO.Directory.EnumerateFiles(folder) .Select(n => n.Split(".") .Reverse() .ToList()[1] .Trim('[') .Trim(']') ) .ToList(); foreach (var video in channelUploads) { if (downloadedVideos.Contains(video.Id)) { continue; } await DownloadVideo(video.Id, folder); } } catch { } }
getchannelshit(string channelid, string path) { var client = new YoutubeClient(); IReadOnlyList <YoutubeExplode.Models.Video> video = null; int retry2 = 10; bool Bretry = false; YoutubeExplode.Models.Channel channel = null; Console.WriteLine("Downloading channel started " + channelid); while (video == null) { if (retry2 == 0) { Bretry = true; break; } try { video = await client.GetChannelUploadsAsync(channelid); channel = await client.GetChannelAsync(channelid); } catch (Exception e) { Console.WriteLine("Retrying channel 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) { try { await getshit(x.Id, path, false, channel.Title); } catch (Exception e) { Console.WriteLine("getshiterror\n" + e); } } } catch (Exception x) { Console.WriteLine(x); } } // Console.WriteLine("Downloading channel finished " + channelid); }
static async Task <int> RunInfo(InfoVerb verb) { foreach (var source in verb.Source) { if (YoutubeClient.ValidateChannelId(source)) { var channel = await youtube.GetChannelAsync(source); Console.WriteLine(channel.Title); var uploads = await youtube.GetChannelUploadsAsync(source, 1); for (var i = 0; i < Math.Min(3, uploads.Count); i++) { var upload = uploads[i]; Console.WriteLine($"- {upload.Title} (id: {upload.Id}, date: {upload.UploadDate.Date.ToShortDateString()}, duration: {upload.Duration})"); } } else if (YoutubeClient.ValidateVideoId(source)) { var video = await youtube.GetVideoAsync(source); Console.WriteLine(video.Title); } } return(0); }
/*public bool GetVideoThumbnail(string path, string saveThumbnailTo, int seconds) * { * string parameters = $"-ss {seconds} -i {path} -f image2 -vframes 1 -y {saveThumbnailTo}"; * * var processInfo = new ProcessStartInfo(); * processInfo.FileName = pathToConvertor; * processInfo.Arguments = parameters; * processInfo.CreateNoWindow = true; * processInfo.UseShellExecute = false; * * File.Delete(saveThumbnailTo); * * using (var process = new Process()) * { * process.StartInfo = processInfo; * process.Start(); * process.WaitForExit(); * } * * return File.Exists(saveThumbnailTo); * }*/ private static void Test() { var client = new YoutubeClient(); client.GetChannelUploadsAsync("UCZqh6VE-OYFz2RCWDbZQOqw").ContinueWith(task => { var video = task.Result.FirstOrDefault(v => v.Title.Contains("listening practice test")); client.GetVideoAsync("").ContinueWith(t => { //t.Result. //t.Result. }); client.GetVideoClosedCaptionTrackInfosAsync(video.Id).ContinueWith(task1 => { //task1.Result[0]. var captionTrackInfo = task1.Result.FirstOrDefault(info => info.Language.Code == "en"); client.GetClosedCaptionTrackAsync(captionTrackInfo).ContinueWith(task2 => { var captionTrack = task2.Result; foreach (var captionTrackCaption in captionTrack.Captions) { Console.WriteLine($"{captionTrackCaption.Offset}: {captionTrackCaption.Text}"); } }); }); }); }
/// <summary> /// Gets the youtube channels video's. /// </summary> /// <param name="id">The id of the youtube channel.</param> /// <returns>A list of video info.</returns> public async Task <List <VideoInfo> > GetYoutubeChannel(string id) { var client = new YoutubeClient(); var videos = await client.GetChannelUploadsAsync(id); return(videos.Select(v => new VideoInfo(v)).ToList()); }
public async Task <IEnumerable <Video> > VideoOfChannel(string channel) { var client = new YoutubeClient(); var list = await client.GetChannelUploadsAsync(channel); return(list); }
static async Task Load() { var client = new YoutubeClient(); var list = await client.GetChannelUploadsAsync("UC4V3oCikXeSqYQr0hBMARwg"); foreach (var video in list) { var tubeUrl = video.GetUrl(); if (await(await videoCollection.FindAsync(x => x.YoutubeUrl == tubeUrl)).AnyAsync()) { continue; } var info = await client.GetVideoClosedCaptionTrackInfosAsync(video.Id); if (info.Count <= 0) { continue; } var minfo = await client.GetVideoMediaStreamInfosAsync(video.Id); var subVideo = new SubVideo { Title = video.Title, YoutubeUrl = tubeUrl, Thumbnail = video.Thumbnails.MediumResUrl, SourceUrl = minfo.Muxed[0].Url, Published = video.UploadDate.DateTime }; await videoCollection.InsertOneAsync(subVideo); var captions = await client.GetClosedCaptionTrackAsync(info.First()); var mergedCaptions = new List <VideoText>(); for (int i = 0; i < captions.Captions.Count; i++) { for (int size = 1; size < 4; size++) { var cap = captions.Captions.Skip(i).Take(size).Aggregate((f, s) => new ClosedCaption($"{f.Text} {s.Text}", f.Offset, f.Duration + s.Duration)); mergedCaptions.Add(new VideoText { VideoId = subVideo.Id, OffSet = cap.Offset, Text = cap.Text, Duration = cap.Duration }); } } await textCollection.InsertManyAsync(mergedCaptions); } }
public async Task YoutubeClient_GetChannelUploadsAsync_Test(string channelId) { var client = new YoutubeClient(); var videos = await client.GetChannelUploadsAsync(channelId); Assert.That(videos, Is.Not.Null); }
public async Task LoadChannel(string channelId) { var client = new YoutubeClient(); var list = await client.GetChannelUploadsAsync(channelId); foreach (var video in list) { await _video.InsertOneAsync(await GetSubtitledVideoAsync(video.Id)); } }
public async Task YoutubeClient_GetChannelUploadsAsync_Test() { var client = new YoutubeClient(); var videos = await client.GetChannelUploadsAsync("UC2pmfLm7iq6Ov1UwYrWYkZA"); Assert.IsNotNull(videos); foreach (var video in videos) { Assert.That.IsSet(video); } }
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 override Podcast Parse(string url) { var channelId = Utils.YTUrlParser(url); var podcast = new Podcast(); var yc = new YoutubeClient(); var channel = yc.GetChannelAsync(channelId).Result; podcast.Title = channel.Title; podcast.Description = channel.Title; podcast.Image = channel.LogoUrl; podcast.Link = "https://www.youtube.com/channel/" + channelId; podcast.Host = "www.youtube.com"; podcast.Copyright = podcast.Title; podcast.Items = new List <Item>(); foreach (var upload in yc.GetChannelUploadsAsync(channelId, 1).Result.Take(10).ToList()) { var item = new Item(); item.Duration = upload.Duration.ToString(@"hh\:mm\:ss"); item.Title = upload.Title; item.Keywords = upload.Keywords.ToList(); item.Description = upload.Description; item.PubDate = Utils.ConvertToPubDate(upload.UploadDate.DateTime); item.Image = upload.Thumbnails.LowResUrl; item.Guid = upload.Id; item.Link = "https://www.youtube.com/watch?v=" + item.Guid; var(flink, fmime) = Utils.YTGetAudioLinks(upload.Id); item.EncloseUrl = flink; item.EncloseType = fmime; item.Length = (long)upload.Duration.TotalMilliseconds; if (string.IsNullOrWhiteSpace(item.EncloseUrl)) { continue; } podcast.Items.Add(item); if (podcast.Keywords == null || podcast.Keywords.Count == 0) { podcast.Keywords = item.Keywords; } if (podcast.Author == null) { podcast.Author = upload.Author; } } ; podcast.CreationTimestamp = DateTime.UtcNow; podcast.BuildTimestamp = podcast.CreationTimestamp; return(podcast); }
/// <summary> /// Get the playList videos /// </summary> /// <param name="playlistId">comma seperated ids</param> /// <returns></returns> public async Task <IEnumerable <VideoWrapper> > GetChannelVideosAsync(string channelId, int pageNumber = 1, int pageSize = 30) { return((await dataContext.GetChannelUploadsAsync(channelId, pageNumber, pageSize))?.Select(x => Create(x))); }