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; } }
public async Task <DeckDetailOutputModel> Handle(DeckByIdQuery request, CancellationToken cancellationToken) { var deckResult = await _deckService.GetDeckById(request.DeckId); if (deckResult != null) { var response = DeckDetailOutputModel.From(deckResult); if (!string.IsNullOrWhiteSpace(response.YoutubeUrl)) { response.VideoId = YoutubeHelpers.ExtractVideoId(response.YoutubeUrl); } // we duplicate card based on quantity property, also maintain order var mainList = deckResult.MainDeck.SelectMany(c => Enumerable.Repeat(c, c.Quantity)).OrderBy(c => c.SortOrder).ToList(); var extraList = deckResult.ExtraDeck.SelectMany(c => Enumerable.Repeat(c, c.Quantity)).OrderBy(c => c.SortOrder).ToList(); var sideList = deckResult.SideDeck.SelectMany(c => Enumerable.Repeat(c, c.Quantity)).OrderBy(c => c.SortOrder).ToList(); // we map to cardoutputmodel response.MainDeck = mainList.Select(card => CardMapperHelper.MapToCardOutputModel(_mapper, card)).ToList(); response.ExtraDeck = extraList.Select(card => CardMapperHelper.MapToCardOutputModel(_mapper, card)).ToList(); response.SideDeck = sideList.Select(card => CardMapperHelper.MapToCardOutputModel(_mapper, card)).ToList(); return(response); } return(null); }
public void ShouldReturnVideoIDFromYoutubeLink() { var testCases = new[] { new { ExpectedID = "THBFWQIgWw4", Link = "https://www.youtube.com/watch?v=THBFWQIgWw4&list=PLRIWtICgwaX1gcSZ8qj8Q473tz7PsNmpR" }, new { ExpectedID = "TQ_qwrrI8Og", Link = "https://www.youtube.com/watch?v=TQ_qwrrI8Og" }, new { ExpectedID = "dPoMql9Ok9M", Link = "www.youtube.com/watch?v=dPoMql9Ok9M" }, new { ExpectedID = "dPoMql9Ok9M", Link = "youtube.com/watch?v=dPoMql9Ok9M" }, new { ExpectedID = "3q1JN_3s3gw", Link = "https://www.youtube.com/watch?v=3q1JN_3s3gw" }, new { ExpectedID = "7wPH_Ed78VY", Link = "watch?v=7wPH_Ed78VY" }, new { ExpectedID = "7wPH_Ed78VY", Link = "https://youtu.be/7wPH_Ed78VY" }, new { ExpectedID = "iopENDI-Ayk", Link = "https://www.youtube.com/watch?v=iopENDI-Ayk" }, new { ExpectedID = "6k_9QPAosTc", Link = "https://www.youtube.com/watch?v=6k_9QPAosTc" }, new { ExpectedID = "6k_9QPAosTc", Link = "https://youtu.be/6k_9QPAosTc" }, new { ExpectedID = "y_Rd2hByRyc", Link = "https://www.youtube.com/watch?feature=player_embedded&v=y_Rd2hByRyc" }, new { ExpectedID = "-MPe7E1YrY4", Link = "https://www.youtube.com/watch?v=-MPe7E1YrY4&feature=player_embedded" }, new { ExpectedID = "6xyQWw_j3fU", Link = "https://www.youtube.com/watch?v=6xyQWw_j3fU&feature=youtu.be" }, new { ExpectedID = "0r7pnMVNvPE", Link = "https://www.youtube.com/watch?v=0r7pnMVNvPE" }, new { ExpectedID = "3qy_kJbWfuI", Link = "https://www.youtube.com/watch?v=3qy_kJbWfuI" }, new { ExpectedID = "n4R2p9WnzAo", Link = "https://www.youtube.com/watch?v=n4R2p9WnzAo" }, new { ExpectedID = "BF_CI__LFSA", Link = "https://www.youtube.com/watch?v=BF_CI__LFSA" }, new { ExpectedID = "LxO1Xqx7GqQ", Link = "https://www.youtube.com/watch?v=LxO1Xqx7GqQ" }, new { ExpectedID = "obKI72j2iqo", Link = "https://www.youtube.com/watch?v=obKI72j2iqo&list=PL157A6EA7421FC089" }, new { ExpectedID = "obKI72j2iqo", Link = "https://youtu.be/obKI72j2iqo?list=PL157A6EA7421FC089" }, }; foreach (var test in testCases) { Assert.AreEqual(test.ExpectedID, YoutubeHelpers.ExtractYoutubeID(test.Link)); } }
private async void HandleDataObject(IDataObject data) { if (string.IsNullOrEmpty(Settings.OutputFolder)) { await Application.Current.Dispatcher.InvokeAsync(() => MessageBox.Show(this, "You need to set an output folder for your converted songs first.", "There was a problem")); } else if (data.GetDataPresent(DataFormats.UnicodeText)) { HandleYoutubeConversion((string)data.GetData(DataFormats.UnicodeText)); } else if (data.GetDataPresent(DataFormats.FileDrop)) { string[] filepaths = (string[])data.GetData(DataFormats.FileDrop); foreach (var filepath in filepaths) { string extension = Path.GetExtension(filepath); if (string.IsNullOrWhiteSpace(extension)) { await Application.Current.Dispatcher.InvokeAsync(() => MessageBox.Show(this, "Folders aren't supported. Instead, select all of the files inside the folder you wish to convert.", "There was a problem")); } else if (string.Compare(extension, ".url", true) == 0) { HandleYoutubeConversion(YoutubeHelpers.ExtractURLFromShortcut(filepath)); } else { HandleFileConversion(filepath); } } } }
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); } }
public void Given_A_YoutubeUrl_Extract_VideoId_(string youtubeVideoUrl, string expectVideoId) { // Arrange // Act var result = YoutubeHelpers.ExtractVideoId(youtubeVideoUrl); // Assert result.Should().BeEquivalentTo(expectVideoId); }
public SearchService([NotNull] IHistoryRepository historyRepository, [NotNull] IYoutubeSearchService youtubeSearchService, [NotNull] AppSettings appSettings, [NotNull] IVideoRepository videoRepository, [NotNull] YoutubeHelpers youtubeHelpers) { _historyRepository = historyRepository; _youtubeSearchService = youtubeSearchService; _appSettings = appSettings; _videoRepository = videoRepository; _youtubeHelpers = youtubeHelpers; }
public void ShouldReturnURLFromShortcut() { var testCases = new[] { new { ExpectedURL = "https://www.youtube.com/watch?v=p6j8fuvQICI", ShortcutFilepath = "TestShortcuts/Link1.url" }, new { ExpectedURL = "https://www.youtube.com/watch?v=f9qavey27Kc", ShortcutFilepath = "TestShortcuts/Link2.url" }, new { ExpectedURL = "https://www.youtube.com/watch?v=WpTOzX4xDUw", ShortcutFilepath = "TestShortcuts/Link3.url" }, new { ExpectedURL = "https://www.youtube.com/watch?v=QGHlVLsbuoc", ShortcutFilepath = "TestShortcuts/Link4.url" }, }; foreach (var test in testCases) { Assert.AreEqual(test.ExpectedURL, YoutubeHelpers.ExtractURLFromShortcut(test.ShortcutFilepath)); } }
public async Task <Result <YoutubeVideo, string> > GetYoutubeVideoInfo(string videoUrl) { videoUrl = YoutubeHelpers.NormalizeVideoUrl(videoUrl); if (string.IsNullOrEmpty(videoUrl)) { return("Invalid Link"); } try { var videos = await Task.Run(() => DownloadUrlResolver.GetDownloadUrls(videoUrl)); var video = new YoutubeVideo() { Title = videos.First().Title, Url = videoUrl, }; video.Formats = videos.Select(v => new YTEVideoFormat(video) { FormatCode = v.FormatCode, AudioBitrate = v.AudioBitrate, Resolution = v.Resolution, ContainerExtension = v.VideoExtension, AudioExtension = v.AudioExtension, Container = (MediaContainer)v.VideoType, AudioCodec = (AudioCodec)v.AudioType, AdaptiveType = (AdaptiveType)v.AdaptiveType, DownloadUrl = v.DownloadUrl, IsEncrypted = v.RequiresDecryption, YTEVideoInfo = v, } as VideoFormat).ToList(); return(video); } catch (WebException e) { return((e.Response as HttpWebResponse).StatusCode.ToString()); } catch (Exception) { return("Private/Removed Video"); } }
public YoutubeHelpersTests() { _youtubeHelpers = new YoutubeHelpers(); }