getid(string channelid, string path)
        {
            var    client = new YoutubeClient();
            int    retry2 = 10;
            bool   Bretry = false;
            string video  = null;

            while (video == null)
            {
                if (retry2 == 0)
                {
                    Bretry = true;
                    break;
                }
                try
                {
                    video = await client.GetChannelIdAsync(channelid);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Retrying channel id download " + (11 - retry2) + " attempt");
                }
                retry2--;
                if (video == null)
                {
                    Thread.Sleep(1000);
                }
            }
            await getchannelshit(video, path);
        }
Example #2
0
        public async Task YoutubeClient_GetChannelIdAsync_Test(string username)
        {
            var client = new YoutubeClient();

            var channelId = await client.GetChannelIdAsync(username);

            Assert.That(channelId, Is.Not.Null.Or.Empty);
        }
        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);
            }
        }