Skip to content

Commit

Permalink
Warm up system playlists if they report themselves unavailable on the…
Browse files Browse the repository at this point in the history
… first request

Related to #854
  • Loading branch information
Tyrrrz committed Dec 30, 2024
1 parent 30ba3f2 commit 93e6b1b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion YoutubeExplode/Playlists/PlaylistController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,27 @@ await response.Content.ReadAsStringAsync(cancellationToken)
if (!playlistResponse.IsAvailable)
{
// Retry if this is not the first request, meaning that the previous requests were successful,
// and that the playlist is probably not actually unavailable.
// indicating that it's most likely a transient error.
if (index > 0 && !string.IsNullOrWhiteSpace(visitorData) && retriesRemaining > 0)
continue;

// Some system playlists are unavailable through this endpoint until their page is opened by
// at least one user. Retry if this is the first request and we haven't retried yet.
if (index <= 0 && string.IsNullOrWhiteSpace(visitorData) && retriesRemaining >= 5)
{
using (
await http.GetAsync(
$"https://youtube.com/playlist?list={playlistId}",
cancellationToken
)
)
{
// We don't actually care about the outcome of this request
}

continue;
}

throw new PlaylistUnavailableException(
$"Playlist '{playlistId}' is not available."
);
Expand Down

0 comments on commit 93e6b1b

Please sign in to comment.