diff --git a/CHANGELOG.md b/CHANGELOG.md index 675825d5..12b585a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Shorts being merged with subscription videos, regardless of "Disable Shorts" preference. +- Gracefully handle STS_MISMATCH errors ## [0.40.14] - 2025-08-22 diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs index 6ebbb245..62ef19bf 100644 --- a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs +++ b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs @@ -103,7 +103,15 @@ namespace InnertubeService return rawResponse end if - parsedResponse = Innertube.ParseInnertubePlayerResponse(playerResponse.Json(), playerRequest.signatureTimestamp, cancellation) + parsedResponse = invalid + try + parsedResponse = Innertube.ParseInnertubePlayerResponse(playerResponse.Json(), playerRequest.signatureTimestamp, cancellation) + catch exception + if ValidString(exception.code) = "STS_MISMATCH" + return GetVideoMetadata(videoId, options) + end if + throw exception + end try if parsedResponse.error <> invalid return parsedResponse end if diff --git a/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs b/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs index b62d140d..108ea219 100644 --- a/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs +++ b/playlet-lib/src/components/Services/Innertube/PlayerEndpoint.bs @@ -409,26 +409,37 @@ namespace Innertube response = request.Await() if not response.IsSuccess() + LogError(response.ErrorMessage()) + code = "" if response.StatusCode() = 400 json = response.Json() - if IsAssociativeArray(json) and json["code"] = "STS_MISMATCH" - DeleteFile("tmp:/sts_cache.json") + if IsAssociativeArray(json) + code = ValidString(json["code"]) + if code = "STS_MISMATCH" + DeleteFile("tmp:/sts_cache.json") + end if end if end if - LogError(response.ErrorMessage()) - return adaptiveFormats + + exception = { message: response.ErrorMessage() } + if code <> "" + exception.code = code + end if + throw exception end if json = response.Json() if not IsAssociativeArray(json) or not json.DoesExist("formats") - LogError("Invalid response from decipher service") - return adaptiveFormats + error = "Invalid response from decipher service" + LogError(error) + throw error end if decipheredFormats = json["formats"] if not IsArray(decipheredFormats) or decipheredFormats.Count() <> adaptiveFormats.Count() - LogError("Invalid formats in deciphered response") - return adaptiveFormats + error = "Invalid formats in deciphered response" + LogError(error) + throw error end if for i = 0 to decipheredFormats.Count() - 1