Skip to content

Commit

Permalink
Add support for looking up channels by their slugs
Browse files Browse the repository at this point in the history
Related to #273
  • Loading branch information
Tyrrrz committed Jun 29, 2022
1 parent ceb2d4f commit 393e8bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion YoutubeDownloader.Core/Resolving/QueryResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,22 @@ public async Task<QueryResult> ResolveAsync(
return new QueryResult(QueryResultKind.Channel, $"Channel: {channel.Title}", videos);
}

// User
// Channel (by username)
if (isUrl && UserName.TryParse(query) is { } userName)
{
var channel = await _youtube.Channels.GetByUserAsync(userName, cancellationToken);
var videos = await _youtube.Channels.GetUploadsAsync(channel.Id, cancellationToken);
return new QueryResult(QueryResultKind.Channel, $"Channel: {channel.Title}", videos);
}

// Channel (by slug)
if (isUrl && ChannelSlug.TryParse(query) is { } channelSlug)
{
var channel = await _youtube.Channels.GetBySlugAsync(channelSlug, cancellationToken);
var videos = await _youtube.Channels.GetUploadsAsync(channel.Id, cancellationToken);
return new QueryResult(QueryResultKind.Channel, $"Channel: {channel.Title}", videos);
}

// Search
{
var videos = await _youtube.Search.GetVideosAsync(query, cancellationToken).CollectAsync(20);
Expand Down
4 changes: 2 additions & 2 deletions YoutubeDownloader.Core/YoutubeDownloader.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<PackageReference Include="JsonExtensions" Version="1.2.0" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="TagLibSharp" Version="2.2.0" />
<PackageReference Include="YoutubeExplode" Version="6.1.2" />
<PackageReference Include="YoutubeExplode.Converter" Version="6.1.2" />
<PackageReference Include="YoutubeExplode" Version="6.2.0" />
<PackageReference Include="YoutubeExplode.Converter" Version="6.2.0" />
</ItemGroup>

</Project>

0 comments on commit 393e8bb

Please sign in to comment.