Compare commits

..
5 Commits
Author SHA1 Message Date
Weblate (bot)andmonochrome0301 5b204f2095 Translated using Weblate (Spanish) (#968)
Currently translated at 99.7% (349 of 350 strings)

Translation: Playlet/Playlet
Translate-URL: https://hosted.weblate.org/projects/playlet/playlet/es/

Co-authored-by: monochrome0301 <monochrome0301@users.noreply.hosted.weblate.org>
2026-11-04 08:27:59 -05:00
Brahim Hadriche 7dd7c0a93b telemetry adjust 2026-10-19 12:20:40 -04:00
Brahim Hadriche 0c31ee1354 Simplify lounge 2026-10-19 11:37:27 -04:00
Brahim Hadriche 6822f12336 Fix drm errors 2026-10-18 11:25:01 -04:00
Brahim Hadriche d6c776fbd5 Remove OTF DRM probe 2026-10-18 10:12:24 -04:00
18 changed files with 240 additions and 377 deletions

No files matched your search

+6
View File
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- DRM playback errors on certain TVs, by filtering out FairPlay-only streams
## [0.48.10] - 2026-10-17
### Added
@@ -267,6 +267,10 @@ class DashManifest
continue for
end if
if m.HasOnlyUnsupportedDrm(format)
continue for
end if
if (format.width = invalid or format.height = invalid) and not StringUtils.IsNullOrEmpty(format.size)
if format.size.instr("x") > 0
parts = format.size.Tokenize("x")
@@ -323,7 +327,12 @@ class DashManifest
audioTrackId = format.audioTrack.id
end if
groupId = `${mimeType}-${justCodec}-${colorInfo}-${audioTrackId}${m.GetAudioVariantSuffix(format)}`
drmFamilies = ""
if IsArray(format.drmFamilies)
drmFamilies = format.drmFamilies.Join("+")
end if
groupId = `${mimeType}-${justCodec}-${colorInfo}-${audioTrackId}${m.GetAudioVariantSuffix(format)}-${drmFamilies}`
if groupInfo[groupId] = invalid
groupInfo[groupId] = []
@@ -473,14 +482,7 @@ class DashManifest
end if
if xml.Node("AdaptationSet", adaptationSetAttributes)
if IsArray(firstFormat.drmFamilies)
for each drmFamily in firstFormat.drmFamilies
systemId = m.GetDrmSystemId(drmFamily)
if IsString(systemId)
xml.EmptyNode("ContentProtection", { "schemeIdUri": `urn:uuid:${systemId}` })
end if
end for
end if
m.AddContentProtection(xml, firstFormat)
if IsAssociativeArray(firstFormat.audioTrack) or firstFormat.isDrc = true or firstFormat.isVoiceBoost = true
' Roles
@@ -574,14 +576,7 @@ class DashManifest
end if
if xml.Node("AdaptationSet", adaptationSetAttributes)
if IsArray(firstFormat.drmFamilies)
for each drmFamily in firstFormat.drmFamilies
systemId = m.GetDrmSystemId(drmFamily)
if IsString(systemId)
xml.EmptyNode("ContentProtection", { "schemeIdUri": `urn:uuid:${systemId}` })
end if
end for
end if
m.AddContentProtection(xml, firstFormat)
m.AddColorInfo(firstFormat, xml)
@@ -1015,6 +1010,32 @@ class DashManifest
}
end function
' DRM movies have formats whose only DRM family is FAIRPLAY, which no ContentProtection Roku supports can declare.
function HasOnlyUnsupportedDrm(format as object) as boolean
if not IsArray(format.drmFamilies) or format.drmFamilies.Count() = 0
return false
end if
for each drmFamily in format.drmFamilies
if IsString(m.GetDrmSystemId(drmFamily))
return false
end if
end for
return true
end function
' A set's formats share their drmFamilies: CreateFormatGroupings keys groups on them.
function AddContentProtection(xml as object, format as object) as void
if not IsArray(format.drmFamilies)
return
end if
for each drmFamily in format.drmFamilies
systemId = m.GetDrmSystemId(drmFamily)
if IsString(systemId)
xml.EmptyNode("ContentProtection", { "schemeIdUri": `urn:uuid:${systemId}` })
end if
end for
end function
function GetDrmSystemId(drmFamily as dynamic) as dynamic
if not IsString(drmFamily)
return invalid
@@ -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
@@ -1,6 +1,6 @@
import "pkg:/components/Services/LoungeService/LoungeFraming.bs"
import "pkg:/components/Services/LoungeService/LoungeService.types.bs"
import "pkg:/source/services/HttpClient.bs"
import "pkg:/source/utils/ByteArrayUtils.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"
@@ -71,10 +71,6 @@ class LoungeBackchannel
m.closeReason = LoungeCloseReason.NotSent
return []
end if
if m.statusCode < 0
m.closeReason = LoungeCloseReason.Curl
return []
end if
if m.statusCode < 200 or m.statusCode >= 300
m.closeReason = LoungeCloseReason.Http
return []
@@ -97,25 +93,42 @@ class LoungeBackchannel
return commands
end function
function CloseLabel() as string
if m.closeReason = LoungeCloseReason.Curl or m.closeReason = LoungeCloseReason.Http
return `${m.closeReason}_${Abs(m.statusCode)}`
end if
return m.closeReason
end function
' Frame = `<byteLength>\n<json>`, the length counted in BYTES. The answer is complete, so a malformed or cut-off
' frame ends the extraction: no later read can complete it.
private function ExtractFrames(text as string) as object
body = CreateObject("roByteArray")
body.FromAsciiString(text)
result = LoungeFraming.Extract(body, 0)
if result.nextPos < body.Count()
LogTelemetryEvent({
level: "warning"
message: `Lounge answer ended mid-frame, ${body.Count() - result.nextPos} bytes left: ${text}`
fingerprint: "lounge-partial-frame"
})
end if
return result.frames
frames = []
count = body.Count()
cursor = 0
while cursor < count
if body[cursor] = 10 or body[cursor] = 13
cursor += 1
continue while
end if
frameStart = cursor
frameLength = 0
' Stops once the length exceeds the body: a frame that long can't be whole, and the integer can't overflow.
while cursor < count and body[cursor] >= 48 and body[cursor] <= 57 and frameLength <= count
frameLength = frameLength * 10 + body[cursor] - 48
cursor += 1
end while
if cursor < count and body[cursor] = 13
cursor += 1
end if
if cursor >= count or body[cursor] <> 10 or frameLength = 0 or count - cursor - 1 < frameLength
LogTelemetryEvent({
level: "warning"
message: `Lounge answer has a malformed or cut-off frame at byte ${frameStart} of ${count}: ${text}`
fingerprint: "lounge-partial-frame"
})
exit while
end if
dataStart = cursor + 1
frames.Push(ByteArrayUtils.Slice(body, dataStart, dataStart + frameLength).ToAsciiString())
cursor = dataStart + frameLength
end while
return frames
end function
private function Receive(frames as object) as LoungeCommand[]
@@ -1,19 +0,0 @@
import "pkg:/source/utils/ByteArrayUtils.bs"
namespace LoungeBytes
function RangeToString(bytes as object, fromIndex as integer, toIndex as integer) as string
return ByteArrayUtils.Slice(bytes, fromIndex, toIndex).ToAsciiString()
end function
function IndexOfByte(bytes as object, fromIndex as integer, value as integer) as integer
last = bytes.Count() - 1
for i = fromIndex to last
if bytes[i] = value
return i
end if
end for
return -1
end function
end namespace
@@ -1,43 +0,0 @@
import "pkg:/components/Services/LoungeService/LoungeBytes.bs"
namespace LoungeFraming
' Frame = `<byteLength>\n<json>`, the length counted in BYTES. An incomplete trailing frame
' is left unconsumed (nextPos marks its start).
function Extract(body as object, startPos as integer) as object
frames = []
cursor = startPos
count = body.Count()
while true
while cursor < count and (body[cursor] = 13 or body[cursor] = 10)
cursor += 1
end while
if cursor >= count
exit while
end if
lf = LoungeBytes.IndexOfByte(body, cursor, 10)
if lf = -1
exit while
end if
frameLength = Int(Val(LoungeBytes.RangeToString(body, cursor, lf).Trim(), 10))
if frameLength <= 0
cursor = lf + 1
continue while
end if
dataStart = lf + 1
if count - dataStart < frameLength
exit while
end if
frames.Push(LoungeBytes.RangeToString(body, dataStart, dataStart + frameLength))
cursor = dataStart + frameLength
end while
return { frames: frames, nextPos: cursor }
end function
end namespace
@@ -151,21 +151,20 @@ function RunSession(api as LoungeApi, messagePort as object) as boolean
continue while
end if
closeLabel = backchannel.CloseLabel()
LogDebug("Backchannel closed:", closeLabel, "next:", nextStep)
LogDebug("Backchannel closed:", backchannel.closeReason, backchannel.statusCode, "next:", nextStep)
if nextStep = LoungeSessionStep.Drop
LogTelemetryEvent({
level: "error"
message: `Lounge session dropped: no poll delivered for ${sinceDelivered.TotalSeconds()} s, last close: ${closeLabel}`
fingerprint: ["lounge-session-dropped", closeLabel]
message: `Lounge session dropped: no poll delivered for ${sinceDelivered.TotalSeconds()} s, last close: ${backchannel.closeReason} ${backchannel.statusCode}`
fingerprint: ["lounge-session-dropped", backchannel.closeReason, backchannel.statusCode]
})
return false
end if
if nextStep = LoungeSessionStep.Retry and backchannel.closeReason <> LoungeCloseReason.Timeout
LogTelemetryEvent({
level: "warning"
message: "Lounge backchannel failure: " + closeLabel
fingerprint: "lounge-backchannel-" + closeLabel
message: `Lounge backchannel failure: ${backchannel.closeReason} ${backchannel.statusCode}`
fingerprint: ["lounge-backchannel", backchannel.closeReason, backchannel.statusCode]
})
end if
@@ -4,7 +4,6 @@ enum LoungeCloseReason
Stalled = "stalled"
Timeout = "timeout"
NotSent = "not_sent"
Curl = "curl"
Http = "http"
end enum
@@ -233,9 +233,8 @@ namespace PlaybackTelemetry
function ReportVideoError(errorData as object, errorInfo as object, url as dynamic, urlIndex as dynamic, shownInDialog as boolean) as void
m.errorCount += 1
' malformed data: the last generated DASH/HLS manifest and player response diagnose it from the report.
attachments = invalid
if errorData.body.Instr("malformed data") <> -1 or errorData.body.Instr("invalid pathname") <> -1
if errorData.body.Instr("malformed data") <> -1 or errorData.body.Instr("invalid pathname") <> -1 or ((errorInfo = invalid or errorInfo.category <> "http") and errorData.body.Instr("last_err:") = -1)
attachments = [{
filename: "last_generated_dash.xml"
content_type: "plain/text"
+12 -4
View File
@@ -1230,11 +1230,11 @@
</message>
<message>
<source>Do not show again</source>
<translation>No volver a mostrar de nuevo</translation>
<translation>No volver a mostrar</translation>
</message>
<message>
<source>Recommended</source>
<translation>Recomendados</translation>
<translation>Recomendado</translation>
</message>
<message>
<source>Courses</source>
@@ -1258,11 +1258,11 @@
</message>
<message>
<source>Select a service to login</source>
<translation>Seleccione un servicio para iniciar sesion</translation>
<translation>Seleccione un servicio para iniciar sesión</translation>
</message>
<message>
<source>Login to YouTube</source>
<translation>Iniciar sesion en YouTube</translation>
<translation>Iniciar sesión en YouTube</translation>
</message>
<message>
<source>Open the link %1 and enter the following code:</source>
@@ -1396,5 +1396,13 @@
<source>Help improve Playlet by enabling diagnostics. This will send anonymous diagnotics data to the developer.</source>
<translation>Ayuda a mejorar Playlet activando las herramientas de diagnóstico. Esto enviará datos de diagnóstico anónimos al desarrollador.</translation>
</message>
<message>
<source>Backend changed</source>
<translation>Backend cambiado</translation>
</message>
<message>
<source>Backend changed to Playlet, because no Invidious instance is set.</source>
<translation type="unfinished">Backend cambiado a Playlet, porque no hay ninguna instancia de Invidious colocada.</translation>
</message>
</context>
</TS>
@@ -75,7 +75,7 @@ namespace Tests
m.assertEqual(backchannel.closeReason, LoungeCloseReason.Empty)
end function
@it("returns the commands of the whole frames of an answer that ends mid-frame, and reports what is left")
@it("returns the commands of the whole frames of an answer that ends mid-frame, and reports where")
function _()
backchannel = new LoungeBackchannel()
commands = m.PollOnce(backchannel, "/lounge/partial", { status: 200, body: m.Frame(`[[7,["noop"]]]`) + `40\n[[8,` })
@@ -84,7 +84,49 @@ namespace Tests
m.assertEqual(backchannel.closeReason, LoungeCloseReason.Complete)
event = m.global.telemetry.LogEvent
m.assertEqual(event.fingerprint, "lounge-partial-frame")
m.assertTrue(event.message.InStr("7 bytes left") <> -1, event.message)
m.assertTrue(event.message.InStr("at byte 17 of 24") <> -1, event.message)
end function
@it("counts a frame's length in bytes, so a multi-byte character does not shift the next frame")
function _()
backchannel = new LoungeBackchannel()
titleBytes = CreateObject("roByteArray")
titleBytes.FromHexString("636166C3A9")
title = titleBytes.ToAsciiString()
commands = backchannel.StartSession(m.Frame(`[[0,["setTitle","${title}"]]]`) + m.Frame(`[[1,["noop"]]]`))
m.assertEqual(commands.Count(), 2)
m.assertEqual(commands[0].args, title)
m.assertEqual(commands[1].type, "noop")
m.assertEmpty(m.global.telemetry.LogEvent)
end function
@it("reads a length line that ends in CR LF")
function _()
backchannel = new LoungeBackchannel()
commands = backchannel.StartSession(`\r\n14\r\n[[0,["noop"]]]`)
m.assertEqual(commands.Count(), 1)
m.assertEqual(commands[0].type, "noop")
m.assertEmpty(m.global.telemetry.LogEvent)
end function
@it("stops at a frame without a valid length, keeps the frames before it, and reports it")
function _()
for each badFrame in [`0\n`, `x\n[[1,["noop"]]]`, `14 [[1,["noop"]]]`, `99999999999999999999\n[[1,["noop"]]]`]
m.global.telemetry.LogEvent = {}
backchannel = new LoungeBackchannel()
commands = backchannel.StartSession(m.Frame(`[[0,["noop"]]]`) + badFrame + m.Frame(`[[2,["noop"]]]`))
m.assertEqual(commands.Count(), 1, badFrame)
m.assertEqual(commands[0].index, 0, badFrame)
m.assertEqual(m.global.telemetry.LogEvent.fingerprint, "lounge-partial-frame", badFrame)
end for
end function
@it("ends a 2xx answer that is not framed as empty, and reports it")
function _()
backchannel = new LoungeBackchannel()
m.assertEmpty(m.PollOnce(backchannel, "/lounge/unframed", { status: 200, body: "<html></html>" }))
m.assertEqual(backchannel.closeReason, LoungeCloseReason.Empty)
m.assertEqual(m.global.telemetry.LogEvent.fingerprint, "lounge-partial-frame")
end function
@it("skips the commands it already received")
@@ -145,16 +187,14 @@ namespace Tests
backchannel = new LoungeBackchannel()
m.assertEmpty(m.PollOnce(backchannel, "/lounge/unknownsid", { status: 400, body: "Unknown SID" }))
m.assertEqual(backchannel.closeReason, LoungeCloseReason.Http)
m.assertEqual(backchannel.CloseLabel(), "http_400")
m.assertEqual(backchannel.statusCode, 400)
end function
@it("ends a poll the server drops with its curl code")
@it("ends a poll the server drops with the status the OS returns")
function _()
backchannel = new LoungeBackchannel()
m.assertEmpty(m.PollOnce(backchannel, "/lounge/dropped", { drop: true }))
m.assertEqual(backchannel.closeReason, LoungeCloseReason.Curl)
m.assertEqual(backchannel.CloseLabel(), "curl_52")
m.assertEqual(backchannel.closeReason, LoungeCloseReason.Http)
m.assertEqual(backchannel.statusCode, HttpClient.CurlErrors.CURLE_GOT_NOTHING)
end function
@@ -1,41 +0,0 @@
import "pkg:/components/Services/LoungeService/LoungeBytes.bs"
namespace Tests
@suite
class LoungeBytesTests extends Rooibos.BaseTestSuite
@describe("LoungeBytes byte helpers")
@it("converts a byte range to a string, byte-exact across a UTF-8 boundary")
function rangeToString()
' "Xcafé" where é is 2 bytes; extract "café" = bytes [1, end).
cafe = "caf" + m.Utf8(&hC3, &hA9)
bytes = m.Bytes("X" + cafe)
m.assertEqual(LoungeBytes.RangeToString(bytes, 1, bytes.Count()), cafe)
end function
@it("finds the first byte value at or after a position, or -1")
function indexOfByte()
bytes = m.Bytes("a,b,c")
m.assertEqual(LoungeBytes.IndexOfByte(bytes, 0, Asc(",")), 1)
m.assertEqual(LoungeBytes.IndexOfByte(bytes, 2, Asc(",")), 3)
m.assertEqual(LoungeBytes.IndexOfByte(bytes, 0, Asc("z")), -1)
end function
function Bytes(text as string) as object
bytes = CreateObject("roByteArray")
bytes.FromAsciiString(text)
return bytes
end function
function Utf8(b1 as integer, b2 as integer) as string
bytes = CreateObject("roByteArray")
bytes.Push(b1)
bytes.Push(b2)
return bytes.ToAsciiString()
end function
end class
end namespace
@@ -1,105 +0,0 @@
import "pkg:/components/Services/LoungeService/LoungeFraming.bs"
namespace Tests
@suite
class LoungeFramingTests extends Rooibos.BaseTestSuite
@describe("LoungeFraming.Extract")
@it("extracts a single complete frame and reports the consumed position")
function singleFrame()
result = LoungeFraming.Extract(m.Bytes(`5\nhello`), 0)
m.assertEqual(result.frames.Count(), 1)
m.assertEqual(result.frames[0], "hello")
m.assertEqual(result.nextPos, 7)
end function
@it("extracts multiple consecutive frames in one pass")
function multipleFrames()
result = LoungeFraming.Extract(m.Bytes(`5\nhello3\nfoo`), 0)
m.assertEqual(result.frames, ["hello", "foo"])
end function
@it("skips leading CR/LF between frames")
function leadingNewlines()
result = LoungeFraming.Extract(m.Bytes(`\r\n5\nhello`), 0)
m.assertEqual(result.frames, ["hello"])
end function
' The bug that motivated the rewrite: the length prefix is a BYTE count, but the old
' parser sliced with character-based string ops, so any multi-byte payload shifted every
' subsequent frame. A char-based slice of 5 from "café2..." keeps 5 characters ("café2")
' and desyncs; a byte-accurate slice keeps "café" (5 bytes) and frame 2 still lines up.
@it("slices payloads by byte length so multi-byte UTF-8 does not desync the stream")
function utf8ByteAccurate()
cafe = "caf" + m.Utf8(&hC3, &hA9) ' é is 2 bytes -> "café" is 5 bytes, 4 characters
body = m.Bytes(Str(m.ByteLen(cafe)).Trim() + Chr(10) + cafe + Str(m.ByteLen("ok")).Trim() + Chr(10) + "ok")
result = LoungeFraming.Extract(body, 0)
m.assertEqual(result.frames.Count(), 2, "a character-based slice would mis-split frame 2")
m.assertEqual(result.frames[0], cafe)
m.assertEqual(result.frames[1], "ok")
end function
@it("leaves a whole frame unconsumed when its payload has not fully arrived")
function partialPayload()
result = LoungeFraming.Extract(m.Bytes(`5\nhel`), 0)
m.assertEqual(result.frames.Count(), 0)
m.assertEqual(result.nextPos, 0)
end function
@it("consumes complete frames but retains an incomplete trailing frame")
function partialAfterComplete()
result = LoungeFraming.Extract(m.Bytes(`5\nhello2\nh`), 0)
m.assertEqual(result.frames, ["hello"])
m.assertEqual(result.nextPos, 7)
end function
@it("waits when the length line is not yet terminated")
function partialLengthLine()
result = LoungeFraming.Extract(m.Bytes("12"), 0)
m.assertEqual(result.frames.Count(), 0)
m.assertEqual(result.nextPos, 0)
end function
@it("resumes extraction from a caller-supplied position")
function resumeFromPosition()
' Index 7 is the start of the second frame ("3\nfoo").
result = LoungeFraming.Extract(m.Bytes(`5\nhello3\nfoo`), 7)
m.assertEqual(result.frames, ["foo"])
end function
@it("skips a non-positive length line instead of stalling")
function malformedLength()
result = LoungeFraming.Extract(m.Bytes(`0\n5\nhello`), 0)
m.assertEqual(result.frames, ["hello"])
end function
@it("returns no frames for an empty body")
function emptyBody()
result = LoungeFraming.Extract(m.Bytes(""), 0)
m.assertEqual(result.frames.Count(), 0)
m.assertEqual(result.nextPos, 0)
end function
function Bytes(text as string) as object
bytes = CreateObject("roByteArray")
bytes.FromAsciiString(text)
return bytes
end function
function ByteLen(text as string) as integer
return m.Bytes(text).Count()
end function
function Utf8(b1 as integer, b2 as integer) as string
bytes = CreateObject("roByteArray")
bytes.Push(b1)
bytes.Push(b2)
return bytes.ToAsciiString()
end function
end class
end namespace
@@ -14,7 +14,7 @@ namespace Tests
@it("retries a failed poll")
function _()
m.assertEqual(m.Step(LoungeCloseReason.Curl, -7, 0, false, false, 1000), LoungeSessionStep.Retry)
m.assertEqual(m.Step(LoungeCloseReason.Http, -7, 0, false, false, 1000), LoungeSessionStep.Retry)
m.assertEqual(m.Step(LoungeCloseReason.Timeout, 0, 0, false, false, 40000), LoungeSessionStep.Retry)
m.assertEqual(m.Step(LoungeCloseReason.Http, 503, 0, false, false, 1000), LoungeSessionStep.Retry)
m.assertEqual(m.Step(LoungeCloseReason.Empty, 200, 0, false, false, 1000), LoungeSessionStep.Retry)
@@ -42,11 +42,11 @@ namespace Tests
@it("drops a session that delivered no poll for the give-up time, whatever the failure")
function _()
m.assertEqual(m.Step(LoungeCloseReason.Curl, -7, 0, false, false, LoungeSession.GIVE_UP_MS), LoungeSessionStep.Drop)
m.assertEqual(m.Step(LoungeCloseReason.Http, -7, 0, false, false, LoungeSession.GIVE_UP_MS), LoungeSessionStep.Drop)
m.assertEqual(m.Step(LoungeCloseReason.Http, 400, 0, false, false, LoungeSession.GIVE_UP_MS), LoungeSessionStep.Drop)
m.assertEqual(m.Step(LoungeCloseReason.Http, 401, 0, false, false, LoungeSession.GIVE_UP_MS), LoungeSessionStep.Drop)
m.assertEqual(m.Step(LoungeCloseReason.Stalled, 200, 3, false, false, LoungeSession.GIVE_UP_MS), LoungeSessionStep.Drop)
m.assertEqual(m.Step(LoungeCloseReason.Curl, -7, 0, false, false, LoungeSession.GIVE_UP_MS - 1), LoungeSessionStep.Retry)
m.assertEqual(m.Step(LoungeCloseReason.Http, -7, 0, false, false, LoungeSession.GIVE_UP_MS - 1), LoungeSessionStep.Retry)
end function
@it("never drops a session whose poll just delivered")
@@ -34,6 +34,87 @@ namespace Tests
m.assertInvalid(proxied[0].url)
end function
@describe("DashManifest.FromVideoMetadata DRM")
function DrmFormat(itag as string, mimeType as string, drmFamilies as dynamic) as object
format = {
itag: itag
url: `https://rr1.googlevideo.com/videoplayback?itag=${itag}`
type: mimeType
bitrate: 1000000
init: "0-700"
index: "701-900"
}
if mimeType.startsWith("video")
format.width = 1920
format.height = 1080
end if
if drmFamilies <> invalid
format.drmFamilies = drmFamilies
end if
return format
end function
' Each audio/video AdaptationSet as { reps: its Representation ids, drm: its ContentProtection schemeIdUris }.
function DrmAdaptationSets(formats as object) as object
manifest = new DashManifest("")
xml = CreateObject("roXMLElement")
xml.Parse(manifest.FromVideoMetadata({ videoId: "v", lengthSeconds: 100, isPostLiveDvr: false, adaptiveFormats: formats, storyboards: [] }, {}, false))
sets = []
for each adaptationSet in xml.GetNamedElements("Period").GetNamedElements("AdaptationSet")
contentType = adaptationSet@contentType
if contentType <> "audio" and contentType <> "video"
continue for
end if
reps = []
for each representation in adaptationSet.GetNamedElements("Representation")
reps.Push(representation@id)
end for
drm = []
for each contentProtection in adaptationSet.GetNamedElements("ContentProtection")
drm.Push(contentProtection@schemeIdUri)
end for
sets.Push({ reps: reps, drm: drm })
end for
return sets
end function
@it("leaves out formats whose only DRM is FairPlay, and keeps the formats without DRM")
function _()
sets = m.DrmAdaptationSets([
m.DrmFormat("137", `video/mp4; codecs="avc1.640028"`, ["WIDEVINE", "PLAYREADY"])
m.DrmFormat("399", `video/mp4; codecs="vp09.00.40.08.00.01.01.01.00"`, ["FAIRPLAY"])
m.DrmFormat("140", `audio/mp4; codecs="mp4a.40.2"`, ["WIDEVINE", "PLAYREADY"])
m.DrmFormat("141", `audio/mp4; codecs="mp4a.40.2"`, ["FAIRPLAY"])
m.DrmFormat("136", `video/mp4; codecs="avc1.4D401F"`, invalid)
])
reps = []
for each adaptationSet in sets
reps.Append(adaptationSet.reps)
end for
reps.Sort()
m.assertEqual(reps, ["136", "137", "140"])
end function
@it("marks each set with the DRM systems its formats carry")
function _()
widevine = "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
playready = "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95"
sets = m.DrmAdaptationSets([
m.DrmFormat("140", `audio/mp4; codecs="mp4a.40.2"`, ["WIDEVINE", "PLAYREADY"])
m.DrmFormat("139", `audio/mp4; codecs="mp4a.40.5"`, ["WIDEVINE"])
m.DrmFormat("136", `video/mp4; codecs="avc1.4D401F"`, invalid)
])
drmByRep = {}
for each adaptationSet in sets
m.assertEqual(adaptationSet.reps.Count(), 1)
drmByRep[adaptationSet.reps[0]] = adaptationSet.drm
end for
m.assertEqual(drmByRep["140"], [widevine, playready])
m.assertEqual(drmByRep["139"], [widevine])
m.assertEqual(drmByRep["136"], [])
end function
@describe("DashManifest.FillLiveManifest")
' The filled startNumber, <S> entries ({ t, d, r }) and now.
@@ -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