Skip to content

Conversation

@HossamSaberX
Copy link

Partially fixes #921 by handling unavailable playlist batches gracefully.

Before: Fetching crashed with PlaylistUnavailableException on any unavailable batch.

After: Catches the exception to stop enumeration without crashing.

Note: In practice, unavailable batches omit all videos, so this prevents crashes but may still stop early.
We may think of further improvements (like jumping over batches) can extend coverage but also may miss smth before if the jumping to indices is too large.

Comment on lines +100 to +101
// Stop enumeration if the playlist becomes unavailable
yield break;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we try the next batch still, until it's empty?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!
I already tried that with jumping techniques instead of brute forcing every index, but it always misses some videos.

I can give it another round of trial.

But for this pr, it just returns with the available ones until an unavailable batch comes in.

@Tyrrrz Tyrrrz changed the title fix(issue#921): get the batch of working videos and stop on the unavailable batch Get the batch of working playlist videos and stop on the unavailable batch Oct 28, 2025
@Tyrrrz Tyrrrz requested a review from Copilot October 28, 2025 19:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the playlist handling logic to gracefully handle scenarios where a playlist becomes unavailable during enumeration. The key change is to allow continuing with video extraction even when a playlist is marked as unavailable, as long as the API response contains videos.

  • Modified GetPlaylistNextResponseAsync to return the response if it contains videos, even when marked unavailable
  • Added exception handling in GetVideoBatchesAsync to stop enumeration gracefully when playlists become unavailable
  • Added System.Linq import to support the new .Any() call on videos

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
YoutubeExplode/Playlists/PlaylistController.cs Added logic to proceed with videos even when playlist is marked unavailable; added System.Linq import
YoutubeExplode/Playlists/PlaylistClient.cs Added try-catch to gracefully stop enumeration on PlaylistUnavailableException; added YoutubeExplode.Bridge import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +130 to +131
// If the response contains videos, proceed with them even if the playlist is marked unavailable
if (playlistResponse.Videos.Any())
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new logic bypasses the retry mechanism when videos are present. If playlistResponse.Videos.Any() returns true, the method returns immediately without decrementing retriesRemaining, which could mask transient errors. Consider checking if videos exist before entering the retry logic, or ensure this check only applies on the final retry attempt.

Suggested change
// If the response contains videos, proceed with them even if the playlist is marked unavailable
if (playlistResponse.Videos.Any())
// If the response contains videos, proceed with them even if the playlist is marked unavailable,
// but only on the final retry attempt.
if (retriesRemaining == 0 && playlistResponse.Videos.Any())

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't fetch a public playlist

2 participants