Beispiel #1
0
        private async void AddChannelSubscriptionTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (YoutubeHelpers.TryParseChannelId(AddChannelSubscriptionTextBox.Text, out string channelId) && !Subscriptions.Any(x => x.ChannelId == channelId))
            {
                SubscriptionChannelId      = channelId;
                AddChannelButton.IsEnabled = true;
            }
            else if (YoutubeHelpers.TryParseUsername(AddChannelSubscriptionTextBox.Text, out string username))
            {
                try
                {
                    var client    = GlobalConsts.YoutubeClient;
                    var channelID = (await client.Channels.GetByUserAsync(username)).Id.Value;

                    if (!Subscriptions.Any(x => x.ChannelId == channelID))
                    {
                        SubscriptionChannelId      = channelID;
                        AddChannelButton.IsEnabled = true;
                    }
                    else
                    {
                        AddChannelButton.IsEnabled = false;
                    }
                }
                catch
                {
                    AddChannelButton.IsEnabled = false;
                }
            }

            else
            {
                AddChannelButton.IsEnabled = false;
            }
        }
        private async void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (YoutubeHelpers.TryParsePlaylistId(PlaylistLinkTextBox.Text, out string playlistId))
                {
                    _ = Task.Run(async() =>
                    {
                        Playlist basePlaylist = await client.Playlists.GetAsync(playlistId).ConfigureAwait(false);
                        list      = new FullPlaylist(basePlaylist, await client.Playlists.GetVideosAsync(basePlaylist.Id).BufferAsync().ConfigureAwait(false));
                        VideoList = new List <Video>();
                        await UpdatePlaylistInfo(Visibility.Visible, list.BasePlaylist.Title, list.BasePlaylist.Author, list.BasePlaylist.Engagement.ViewCount.ToString(), list.Videos.Count().ToString(), $"https://img.youtube.com/vi/{list?.Videos?.FirstOrDefault()?.Id}/0.jpg", true, true);
                    }).ConfigureAwait(false);
                }
                else if (YoutubeHelpers.TryParseChannelId(PlaylistLinkTextBox.Text, out string channelId))
                {
                    _ = Task.Run(async() =>
                    {
                        channel   = await client.Channels.GetAsync(channelId).ConfigureAwait(false);
                        list      = new FullPlaylist(null, null);
                        VideoList = await client.Channels.GetUploadsAsync(channel.Id).BufferAsync().ConfigureAwait(false);;
                        await UpdatePlaylistInfo(Visibility.Visible, channel.Title, totalVideos: VideoList.Count().ToString(), imageUrl: channel.LogoUrl, downloadEnabled: true, showIndexes: true);
                    }).ConfigureAwait(false);
                }
                else if (YoutubeHelpers.TryParseUsername(PlaylistLinkTextBox.Text, out string username))
                {
                    _ = Task.Run(async() =>
                    {
                        var channel = await client.Channels.GetByUserAsync(username).ConfigureAwait(false);
                        list        = new FullPlaylist(null, null);
                        VideoList   = await client.Channels.GetUploadsAsync(channel.Id).BufferAsync().ConfigureAwait(false);
                        await UpdatePlaylistInfo(Visibility.Visible, channel.Title, totalVideos: VideoList.Count().ToString(), imageUrl: channel.LogoUrl, downloadEnabled: true, showIndexes: true);
                    }).ConfigureAwait(false);
                }
                else if (YoutubeHelpers.TryParseVideoId(PlaylistLinkTextBox.Text, out string videoId))
                {
                    _ = Task.Run(async() =>
                    {
                        var video = await client.Videos.GetAsync(videoId);
                        VideoList = new List <Video> {
                            video
                        };
                        list = new FullPlaylist(null, null);
                        await UpdatePlaylistInfo(Visibility.Visible, video.Title, video.Author, video.Engagement.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);
            }
        }