Compare commits

..
8 Commits
16 changed files with 276 additions and 173 deletions

No files matched your search

+13
View File
@@ -5,6 +5,19 @@ 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).
## [0.43.9] - 2025-11-07
### Fixed
- Another mistake in OTF streams
## [0.43.8] - 2025-11-07
### Fixed
- Fix in url decipher logic
- Redo OTF segment processing
## [0.43.7] - 2025-11-06
### Fixed
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "playlet",
"version": "0.43.7",
"version": "0.43.9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "playlet",
"version": "0.43.7",
"version": "0.43.9",
"hasInstallScript": true,
"devDependencies": {
"@rokucommunity/bslint": "^0.8.38",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "playlet",
"version": "0.43.7",
"version": "0.43.9",
"description": "Unofficial YouTube client for Roku",
"devDependencies": {
"@rokucommunity/bslint": "^0.8.38",
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "playlet-app",
"version": "0.43.7",
"version": "0.43.9",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "playlet-app",
"version": "0.43.7"
"version": "0.43.9"
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "playlet-app",
"version": "0.43.7",
"version": "0.43.9",
"description": "Unofficial YouTube client for Roku",
"scripts": {
"prebuild": "node ../tools/rm.js ../build/playlet-app",
+1 -1
View File
@@ -3,7 +3,7 @@ title=Playlet
# Do not update version manually, it is auto updated from package.json
major_version=0
minor_version=43
build_version=00007
build_version=00009
ui_resolutions=hd
uri_resolution_autosub=$$RES$$,480p,720p,1080p
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "playlet-lib",
"version": "0.43.7",
"version": "0.43.9",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "playlet-lib",
"version": "0.43.7"
"version": "0.43.9"
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "playlet-lib",
"version": "0.43.7",
"version": "0.43.9",
"description": "Unofficial YouTube client for Roku",
"scripts": {
"prebuild": "node ../tools/rm.js ../build/playlet-lib",
@@ -496,11 +496,7 @@ class DashManifest
xml.Comment(`[ERROR] OTF stream has empty otfSegmentDurations for itag: ${stream.itag}`)
end if
for each segment in segmentDurations
sAttributes = { "d": segment.duration }
if segment.repeatCount <> invalid
sAttributes["r"] = segment.repeatCount
end if
xml.EmptyNode("S", sAttributes)
xml.EmptyNode("S", segment)
end for
xml.End()
end if
@@ -0,0 +1,194 @@
import "pkg:/components/Services/Innertube/Context.bs"
namespace Innertube
' OTF (On-The-Fly?) segment info retrieval and parsing
' When innertube returns adaptive formats, sometimes there's a property
' attached to the object: adaptiveFormats[].type = "FORMAT_STREAM_TYPE_OTF".
' When that happens, the segment info (durations, repeat counts) is not included
' in the response. Instead, they are appended to the media init segment itself.
' The init segment would contain video init information, which is binary, appended
' with a text section in this format:
' `Segment-Count: 731\r\n` +
' `Segment-Durations-Ms: 5333,5334,5333(r=1),5334,5333(r=1),\r\n`
' Because of this, the init segment needs to be downloaded to a tmp file, loaded in
' a byte array, converted to hex, and parsed. Loading the file to ascii string directly
' would not work because it would be truncated at the first null byte.
const OTF_MAX_REQUEST_COUNT = 8
function OTFGetSegmentInfo(adaptiveFormats as object, client as Innertube.ClientType, cancellation as object) as void
errors = {
message: ""
attachments: []
}
formatsToProcess = []
for i = 0 to adaptiveFormats.Count() - 1
formatsToProcess.Push({
format: adaptiveFormats[i]
file: `tmp:/otf_segments/${i}.bin`
})
end for
pendingFormats = []
requestHeaders = Innertube.CreateHeaders(client)
requestHeaders["origin"] = "https://www.youtube.com"
requestHeaders["referer"] = "https://www.youtube.com"
requestHeaders["DNT"] = "?1"
fs = CreateObject("roFileSystem")
fs.Delete("tmp:/otf_segments")
fs.CreateDirectory("tmp:/otf_segments")
while true
while formatsToProcess.Count() > 0 and pendingFormats.Count() < OTF_MAX_REQUEST_COUNT
formatToProcess = formatsToProcess.Pop()
request = OTFMakeSegmentInfoRequest(formatToProcess.format, formatToProcess.file, requestHeaders, errors, cancellation)
if request <> invalid
formatToProcess.request = request
pendingFormats.Push(formatToProcess)
end if
end while
if pendingFormats.Count() = 0
exit while
end if
pendingFormat = pendingFormats.Shift()
' returns false if processing should stop (e.g., cancelled)
if not OTFProcessPendingFormat(pendingFormat.format, pendingFormat.request, pendingFormat.file, errors)
exit while
end if
end while
fs.Delete("tmp:/otf_segments")
if not StringUtils.IsNullOrEmpty(errors.message) or errors.attachments.Count() > 0
LogTelemetryEvent({
level: "error"
message: `OTF errors during segment info retrieval: \n${errors.message}`
fingerprint: ["OTF errors during segment info retrieval"]
attachments: errors.attachments
})
end if
end function
function OTFMakeSegmentInfoRequest(format as object, file as string, requestHeaders as object, errors as object, cancellation as object) as object
url = format.url
if StringUtils.IsNullOrEmpty(url)
errors.message += `URL is empty for itag ${format.itag}.\n`
return invalid
end if
queryComponents = UrlUtils.ParseQueryComponents(url)
queryComponents["rn"] = "0"
queryComponents["sq"] = "0"
otfUrl = UrlUtils.SetQueryParams(url, queryComponents)
request = HttpClient.Get(otfUrl)
request.Headers(requestHeaders)
request.ToFile(file)
request.Cancellation(cancellation)
request.Send()
return request
end function
function OTFProcessPendingFormat(format as object, request as object, file as string, errors as object) as boolean
response = request.Await()
if response.IsCancelled()
return false
end if
if not response.IsSuccess()
errors.message += `Failed to get segment info for itag ${format.itag}: ${response.ErrorMessage()}\n`
return true
end if
segmentDurations = OTFParseFileForSegmentDurations(file, errors)
if segmentDurations = invalid
errors.message += `Failed to parse segment durations for itag ${format.itag}.\n`
errors.message += `Headers: ${ToString(response.Headers())}\n`
return true
end if
format["otfSegmentDurations"] = segmentDurations
return true
end function
function OTFParseFileForSegmentDurations(filePath as string, errors as object) as dynamic
buffer = CreateObject("roByteArray")
buffer.FromAsciiString("Segment-Durations-Ms:")
startMarkerHex = buffer.ToHexString()
buffer.FromAsciiString(`\r\n`)
endMarkerHex = buffer.ToHexString()
if not buffer.ReadFile(filePath)
errors.message += `Failed to read file at path ${filePath}.\n`
return invalid
end if
contentHex = buffer.ToHexString()
startIndex = contentHex.InStr(startMarkerHex)
if startIndex = -1
errors.message += `Start marker not found in file at path ${filePath}.\n`
errors.attachments.Push({
filename: filePath
content_type: "plain/text"
data: contentHex
})
return invalid
end if
endIndex = contentHex.InStr(startIndex, endMarkerHex)
if endIndex = -1
errors.message += `End marker not found in file at path ${filePath}.\n`
errors.attachments.Push({
filename: filePath
content_type: "plain/text"
data: contentHex
})
return invalid
end if
segmentDurationsMsHex = contentHex.Mid(startIndex + startMarkerHex.len(), endIndex - (startIndex + startMarkerHex.len()))
buffer.FromHexString(segmentDurationsMsHex)
segmentDurationsMs = buffer.ToAsciiString()
regex = CreateObject("roRegex", "(\d+)(?:\(r=(\d+)\))?", "g")
matches = regex.MatchAll(segmentDurationsMs)
if not IsArray(matches) or matches.Count() = 0
errors.message += `No segment duration matches found in file at path ${filePath}.\n`
errors.attachments.Push({
filename: filePath
content_type: "plain/text"
data: contentHex
})
return invalid
end if
segmentDurations = CreateObject("roArray", matches.Count(), false)
for i = 0 to matches.Count() - 1
match = matches[i]
segment = {}
' We set duration and repeatCount to "d" and "r" so that we can feed
' them directly into the DashManifest generation code.
if match.Count() >= 2
segment["d"] = match[1].ToInt()
end if
if match.Count() >= 3
segment["r"] = match[2].ToInt()
end if
segmentDurations[i] = segment
end for
return segmentDurations
end function
end namespace
@@ -1,5 +1,6 @@
import "pkg:/components/Services/Innertube/Context.bs"
import "pkg:/components/Services/Innertube/NodesParser.bs"
import "pkg:/components/Services/Innertube/OTFSegmentInfo.bs"
import "pkg:/source/services/HttpClient.bs"
import "pkg:/source/utils/ObjectUtils.bs"
import "pkg:/source/utils/Types.bs"
@@ -168,7 +169,7 @@ namespace Innertube
if isOTF
LogDebug("Fetching OTF segment info")
GetOTFSegmentInfo(adaptiveFormats, client, cancellation)
OTFGetSegmentInfo(adaptiveFormats, client, cancellation)
end if
return parsedResponse
@@ -547,8 +548,7 @@ namespace Innertube
for i = 0 to decipheredFormats.Count() - 1
fmt = formats[i]
decipheredFmt = decipheredFormats[i]
fmt["url"] = decipheredFmt["url"]
fmt["url"] = ResetUrlClientVersion(decipheredFmt["url"])
end for
decipheredAdaptiveFormats = json["adaptiveFormats"]
@@ -562,11 +562,34 @@ namespace Innertube
for i = 0 to decipheredAdaptiveFormats.Count() - 1
fmt = adaptiveFormats[i]
decipheredFmt = decipheredAdaptiveFormats[i]
fmt["url"] = decipheredFmt["url"]
fmt["url"] = ResetUrlClientVersion(decipheredFmt["url"])
end for
return invalid
end function
' YouTube.js sets cver to hardcoded values that might be different from
' What's used in Playlet. There's no indication that this makes a difference,
' but it makes sense to keep it consistent.
function ResetUrlClientVersion(url as dynamic) as dynamic
if StringUtils.IsNullOrEmpty(url)
return url
end if
queryComponents = UrlUtils.ParseQueryComponents(url)
client = ValidString(queryComponents["c"])
if client = "TVHTML5"
queryComponents["cver"] = INNERTUBE_TV_CLIENT_VERSION
else if client = "IOS"
queryComponents["cver"] = INNERTUBE_IOS_CLIENT_VERSION
else if client = "WEB"
queryComponents["cver"] = INNERTUBE_WEB_CLIENT_VERSION
else
return url
end if
return UrlUtils.SetQueryParams(url, queryComponents)
end function
function ParseIsLoggedIn(payload as object) as boolean
trackingParams = ObjectUtils.Dig(payload, ["responseContext", "serviceTrackingParams"])
if not IsArray(trackingParams)
@@ -709,149 +732,4 @@ namespace Innertube
end if
end function
function GetOTFSegmentInfo(adaptiveFormats as object, client as Innertube.ClientType, cancellation as object) as void
requests = CreateObject("roArray", adaptiveFormats.Count(), false)
requestHeaders = Innertube.CreateHeaders(client)
requestHeaders["origin"] = "https://www.youtube.com"
requestHeaders["referer"] = "https://www.youtube.com"
requestHeaders["DNT"] = "?1"
for i = 0 to adaptiveFormats.Count() - 1
format = adaptiveFormats[i]
if format.isTypeOTF <> true
continue for
end if
url = format.url
if StringUtils.IsNullOrEmpty(url)
LogError("GetOTFSegmentInfo: URL is empty for itag", format.itag)
continue for
end if
queryComponents = UrlUtils.ParseQueryComponents(url)
queryComponents["rn"] = "0"
queryComponents["sq"] = "0"
otfUrl = UrlUtils.SetQueryParams(url, queryComponents)
request = HttpClient.Get(otfUrl)
request.Headers(requestHeaders)
request.TryCount(2)
request.Cancellation(cancellation)
request.Send()
requests[i] = request
end for
for i = 0 to requests.Count() - 1
request = requests[i]
if request = invalid
continue for
end if
format = adaptiveFormats[i]
response = request.Await()
if response.IsCancelled()
return
end if
if not response.IsSuccess()
LogErrorNoTelemetry("Failed to fetch OTF segment info for itag", format.itag, response.ErrorMessage())
LogTelemetryEvent({
level: "error"
message: `Failed to fetch OTF segment info for itag ${format.itag}`
fingerprint: ["OTF Fetch Error"]
attachments: [{
filename: "otf.txt"
content_type: "plain/text"
data: response.ErrorMessage()
}]
})
continue for
end if
responseText = response.Text()
segmentDurationsMs = StringUtils.GetBetween(responseText, "Segment-Durations-Ms:", `\r\n`)
if StringUtils.IsNullOrEmpty(segmentDurationsMs)
LogErrorNoTelemetry("Failed to extract Segment-Durations-Ms from OTF stream for itag", format.itag)
LogTelemetryEvent({
level: "error"
message: `Failed to extract Segment-Durations-Ms from OTF stream for itag ${format.itag}`
fingerprint: ["OTF Missing Segment Durations"]
attachments: [{
filename: "otf.txt"
content_type: "plain/text"
data: responseText
}, {
filename: "headers.json"
content_type: "application/json"
data: FormatJson(response.Headers())
}]
})
continue for
end if
segmentDurationStrings = segmentDurationsMs.Split(",")
segmentDurations = []
for each segmentDurationString in segmentDurationStrings
trimmedSegmentDuration = segmentDurationString.Trim()
if trimmedSegmentDuration.Len() = 0
continue for
end if
repeatCount = invalid
repeatCountString = StringUtils.GetBetween(trimmedSegmentDuration, "(r=", ")")
if not StringUtils.IsNullOrEmpty(repeatCountString)
repeatCount = repeatCountString.ToInt()
end if
duration = trimmedSegmentDuration.ToInt()
if duration <= 0
LogErrorNoTelemetry("Invalid OTF segment duration parsed", trimmedSegmentDuration, "for itag", format.itag)
LogTelemetryEvent({
level: "error"
message: `Invalid OTF segment duration parsed: ${trimmedSegmentDuration} for itag ${format.itag}`
fingerprint: ["OTF Invalid Segment Duration"]
attachments: [{
filename: "otf.txt"
content_type: "plain/text"
data: responseText
}, {
filename: "headers.json"
content_type: "application/json"
data: FormatJson(response.Headers())
}]
})
continue for
end if
segmentDurations.Push({
duration: duration
repeatCount: repeatCount
})
end for
format["otfSegmentDurations"] = segmentDurations
if segmentDurations.Count() = 0
LogErrorNoTelemetry("No OTF segment durations found for itag", format.itag)
LogTelemetryEvent({
level: "error"
message: `No OTF segment durations found for itag ${format.itag}`
fingerprint: ["OTF No Segment Durations"]
attachments: [{
filename: "otf.txt"
content_type: "plain/text"
data: responseText
}, {
filename: "headers.json"
content_type: "application/json"
data: FormatJson(response.Headers())
}]
})
end if
end for
end function
end namespace
@@ -447,7 +447,7 @@ function OnVideoPlayerStateChange() as void
errorData = GetPlayerErrorData(content.videoId, errorInfo)
LogErrorNoTelemetry(errorData.title, errorData.body)
ReportVideoError(errorData, content.url)
ReportVideoError(errorData, content.url, content.playletStreamUrls, content.playletStreamUrlIndex)
errorReported = true
if m.videoPlayingSuccess <> true
@@ -509,7 +509,7 @@ function OnVideoPlayerStateChange() as void
LogErrorNoTelemetry(errorData.title, errorData.body)
if not errorReported
ReportVideoError(errorData, content.url)
ReportVideoError(errorData, content.url, content.playletStreamUrls, content.playletStreamUrlIndex)
end if
buttons = [Tr(Locale.Buttons.PlayNextVideo), Tr(Locale.Buttons.Cancel)]
@@ -557,7 +557,7 @@ function GetPlayerErrorData(videoId as string, errorInfo as object) as object
}
end function
function ReportVideoError(errorData as object, url as string) as void
function ReportVideoError(errorData as object, url as string, urls as object, urlIndex as dynamic) as void
attachments = invalid
if errorData.body.Instr("malformed data") <> -1 or errorData.body.Instr("invalid pathname") <> -1
lastGeneratedDash = ValidString(ReadAsciiFile("cachefs:/last_generated_dash.xml"))
@@ -581,9 +581,18 @@ function ReportVideoError(errorData as object, url as string) as void
position = m.top.position
duration = m.top.duration
message = [
errorData.title
errorData.body
`Position: ${position}`
`Duration: ${duration}`
`Url: ${url}`
`Urls: ` + ToString(urls)
`Url index: ${urlIndex}`
].Join(`\n`)
LogTelemetryEvent({
level: "error"
message: errorData.title + " " + errorData.body + `\nurl: ${url}\nposition: ${position}\nduration: ${duration}`
message: message
fingerprint: errorData.fingerprint
attachments: attachments
})
+1 -1
View File
@@ -3,7 +3,7 @@ title=PlayletLib
# Do not update version manually, it is auto updated from package.json
major_version=0
minor_version=43
build_version=00007
build_version=00009
ui_resolutions=hd
uri_resolution_autosub=$$RES$$,480p,720p,1080p
+14 -1
View File
@@ -299,6 +299,11 @@ namespace HttpClient
return m
end function
function ToFile(filePath as string) as HttpRequest
m._toFilePath = filePath
return m
end function
function ToCurlCommand() as string
command = `curl "${m.BuildUrl()}"`
if m._method = "HEAD"
@@ -387,6 +392,10 @@ namespace HttpClient
end if
#end if
if m._toFilePath <> invalid and m._method <> "GET"
throw "ToFile() can only be used with GET requests."
end if
if m._method = "POST"
body = m._body
if body = invalid
@@ -394,7 +403,11 @@ namespace HttpClient
end if
m._sent = m.urlTransfer.AsyncPostFromString(body)
else if m._method = "GET"
m._sent = m.urlTransfer.AsyncGetToString()
if m._toFilePath <> invalid
m._sent = m.urlTransfer.AsyncGetToFile(m._toFilePath)
else
m._sent = m.urlTransfer.AsyncGetToString()
end if
else if m._method = "HEAD"
m._sent = m.urlTransfer.AsyncHead()
else
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "playlet-web",
"version": "0.43.7",
"version": "0.43.9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "playlet-web",
"version": "0.43.7",
"version": "0.43.9",
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^6.2.1",
"@tailwindcss/postcss": "^4.1.16",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "playlet-web",
"version": "0.43.7",
"version": "0.43.9",
"type": "module",
"scripts": {
"dev": "vite",