private async void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (YoutubeClient.TryParsePlaylistId(PlaylistLinkTextBox.Text, out string playlistId))
                {
                    _ = Task.Run(async() =>
                    {
                        list = await client.GetPlaylistAsync(playlistId).ConfigureAwait(false);
                        VideoList.Clear();
                        await UpdatePlaylistInfo(Visibility.Visible, list.Title, list.Author, list.Statistics.ViewCount.ToString(), list.Videos.Count.ToString(), $"https://img.youtube.com/vi/{list?.Videos?.FirstOrDefault()?.Id}/0.jpg", true, true);
                    }).ConfigureAwait(false);
                }
                else if (YoutubeClient.TryParseChannelId(PlaylistLinkTextBox.Text, out string channelId))
                {
                    _ = Task.Run(async() =>
                    {
                        channel = await client.GetChannelAsync(channelId).ConfigureAwait(false);
                        list    = await client.GetPlaylistAsync(channel.GetChannelVideosPlaylistId());
                        VideoList.Clear();
                        await UpdatePlaylistInfo(Visibility.Visible, channel.Title, list.Author, list.Statistics.ViewCount.ToString(), list.Videos.Count.ToString(), channel.LogoUrl, true, true);
                    }).ConfigureAwait(false);
                }
                else if (YoutubeClient.TryParseUsername(PlaylistLinkTextBox.Text, out string username))
                {
                    _ = Task.Run(async() =>
                    {
                        string channelID = await client.GetChannelIdAsync(username).ConfigureAwait(false);
                        var channel      = await client.GetChannelAsync(channelID).ConfigureAwait(false);
                        list             = await client.GetPlaylistAsync(channel.GetChannelVideosPlaylistId()).ConfigureAwait(false);
                        VideoList.Clear();
                        await UpdatePlaylistInfo(Visibility.Visible, channel.Title, list.Author, list.Statistics.ViewCount.ToString(), list.Videos.Count.ToString(), channel.LogoUrl, true, true);
                    }).ConfigureAwait(false);
                }
                else if (YoutubeClient.TryParseVideoId(PlaylistLinkTextBox.Text, out string videoId))
                {
                    _ = Task.Run(async() =>
                    {
                        var video = await client.GetVideoAsync(videoId);
                        VideoList.Clear();
                        VideoList.Add(video);
                        list = null;
                        await UpdatePlaylistInfo(Visibility.Visible, video.Title, video.Author, video.Statistics.ViewCount.ToString(), string.Empty, $"https://img.youtube.com/vi/{video.Id}/0.jpg", true, false);
                    }).ConfigureAwait(false);
                }
                else
                {
                    await UpdatePlaylistInfo().ConfigureAwait(false);
                }
            }

            catch (Exception ex)
            {
                await GlobalConsts.Log(ex.ToString(), "MainPage TextBox_TextChanged");

                await GlobalConsts.ShowMessage((string)FindResource("Error"), ex.Message);
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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
            {
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public async Task YoutubeClient_GetChannelAsync_Test(string channelId)
        {
            var client = new YoutubeClient();

            var channel = await client.GetChannelAsync(channelId);

            Assert.That(channel, Is.Not.Null);
        }
Esempio n. 6
0
        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);
        }