diff --git a/YoutubeExplode/Playlists/PlaylistClient.cs b/YoutubeExplode/Playlists/PlaylistClient.cs index 38c60085..9763165f 100644 --- a/YoutubeExplode/Playlists/PlaylistClient.cs +++ b/YoutubeExplode/Playlists/PlaylistClient.cs @@ -4,6 +4,7 @@ using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; +using YoutubeExplode.Bridge; using YoutubeExplode.Common; using YoutubeExplode.Exceptions; using YoutubeExplode.Videos; @@ -83,13 +84,22 @@ public async IAsyncEnumerable> GetVideoBatchesAsync( do { - var response = await _controller.GetPlaylistNextResponseAsync( - playlistId, - lastVideoId, - lastVideoIndex, - visitorData, - cancellationToken - ); + PlaylistNextResponse response; + try + { + response = await _controller.GetPlaylistNextResponseAsync( + playlistId, + lastVideoId, + lastVideoIndex, + visitorData, + cancellationToken + ); + } + catch (PlaylistUnavailableException) + { + // Stop enumeration if the playlist becomes unavailable + yield break; + } var videos = new List(); diff --git a/YoutubeExplode/Playlists/PlaylistController.cs b/YoutubeExplode/Playlists/PlaylistController.cs index d3208587..efb34a26 100644 --- a/YoutubeExplode/Playlists/PlaylistController.cs +++ b/YoutubeExplode/Playlists/PlaylistController.cs @@ -1,4 +1,5 @@ -using System.Net.Http; +using System.Linq; +using System.Net.Http; using System.Threading; using System.Threading.Tasks; using YoutubeExplode.Bridge; @@ -126,6 +127,10 @@ await http.GetAsync( continue; } + // If the response contains videos, proceed with them even if the playlist is marked unavailable + if (playlistResponse.Videos.Any()) + return playlistResponse; + throw new PlaylistUnavailableException( $"Playlist '{playlistId}' is not available." );