109 lines
4.8 KiB
Plaintext
109 lines
4.8 KiB
Plaintext
' TV client-version downgrade experiment (recover VOD per-format URLs withheld under useServerDrivenAbr).
|
|
' Self-contained so it can be ripped out wholesale once the experiment concludes: delete this file and the
|
|
' call sites in InnertubeService.GetVideoMetadata (InitialPlayerClient, PlanTvClientDowngradeRetry,
|
|
' ResponseHasUsableAdaptive, ReportDowngradeOutcome) plus the downgradeRetry* / downgradeOutcomeReported locals,
|
|
' then drop ClientType.TvDowngraded + its branches if the downgrade isn't kept.
|
|
'
|
|
' DEBUG-only (compiled out of prod by #if DEBUG):
|
|
' DEBUG_FORCE_DOWNGRADED_CLIENT - downgrade the FIRST player request too, not just the retry.
|
|
' DEBUG_FORCE_DOWNGRADE_RETRY - force the downgrade-retry path on every non-live VOD.
|
|
#const DEBUG_FORCE_DOWNGRADE_RETRY = false
|
|
#const DEBUG_FORCE_DOWNGRADED_CLIENT = false
|
|
|
|
import "pkg:/components/Services/Innertube/Context.bs"
|
|
import "pkg:/source/utils/ObjectUtils.bs"
|
|
import "pkg:/source/utils/StringUtils.bs"
|
|
|
|
namespace Innertube.Experiment
|
|
|
|
enum DowngradeArm
|
|
Control = "control_7x"
|
|
Treatment = "treatment_5x"
|
|
end enum
|
|
|
|
enum DowngradeOutcome
|
|
Recovered = "recovered"
|
|
NotRecovered = "not_recovered"
|
|
RetryFailed = "retry_failed"
|
|
end enum
|
|
|
|
' Client for the first player request: Tv normally, TvDowngraded only under the debug flag.
|
|
function InitialPlayerClient() as Innertube.ClientType
|
|
#if DEBUG
|
|
#if DEBUG_FORCE_DOWNGRADED_CLIENT
|
|
return Innertube.ClientType.TvDowngraded
|
|
#end if
|
|
#end if
|
|
return Innertube.ClientType.Tv
|
|
end function
|
|
|
|
' Plan a one-shot retry only when the player signals useServerDrivenAbr AND no adaptive format has a usable
|
|
' URL (the stuck-at-360p state - SABR can be signaled while URLs are still present, in which case we keep them).
|
|
' Coin-flip control (same version - intermittency baseline) vs treatment (downgrade - the fix).
|
|
' Returns invalid otherwise (URLs present, not SABR, live, or no streamingData).
|
|
function PlanTvClientDowngradeRetry(playerResponseJson as object) as object
|
|
if not IsAssociativeArray(ObjectUtils.Dig(playerResponseJson, ["streamingData"]))
|
|
return invalid
|
|
end if
|
|
if ValidBool(ObjectUtils.Dig(playerResponseJson, ["videoDetails", "isLive"]))
|
|
return invalid
|
|
end if
|
|
serverDrivenAbr = ValidBool(ObjectUtils.Dig(playerResponseJson, ["playerConfig", "mediaCommonConfig", "useServerDrivenAbr"]))
|
|
shouldRetry = serverDrivenAbr and not ResponseHasUsableAdaptive(playerResponseJson)
|
|
#if DEBUG
|
|
#if DEBUG_FORCE_DOWNGRADE_RETRY
|
|
shouldRetry = true
|
|
#end if
|
|
#end if
|
|
if not shouldRetry
|
|
return invalid
|
|
end if
|
|
arm = DowngradeArm.Control
|
|
retryClient = Innertube.ClientType.Tv
|
|
if Rnd(0) < 0.5
|
|
arm = DowngradeArm.Treatment
|
|
retryClient = Innertube.ClientType.TvDowngraded
|
|
end if
|
|
return {
|
|
arm: arm
|
|
client: retryClient
|
|
}
|
|
end function
|
|
|
|
' True if any adaptive format carries a playable field (url / signatureCipher / cipher).
|
|
function ResponseHasUsableAdaptive(playerResponseJson as object) as boolean
|
|
adaptiveFormats = ObjectUtils.Dig(playerResponseJson, ["streamingData", "adaptiveFormats"])
|
|
if not IsArray(adaptiveFormats)
|
|
return false
|
|
end if
|
|
for each format in adaptiveFormats
|
|
if IsAssociativeArray(format) and (not StringUtils.IsNullOrEmpty(format["url"]) or not StringUtils.IsNullOrEmpty(format["signatureCipher"]) or not StringUtils.IsNullOrEmpty(format["cipher"]))
|
|
return true
|
|
end if
|
|
end for
|
|
return false
|
|
end function
|
|
|
|
' One telemetry event per outcome; fingerprint splits GlitchTip into 6 buckets:
|
|
' {control_7x, treatment_5x} x {recovered, not_recovered, retry_failed}.
|
|
' Attaches the retry request + response so each bucket is diagnosable, not just a count.
|
|
function ReportDowngradeOutcome(arm as Innertube.Experiment.DowngradeArm, outcome as Innertube.Experiment.DowngradeOutcome, videoId as string, playerRequest as object, playerResponse as object) as void
|
|
LogInfo("[DOWNGRADE-RETRY] outcome arm=", arm, " outcome=", outcome, " videoId=", videoId)
|
|
LogTelemetryEvent({
|
|
level: "warning"
|
|
message: "[DOWNGRADE-RETRY] arm=" + arm + " outcome=" + outcome
|
|
fingerprint: ["downgrade-retry", arm, outcome]
|
|
attachments: [{
|
|
filename: "request.txt"
|
|
content_type: "text/plain"
|
|
data: playerRequest.ToCurlCommand()
|
|
}, {
|
|
filename: "response.json"
|
|
content_type: "application/json"
|
|
data: playerResponse.Text()
|
|
}]
|
|
})
|
|
end function
|
|
|
|
end namespace
|