Example #1
0
        private async void LoadingView_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (_url == null)
                {
                    throw new NullReferenceException(nameof(_url));
                }
                var videos = await VideoService.GetVideosAsync(_url);

                IReadOnlyList <VideoDownloadOption>?videoOptions;
                string?title = default;

                if (videos.Length == 1)
                {
                    videoOptions = await VideoService.GetVideoDownloadOptionsAsync(_url);
                }
                else
                {
                    videoOptions = YoutubeVideoService.GetOptionPlaylist().Reverse().ToArray();
                    title        = await VideoService.GetPlaylistTitle(_url);
                }

                DialogHost.Close("MainDialog", new YoutubeVideoModel(videos, videoOptions, title));
            }
            catch (Exception)
            {
                DialogHost.Close("MainDialog");
            }
        }
        private async void AddVideoToList(object s)
        {
            if (IsLoading || string.IsNullOrWhiteSpace(s as string))
            {
                return;
            }
            string url = (string)s;

            try
            {
                IsLoading = true;
                var videos = await _youtubeservise.GetVideosAsync(url);

                IReadOnlyList <VideoDownloadOption>?videoOptions;
                string?title = default;

                if (videos.Length == 1)
                {
                    videoOptions = await _youtubeservise.GetVideoDownloadOptionsAsync(url);
                }
                else
                {
                    videoOptions = YoutubeVideoService.GetOptionPlaylist().Reverse().ToArray();
                    title        = await _youtubeservise.GetPlaylistTitle(url);
                }
                IsLoading = false;
                DialogHost.Close("MainDialog", new YoutubeVideoModel(videos, videoOptions, title));
            }
            catch (ArgumentException e)
            {
                MessageBox.Show(e.Message);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            IsLoading = false;
        }