public void Channel_ID_can_be_parsed_from_an_ID_string(string channelId) { // Act var parsed = ChannelId.Parse(channelId); // Assert parsed.Value.Should().Be(channelId); }
public void Channel_ID_can_be_parsed_from_a_URL_string(string channelUrl, string expectedChannelId) { // Act var parsed = ChannelId.Parse(channelUrl); // Assert parsed.Value.Should().Be(expectedChannelId); }
/// <summary> /// Asynchronously searches YouTube for the specified <paramref name="searchQuery"/>. /// </summary> /// <param name="searchQuery">The video, playlist, or channel to search for.</param> /// <returns>An <see cref="IReadOnlyList{T}"/> of <see cref="IVideo"/>'s matching the user's specified <paramref name="searchQuery"/>.</returns> public static async ValueTask <IReadOnlyList <IVideo> > SearchAsync(string searchQuery) { if (PlaylistId.TryParse(searchQuery).HasValue) { return(await Youtube.Client.Playlists.GetVideosAsync(PlaylistId.Parse(searchQuery)).CollectAsync(200)); } else if (ChannelId.TryParse(searchQuery).HasValue) { return(await Youtube.Client.Channels.GetUploadsAsync(ChannelId.Parse(searchQuery)).CollectAsync(200)); } return(await Youtube.Client.Search.GetVideosAsync(searchQuery).CollectAsync(200)); }
private void LoadContentsById(string channelId) { //string channelId = YoutubeClient.ParseChannelId(channelLink); try { ChannelId channelIdStruct = ChannelId.Parse(channelId); Channel channel = _client.Channels.GetAsync(channelIdStruct).Result; //string playlistId = channel.GetChannelVideosPlaylistId(); var videos = _client.Channels.GetUploadsAsync(channel.Id); List <Video> playlistVideos = new List <Video>(); IAsyncEnumerator <PlaylistVideo> enumerator = videos.GetAsyncEnumerator(); while (true) { PlaylistVideo playlistVideo = enumerator.Current; playlistVideos.Add(_client.Videos.GetAsync(playlistVideo.Id).Result); ValueTask <bool> next = enumerator.MoveNextAsync(); if (!next.Result) { break; } } _videos = playlistVideos; } catch (Exception e) { if (_logger != null) { _logger.Log(e.InnerException?.Message); } else { throw; } } }
public void Channel_ID_cannot_be_parsed_from_an_invalid_string(string channelIdOrUrl) { // Act & assert Assert.Throws <ArgumentException>(() => ChannelId.Parse(channelIdOrUrl)); }