Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Jan 8, 2024
1 parent b8bd927 commit 76a780a
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions YoutubeExplode/Videos/Streams/StreamClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ private async ValueTask<IReadOnlyList<IStreamInfo>> GetStreamInfosAsync(
CancellationToken cancellationToken = default
)
{
var streamInfos = new List<IStreamInfo>();

// Video is pay-to-play
if (!string.IsNullOrWhiteSpace(playerResponse.PreviewVideoId))
{
Expand All @@ -222,15 +224,8 @@ private async ValueTask<IReadOnlyList<IStreamInfo>> GetStreamInfosAsync(
);
}

var streamInfos = new List<IStreamInfo>();

// Extract streams from the player response
await foreach (
var streamInfo in GetStreamInfosAsync(playerResponse.Streams, cancellationToken)
)
{
streamInfos.Add(streamInfo);
}
streamInfos.AddRange(await GetStreamInfosAsync(playerResponse.Streams, cancellationToken));

// Extract streams from the DASH manifest
if (!string.IsNullOrWhiteSpace(playerResponse.DashManifestUrl))
Expand All @@ -242,12 +237,9 @@ var streamInfo in GetStreamInfosAsync(playerResponse.Streams, cancellationToken)
cancellationToken
);

await foreach (
var streamInfo in GetStreamInfosAsync(dashManifest.Streams, cancellationToken)
)
{
streamInfos.Add(streamInfo);
}
streamInfos.AddRange(
await GetStreamInfosAsync(dashManifest.Streams, cancellationToken)
);
}
// Some DASH manifest URLs return 404 for whatever reason
// https://github.com/Tyrrrz/YoutubeExplode/issues/728
Expand All @@ -270,20 +262,19 @@ private async ValueTask<IReadOnlyList<IStreamInfo>> GetStreamInfosAsync(
CancellationToken cancellationToken = default
)
{
// Try to get player response from a cipher-less client
try
{
// Try to get player response from a cipher-less client
var playerResponse = await _controller.GetPlayerResponseAsync(
videoId,
cancellationToken
);

return await GetStreamInfosAsync(videoId, playerResponse, cancellationToken);
}
catch (VideoUnplayableException) { }

// Try to get player response from a client with cipher
catch (VideoUnplayableException)
{
// Try to get player response from a client with cipher
var cipherManifest = await ResolveCipherManifestAsync(cancellationToken);

var playerResponse = await _controller.GetPlayerResponseAsync(
Expand Down

0 comments on commit 76a780a

Please sign in to comment.