diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index 5b69db50..3b53f25b 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -57,17 +57,51 @@ public static async Task GetVideoToken(int videoId, strin public static async Task GetVideoPlaylist(int videoId, string token, string sig) { - var request = new HttpRequestMessage() + HttpRequestMessage request; + HttpResponseMessage response; + try { - RequestUri = new Uri($"https://usher.ttvnw.net/vod/{videoId}.m3u8?sig={sig}&token={token}&allow_source=true&allow_audio_only=true&platform=web&player_backend=mediaplayer&playlist_include_framerate=true&supported_codecs=av1,h264"), - Method = HttpMethod.Get - }; - var response = await httpClient.SendAsync(request); + request = new HttpRequestMessage() + { + RequestUri = new Uri($"https://usher.ttvnw.net/vod/{videoId}.m3u8?sig={sig}&token={token}&allow_source=true&allow_audio_only=true&platform=web&player_backend=mediaplayer&playlist_include_framerate=true&supported_codecs=av1,h264"), + Method = HttpMethod.Get + }; + response = await httpClient.SendAsync(request); + } + catch (Exception ex) + { + if (IsAuthException(ex)) + { + request = new HttpRequestMessage() + { + RequestUri = new Uri($"https://twitch-downloader-proxy.twitcharchives.workers.dev/{videoId}.m3u8?sig={sig}&token={token}&allow_source=true&allow_audio_only=true&platform=web&player_backend=mediaplayer&playlist_include_framerate=true&supported_codecs=av1,h264"), + Method = HttpMethod.Get + }; + response = await httpClient.SendAsync(request); + } + else + { + throw; + } + } response.EnsureSuccessStatusCode(); return await response.Content.ReadAsStringAsync(); } + static bool IsAuthException(Exception ex) + { + while (ex != null) + { + if (ex is System.Security.Authentication.AuthenticationException) + { + return true; + } + ex = ex.InnerException; + } + return false; + } + public static async Task GetClipInfo(object clipId) { var request = new HttpRequestMessage()