Skip to content

Commit

Permalink
More refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Jun 10, 2024
1 parent 0478332 commit ba1bf90
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions YoutubeDownloader.Core/Resolving/QueryResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ public class QueryResolver(IReadOnlyList<Cookie>? initialCookies = null)

private async Task<QueryResult?> TryResolvePlaylistAsync(
string query,
CancellationToken cancellationToken
CancellationToken cancellationToken = default
)
{
if (PlaylistId.TryParse(query) is not { } playlistId)
return null;

// Skip personal system playlists if the user is not authenticated
if (!_isAuthenticated && playlistId == "WL" || playlistId == "LL" || playlistId == "LM")
var isPersonalSystemPlaylist =
playlistId == "WL" || playlistId == "LL" || playlistId == "LM";

if (isPersonalSystemPlaylist && !_isAuthenticated)
return null;

var playlist = await _youtube.Playlists.GetAsync(playlistId, cancellationToken);
Expand All @@ -39,7 +42,7 @@ CancellationToken cancellationToken

private async Task<QueryResult?> TryResolveVideoAsync(
string query,
CancellationToken cancellationToken
CancellationToken cancellationToken = default
)
{
if (VideoId.TryParse(query) is not { } videoId)
Expand All @@ -51,7 +54,7 @@ CancellationToken cancellationToken

private async Task<QueryResult?> TryResolveChannelAsync(
string query,
CancellationToken cancellationToken
CancellationToken cancellationToken = default
)
{
if (ChannelId.TryParse(query) is { } channelId)
Expand Down Expand Up @@ -95,7 +98,7 @@ CancellationToken cancellationToken

private async Task<QueryResult> ResolveSearchAsync(
string query,
CancellationToken cancellationToken
CancellationToken cancellationToken = default
)
{
var videos = await _youtube
Expand All @@ -109,12 +112,10 @@ public async Task<QueryResult> ResolveAsync(
string query,
CancellationToken cancellationToken = default
) =>
(
await TryResolvePlaylistAsync(query, cancellationToken)
?? await TryResolveVideoAsync(query, cancellationToken)
?? await TryResolveChannelAsync(query, cancellationToken)
?? await ResolveSearchAsync(query, cancellationToken)
);
await TryResolvePlaylistAsync(query, cancellationToken)
?? await TryResolveVideoAsync(query, cancellationToken)
?? await TryResolveChannelAsync(query, cancellationToken)
?? await ResolveSearchAsync(query, cancellationToken);

public async Task<QueryResult> ResolveAsync(
IReadOnlyList<string> queries,
Expand Down

0 comments on commit ba1bf90

Please sign in to comment.