From 76a780ae436f1989d7a9ed97768cfd07e22c3169 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Mon, 8 Jan 2024 19:47:56 +0200 Subject: [PATCH] Clean up --- YoutubeExplode/Videos/Streams/StreamClient.cs | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/YoutubeExplode/Videos/Streams/StreamClient.cs b/YoutubeExplode/Videos/Streams/StreamClient.cs index 92915950..e27a7e76 100644 --- a/YoutubeExplode/Videos/Streams/StreamClient.cs +++ b/YoutubeExplode/Videos/Streams/StreamClient.cs @@ -205,6 +205,8 @@ private async ValueTask> GetStreamInfosAsync( CancellationToken cancellationToken = default ) { + var streamInfos = new List(); + // Video is pay-to-play if (!string.IsNullOrWhiteSpace(playerResponse.PreviewVideoId)) { @@ -222,15 +224,8 @@ private async ValueTask> GetStreamInfosAsync( ); } - var streamInfos = new List(); - // 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)) @@ -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 @@ -270,9 +262,9 @@ private async ValueTask> 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 @@ -280,10 +272,9 @@ private async ValueTask> GetStreamInfosAsync( 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(