Remove OTF DRM probe
This commit is contained in:
1 parent
1b0466ad44
commit
d6c776fbd5
4 files changed
+14
-109
No files matched your search
@@ -1,79 +0,0 @@
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/utils/UrlUtils.bs"
|
||||
|
||||
namespace Innertube
|
||||
|
||||
const DRM_PROBE_TIMEOUT_SECONDS = 15
|
||||
const DRM_PROBE_DIR = "tmp:/drm_probe"
|
||||
|
||||
' Transport matrix against an OTF+DRM format whose segment-info fetch failed.
|
||||
' Every variant returns 2xx on healthy googlevideo URLs, so any non-2xx is
|
||||
' specific to this shape, and any 2xx is an escape to build playback on.
|
||||
function ProbeOTFDrmFormat(format as object, requestHeaders as object, cancellation as object) as string
|
||||
url = ValidString(format.url)
|
||||
if url = ""
|
||||
return "drm probe skipped: format has no url"
|
||||
end if
|
||||
|
||||
rangeUrl = DrmProbeUrlWithParams(url, { range: "0-16383" })
|
||||
sqUrl = DrmProbeUrlWithParams(url, { sq: "0", rn: "0" })
|
||||
|
||||
fs = CreateObject("roFileSystem")
|
||||
fs.Delete(Innertube.DRM_PROBE_DIR)
|
||||
fs.CreateDirectory(Innertube.DRM_PROBE_DIR)
|
||||
|
||||
postBody = CreateObject("roByteArray")
|
||||
postBody.FromHexString("7800")
|
||||
postBody.WriteFile(`${Innertube.DRM_PROBE_DIR}/post_body.bin`)
|
||||
|
||||
' Bare and sq responses are full media on a healthy URL — stream those to files
|
||||
' instead of buffering them into strings.
|
||||
variants = [
|
||||
{ name: "GET bare", request: HttpClient.Get(url).SaveBodyToFile(`${Innertube.DRM_PROBE_DIR}/bare.bin`) }
|
||||
{ name: "GET Range header", request: HttpClient.Get(url).Header("Range", "bytes=0-16383") }
|
||||
{ name: "GET range param", request: HttpClient.Get(rangeUrl) }
|
||||
{ name: "GET sq=0", request: HttpClient.Get(sqUrl).SaveBodyToFile(`${Innertube.DRM_PROBE_DIR}/sq.bin`) }
|
||||
{ name: "POST empty range param", request: HttpClient.Post(rangeUrl) }
|
||||
{ name: "POST {15:0} range param", request: HttpClient.Post(rangeUrl).FileBody(`${Innertube.DRM_PROBE_DIR}/post_body.bin`) }
|
||||
]
|
||||
|
||||
for each variant in variants
|
||||
variant.request.Headers(requestHeaders)
|
||||
variant.request.AttemptTimeoutMs(Innertube.DRM_PROBE_TIMEOUT_SECONDS * 1000)
|
||||
variant.request.Cancellation(cancellation)
|
||||
variant.request.NoCache()
|
||||
variant.pending = variant.request.Send()
|
||||
end for
|
||||
|
||||
lines = [`drm probe itag=${format.itag} drmFamilies=${ValidArray(format.drmFamilies).Join(",")}`]
|
||||
for each variant in variants
|
||||
lines.Push(DrmProbeCollect(variant))
|
||||
end for
|
||||
|
||||
fs.Delete(Innertube.DRM_PROBE_DIR)
|
||||
|
||||
return lines.Join(`\n`)
|
||||
end function
|
||||
|
||||
function DrmProbeUrlWithParams(url as string, params as object) as string
|
||||
queryComponents = UrlUtils.ParseQueryComponents(url)
|
||||
queryComponents.Append(params)
|
||||
return UrlUtils.SetQueryParams(url, queryComponents)
|
||||
end function
|
||||
|
||||
function DrmProbeCollect(variant as object) as string
|
||||
name = variant.name
|
||||
response = variant.pending.Await()
|
||||
|
||||
if response.IsCancelled()
|
||||
return `${name} -> cancelled`
|
||||
end if
|
||||
|
||||
if response.IsTimedOut()
|
||||
return `${name} -> timed out after ${Innertube.DRM_PROBE_TIMEOUT_SECONDS}s`
|
||||
end if
|
||||
|
||||
return `${name} -> ${response.StatusCode()} headers=${ToString(response.Headers())}`
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -1,5 +1,6 @@
|
||||
import "pkg:/components/Services/Innertube/Context.bs"
|
||||
import "pkg:/components/Services/Innertube/OTFDrmProbe.bs"
|
||||
import "pkg:/source/services/HttpClient.bs"
|
||||
import "pkg:/source/utils/UrlUtils.bs"
|
||||
|
||||
namespace Innertube
|
||||
|
||||
@@ -18,11 +19,10 @@ namespace Innertube
|
||||
|
||||
const OTF_MAX_REQUEST_COUNT = 8
|
||||
|
||||
function OTFGetSegmentInfo(adaptiveFormats as object, client as Innertube.ClientType, cancellation as object, playerResponseText as string) as void
|
||||
function OTFGetSegmentInfo(adaptiveFormats as object, client as Innertube.ClientType, cancellation as object) as void
|
||||
errors = {
|
||||
message: ""
|
||||
attachments: []
|
||||
drmProbed: false
|
||||
}
|
||||
|
||||
formatsToProcess = []
|
||||
@@ -62,7 +62,7 @@ namespace Innertube
|
||||
|
||||
pendingFormat = pendingFormats.Shift()
|
||||
' returns false if processing should stop (e.g., cancelled)
|
||||
if not OTFProcessPendingFormat(pendingFormat.format, pendingFormat.pending, pendingFormat.filePath, segmentDurationsRegex, errors, requestHeaders, cancellation)
|
||||
if not OTFProcessPendingFormat(pendingFormat.format, pendingFormat.pending, pendingFormat.filePath, segmentDurationsRegex, errors)
|
||||
exit while
|
||||
end if
|
||||
end while
|
||||
@@ -72,14 +72,6 @@ namespace Innertube
|
||||
|
||||
fs.Delete("tmp:/otf_segments")
|
||||
|
||||
if errors.drmProbed
|
||||
errors.attachments.Push({
|
||||
filename: "player_response.json"
|
||||
content_type: "application/json"
|
||||
data: playerResponseText
|
||||
})
|
||||
end if
|
||||
|
||||
if not StringUtils.IsNullOrEmpty(errors.message) or errors.attachments.Count() > 0
|
||||
LogTelemetryEvent({
|
||||
level: "error"
|
||||
@@ -110,7 +102,7 @@ namespace Innertube
|
||||
return request.Send()
|
||||
end function
|
||||
|
||||
function OTFProcessPendingFormat(format as object, pending as HttpClient.PendingResponse, filePath as string, segmentDurationsRegex as object, errors as object, requestHeaders as object, cancellation as object) as boolean
|
||||
function OTFProcessPendingFormat(format as object, pending as HttpClient.PendingResponse, filePath as string, segmentDurationsRegex as object, errors as object) as boolean
|
||||
response = pending.Await()
|
||||
|
||||
if response.IsCancelled()
|
||||
@@ -119,10 +111,6 @@ namespace Innertube
|
||||
|
||||
if not response.IsSuccess()
|
||||
errors.message += `Failed to get segment info for itag ${format.itag}: ${response.ErrorMessage()}\n`
|
||||
if IsArray(format.drmFamilies) and not errors.drmProbed
|
||||
errors.drmProbed = true
|
||||
errors.message += Innertube.ProbeOTFDrmFormat(format, requestHeaders, cancellation) + `\n`
|
||||
end if
|
||||
return true
|
||||
end if
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace Innertube
|
||||
|
||||
if isOTF
|
||||
LogDebug("Fetching OTF segment info")
|
||||
OTFGetSegmentInfo(adaptiveFormats, client, cancellation, playerResponse.Text())
|
||||
OTFGetSegmentInfo(adaptiveFormats, client, cancellation)
|
||||
end if
|
||||
|
||||
if isLive
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Tests
|
||||
function _()
|
||||
m.server.routes = { "/otf/init": { status: 200, body: `init bytes\r\nSegment-Count: 3\r\nSegment-Durations-Ms: 5333,5334(r=1),\r\n` } }
|
||||
formats = m.Formats("/otf/init", 10)
|
||||
Innertube.OTFGetSegmentInfo(formats, Innertube.ClientType.Tv, invalid, "{}")
|
||||
Innertube.OTFGetSegmentInfo(formats, Innertube.ClientType.Tv, invalid)
|
||||
for each format in formats
|
||||
m.assertEqual(format.otfSegmentDurations, [{ d: 5333 }, { d: 5334, r: 1 }])
|
||||
end for
|
||||
@@ -58,20 +58,16 @@ namespace Tests
|
||||
m.assertEmpty(m.global.telemetry.LogEvent)
|
||||
end function
|
||||
|
||||
@it("probes a DRM format whose init segment failed, and reports both")
|
||||
@it("reports a format whose init segment failed, after one request")
|
||||
function _()
|
||||
m.server.routes = { "/otf/drm": { status: 404 } }
|
||||
formats = m.Formats("/otf/drm", 1)
|
||||
formats[0].drmFamilies = ["WIDEVINE"]
|
||||
Innertube.OTFGetSegmentInfo(formats, Innertube.ClientType.Tv, invalid, `{"player":1}`)
|
||||
m.server.routes = { "/otf/missing": { status: 404 } }
|
||||
formats = m.Formats("/otf/missing", 1)
|
||||
Innertube.OTFGetSegmentInfo(formats, Innertube.ClientType.Tv, invalid)
|
||||
event = m.global.telemetry.LogEvent
|
||||
m.assertEqual(event.level, "error")
|
||||
m.AssertContains(event.message, "Failed to get segment info for itag 1")
|
||||
m.AssertContains(event.message, "drm probe itag=1 drmFamilies=WIDEVINE")
|
||||
for each variant in ["GET bare", "GET Range header", "GET range param", "GET sq=0", "POST empty range param", "POST {15:0} range param"]
|
||||
m.AssertContains(event.message, `${variant} -> 404`)
|
||||
end for
|
||||
m.assertEqual(event.attachments[0].data, `{"player":1}`)
|
||||
m.assertEqual(m.HitsUnder("/otf/missing?"), 1)
|
||||
m.assertEmpty(event.attachments)
|
||||
m.assertInvalid(formats[0].otfSegmentDurations)
|
||||
end function
|
||||
|
||||
@@ -87,7 +83,7 @@ namespace Tests
|
||||
formats = m.Formats("/delay/3000", 10)
|
||||
canceller.cancelAfterMs = 300
|
||||
timer.Mark()
|
||||
Innertube.OTFGetSegmentInfo(formats, Innertube.ClientType.Tv, cancellation, "{}")
|
||||
Innertube.OTFGetSegmentInfo(formats, Innertube.ClientType.Tv, cancellation)
|
||||
elapsedMs = timer.TotalMilliseconds()
|
||||
m.assertTrue(elapsedMs >= 250 and elapsedMs < 800, `took ${elapsedMs} ms`)
|
||||
for each format in formats
|
||||
|
||||
Reference in new issue
Block a user