From f3cab4ac6b2195ad3853cda689e4960e3149eab1 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Fri, 19 Jan 2024 02:16:15 -0500 Subject: [PATCH] Account for Twitch now returning 403 when trying to access sub-only VODs without authorization --- TwitchDownloaderCore/TwitchHelper.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index fc24b40f..e58eabf0 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -84,6 +84,19 @@ public static async Task GetVideoPlaylist(int videoId, string token, str throw; } } + + if (response.StatusCode == HttpStatusCode.Forbidden) + { + // Twitch returns 403 Forbidden for (some? all?) sub-only VODs when correct authorization is not provided + var forbiddenResponse = await response.Content.ReadAsStringAsync(); + if (forbiddenResponse.Contains("vod_manifest_restricted") || forbiddenResponse.Contains("unauthorized_entitlements")) + { + // Return the error string so the caller can choose their error strategy + // TODO: We may want to eventually return all 403 responses so the error messages can be parsed and/or logged since more potential errors exist + return forbiddenResponse; + } + } + response.EnsureSuccessStatusCode(); return await response.Content.ReadAsStringAsync();