Compare commits

..
14 Commits
25 changed files with 576 additions and 297 deletions

No files matched your search

+16
View File
@@ -5,6 +5,22 @@ 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.2] - 2025-10-29
### Fixed
- Crash on older Roku OS version due to `roByteArray.Slice` not being available
## [0.43.1] - 2025-10-28
### Added
- Support for additional nodes parsing
### Fixed
- Trickplay storyboards on DRM videos
## [0.43.0] - 2025-10-26
### Added
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "playlet",
"version": "0.43.0",
"version": "0.43.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "playlet",
"version": "0.43.0",
"version": "0.43.2",
"hasInstallScript": true,
"devDependencies": {
"@rokucommunity/bslint": "^0.8.37",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "playlet",
"version": "0.43.0",
"version": "0.43.2",
"description": "Unofficial YouTube client for Roku",
"devDependencies": {
"@rokucommunity/bslint": "^0.8.37",
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "playlet-app",
"version": "0.43.0",
"version": "0.43.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "playlet-app",
"version": "0.43.0"
"version": "0.43.2"
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "playlet-app",
"version": "0.43.0",
"version": "0.43.2",
"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=00000
build_version=00002
ui_resolutions=hd
uri_resolution_autosub=$$RES$$,480p,720p,1080p
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "playlet-lib",
"version": "0.43.0",
"version": "0.43.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "playlet-lib",
"version": "0.43.0"
"version": "0.43.2"
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "playlet-lib",
"version": "0.43.0",
"version": "0.43.2",
"description": "Unofficial YouTube client for Roku",
"scripts": {
"prebuild": "node ../tools/rm.js ../build/playlet-lib",
@@ -56,6 +56,7 @@ class DashManifest
end if
if videoStreams.Count() = 0
lastPlayerResponse = ValidString(ReadAsciiFile("cachefs:/last_player_response.json"))
LogTelemetryEvent({
level: "error"
message: "No video streams found in metadata for Dash."
@@ -64,6 +65,10 @@ class DashManifest
filename: "metadata.json"
content_type: "application/json"
data: FormatJson(metadata)
}, {
filename: "last_player_response.json"
content_type: "application/json"
data: lastPlayerResponse
}]
})
end if
@@ -86,214 +91,9 @@ class DashManifest
if xml.Node("Period")
id = 0
for each audioSet in audioSets
adaptationSetAttributes = {
"id": `${id}`
"mimeType": audioSet.mimeType
"startWithSAP": "1"
"subsegmentAlignment": "true"
}
if not StringUtils.IsNullOrEmpty(audioSet.lang)
adaptationSetAttributes["lang"] = audioSet.lang
end if
if xml.Node("AdaptationSet", adaptationSetAttributes)
xml.EmptyNode("Role", {
"schemeIdUri": "urn:mpeg:dash:role:2011"
"value": audioSet.acont = "original" ? "main" : "alternate"
})
for i = 0 to audioStreams.Count() - 1
stream = audioStreams[i]
streamMimeType = stream.type.Tokenize(";")[0]
if streamMimeType <> audioSet.mimeType or stream.languageInfo.lang <> audioSet.lang or stream.languageInfo.acont <> audioSet.acont
continue for
end if
codecs = stream.type.split("codecs=")[1]
if codecs.startsWith(`"`)
codecs = codecs.mid(1)
end if
if codecs.endsWith(`"`)
codecs = codecs.left(codecs.len() - 1)
end if
if xml.Node("Representation", {
"id": stream.itag
"codecs": codecs
"bandwidth": stream.bitrate
})
xml.EmptyNode("AudioChannelConfiguration", {
"schemeIdUri": "urn:mpeg:dash:23003:3:audio_channel_configuration:2011"
"value": `${stream.audioChannels}`
})
if StringUtils.IsNullOrEmpty(stream.url)
xml.Comment(`[ERROR] Stream.url is null or empty for itag: ${stream.itag}`)
else if stream.url.InStr("yt_live_broadcast") <> -1 or stream.url.InStr("yt_premiere_broadcast") <> -1
xml.Comment(`[WARN] Stream URL indicates a live broadcast for itag: ${stream.itag}`)
end if
xml.TextNode("BaseURL", ValidString(stream.url))
if StringUtils.IsNullOrEmpty(stream.index) or StringUtils.IsNullOrEmpty(stream.init)
xml.Comment(`[ERROR] Stream index: ${stream.index}, init: ${stream.init} is invalid for itag: ${stream.itag}`)
end if
if xml.Node("SegmentBase", { "indexRange": stream.index })
xml.EmptyNode("Initialization", { "range": stream.init })
xml.End()
end if
xml.End()
end if
end for
xml.End()
end if
id += 1
end for
for each mimeType in videoMimeTypes
if xml.Node("AdaptationSet", {
"id": `${id}`
"mimeType": mimeType
"startWithSAP": "1"
"subsegmentAlignment": "true"
})
for i = 0 to videoStreams.Count() - 1
stream = videoStreams[i]
streamMimeType = stream.type.Tokenize(";")[0]
if streamMimeType <> mimeType
continue for
end if
codecs = stream.type.split("codecs=")[1]
if codecs.startsWith(`"`)
codecs = codecs.mid(1)
end if
if codecs.endsWith(`"`)
codecs = codecs.left(codecs.len() - 1)
end if
representationAttributes = {
"id": stream.itag
"codecs": codecs
"startWithSAP": "1"
"maxPlayoutRate": "1"
"bandwidth": stream.bitrate
}
if stream.width <> invalid
representationAttributes["width"] = `${stream.width}`
end if
if stream.height <> invalid
representationAttributes["height"] = `${stream.height}`
end if
if stream.fps <> invalid
representationAttributes["frameRate"] = `${stream.fps}`
end if
if xml.Node("Representation", representationAttributes)
m.AddColorInfo(stream, xml)
if StringUtils.IsNullOrEmpty(stream.url)
xml.Comment(`[ERROR] Stream.url is null or empty for itag: ${stream.itag}`)
else if stream.url.InStr("yt_live_broadcast") <> -1 or stream.url.InStr("yt_premiere_broadcast") <> -1
xml.Comment(`[WARN] Stream URL indicates a live broadcast for itag: ${stream.itag}`)
end if
xml.TextNode("BaseURL", ValidString(stream.url))
if StringUtils.IsNullOrEmpty(stream.index) or StringUtils.IsNullOrEmpty(stream.init)
xml.Comment(`[ERROR] Stream index: ${stream.index}, init: ${stream.init} is invalid for itag: ${stream.itag}`)
end if
if xml.Node("SegmentBase", { "indexRange": stream.index })
xml.EmptyNode("Initialization", { "range": stream.init })
xml.End()
end if
xml.End()
end if
end for
xml.End()
end if
id += 1
end for
' https://developer.roku.com/en-ca/docs/developer-program/media-playback/trick-mode/hls-and-dash.md#dash-standard-thumbnail-tiles
for each storyboard in storyboards
interval = ValidInt(storyboard.interval)
if interval = 0
LogWarnNoTelemetry("Invalid storyboard interval:", storyboard.interval)
continue for
end if
storyboardWidth = storyboard.storyboardWidth
storyboardHeight = storyboard.storyboardHeight
storyboardCount = storyboard.storyboardCount
tileWidthInPixels = storyboard.width
tileHeightInPixels = storyboard.height
totalTileCount = storyboard.count
' For the last page, the image height might be smaller than the storyboard height
if storyboardCount = 1
storyboardHeight = totalTileCount \ storyboardWidth
if totalTileCount mod storyboardWidth > 0
storyboardHeight += 1
end if
end if
intervalInSeconds = interval / 1000.0
' YouTube template uses the var $M for tile pages
' DASH-IF uses $Number$ in the SegmentTemplate
' https://dashif.org/docs/DASH-IF-IOP-v4.3.pdf
url = storyboard.templateUrl.replace("$M", "$Number$")
tilesPerPage = storyboardWidth * storyboardHeight
duration = tilesPerPage * intervalInSeconds
storyboardWidthInPixels = tileWidthInPixels * storyboardWidth
storyboardHeightInPixels = tileHeightInPixels * storyboardHeight
' Bandwidth is kind of a guess...
bandwidth = ((storyboardWidthInPixels * storyboardHeightInPixels * 0.5) / duration)
if xml.Node("AdaptationSet", {
"id": `${id}`
"mimeType": "image/jpeg"
"contentType": "image"
})
xml.EmptyNode("SegmentTemplate", {
"media": url
"duration": duration
"startNumber": 0
})
if xml.Node("Representation", {
"id": `thumbnails_${id}`
"bandwidth": bandwidth
"width": storyboardWidthInPixels
"height": storyboardHeightInPixels
})
xml.EmptyNode("EssentialProperty", {
"schemeIdUri": "http://dashif.org/guidelines/thumbnail_tile"
"value": `${storyboardWidth}x${storyboardHeight}`
})
xml.End()
end if
xml.End()
end if
id += 1
end for
id = m.generateAudioAdaptationSets(xml, audioSets, audioStreams, id)
id = m.generateVideoAdaptationSets(xml, videoMimeTypes, videoStreams, id)
m.generateImageAdaptationSets(xml, storyboards, id)
xml.End()
end if
@@ -303,6 +103,225 @@ class DashManifest
return xml.ToXmlString()
end function
function generateAudioAdaptationSets(xml as object, audioSets as object, audioStreams as object, id as integer) as integer
for each audioSet in audioSets
adaptationSetAttributes = {
"id": `${id}`
"mimeType": audioSet.mimeType
"startWithSAP": "1"
"subsegmentAlignment": "true"
}
if not StringUtils.IsNullOrEmpty(audioSet.lang)
adaptationSetAttributes["lang"] = audioSet.lang
end if
if xml.Node("AdaptationSet", adaptationSetAttributes)
xml.EmptyNode("Role", {
"schemeIdUri": "urn:mpeg:dash:role:2011"
"value": audioSet.acont = "original" ? "main" : "alternate"
})
for i = 0 to audioStreams.Count() - 1
stream = audioStreams[i]
streamMimeType = stream.type.Tokenize(";")[0]
if streamMimeType <> audioSet.mimeType or stream.languageInfo.lang <> audioSet.lang or stream.languageInfo.acont <> audioSet.acont
continue for
end if
codecs = stream.type.split("codecs=")[1]
if codecs.startsWith(`"`)
codecs = codecs.mid(1)
end if
if codecs.endsWith(`"`)
codecs = codecs.left(codecs.len() - 1)
end if
if xml.Node("Representation", {
"id": stream.itag
"codecs": codecs
"bandwidth": stream.bitrate
})
xml.EmptyNode("AudioChannelConfiguration", {
"schemeIdUri": "urn:mpeg:dash:23003:3:audio_channel_configuration:2011"
"value": `${stream.audioChannels}`
})
if StringUtils.IsNullOrEmpty(stream.url)
xml.Comment(`[ERROR] Stream.url is null or empty for itag: ${stream.itag}`)
else if stream.url.InStr("yt_live_broadcast") <> -1 or stream.url.InStr("yt_premiere_broadcast") <> -1
xml.Comment(`[WARN] Stream URL indicates a live broadcast for itag: ${stream.itag}`)
end if
xml.TextNode("BaseURL", ValidString(stream.url))
if StringUtils.IsNullOrEmpty(stream.index) or StringUtils.IsNullOrEmpty(stream.init)
xml.Comment(`[ERROR] Stream index: ${stream.index}, init: ${stream.init} is invalid for itag: ${stream.itag}`)
end if
if xml.Node("SegmentBase", { "indexRange": stream.index })
xml.EmptyNode("Initialization", { "range": stream.init })
xml.End()
end if
xml.End()
end if
end for
xml.End()
end if
id += 1
end for
return id
end function
function generateVideoAdaptationSets(xml as object, videoMimeTypes as object, videoStreams as object, id as integer) as integer
for each mimeType in videoMimeTypes
if xml.Node("AdaptationSet", {
"id": `${id}`
"mimeType": mimeType
"startWithSAP": "1"
"subsegmentAlignment": "true"
})
for i = 0 to videoStreams.Count() - 1
stream = videoStreams[i]
streamMimeType = stream.type.Tokenize(";")[0]
if streamMimeType <> mimeType
continue for
end if
codecs = stream.type.split("codecs=")[1]
if codecs.startsWith(`"`)
codecs = codecs.mid(1)
end if
if codecs.endsWith(`"`)
codecs = codecs.left(codecs.len() - 1)
end if
representationAttributes = {
"id": stream.itag
"codecs": codecs
"startWithSAP": "1"
"maxPlayoutRate": "1"
"bandwidth": stream.bitrate
}
if stream.width <> invalid
representationAttributes["width"] = `${stream.width}`
end if
if stream.height <> invalid
representationAttributes["height"] = `${stream.height}`
end if
if stream.fps <> invalid
representationAttributes["frameRate"] = `${stream.fps}`
end if
if xml.Node("Representation", representationAttributes)
m.AddColorInfo(stream, xml)
if StringUtils.IsNullOrEmpty(stream.url)
xml.Comment(`[ERROR] Stream.url is null or empty for itag: ${stream.itag}`)
else if stream.url.InStr("yt_live_broadcast") <> -1 or stream.url.InStr("yt_premiere_broadcast") <> -1
xml.Comment(`[WARN] Stream URL indicates a live broadcast for itag: ${stream.itag}`)
end if
xml.TextNode("BaseURL", ValidString(stream.url))
if StringUtils.IsNullOrEmpty(stream.index) or StringUtils.IsNullOrEmpty(stream.init)
xml.Comment(`[ERROR] Stream index: ${stream.index}, init: ${stream.init} is invalid for itag: ${stream.itag}`)
end if
if xml.Node("SegmentBase", { "indexRange": stream.index })
xml.EmptyNode("Initialization", { "range": stream.init })
xml.End()
end if
xml.End()
end if
end for
xml.End()
end if
id += 1
end for
return id
end function
function generateImageAdaptationSets(xml as object, storyboards as object, id as integer) as integer
' https://developer.roku.com/en-ca/docs/developer-program/media-playback/trick-mode/hls-and-dash.md#dash-standard-thumbnail-tiles
for i = storyboards.Count() - 1 to 0 step -1
storyboard = storyboards[i]
interval = ValidInt(storyboard.interval)
if interval = 0
LogWarnNoTelemetry("Invalid storyboard interval:", storyboard.interval)
continue for
end if
storyboardWidth = storyboard.storyboardWidth
storyboardHeight = storyboard.storyboardHeight
storyboardCount = storyboard.storyboardCount
tileWidthInPixels = storyboard.width
tileHeightInPixels = storyboard.height
totalTileCount = storyboard.count
' For the last page, the image height might be smaller than the storyboard height
if storyboardCount = 1
storyboardHeight = totalTileCount \ storyboardWidth
if totalTileCount mod storyboardWidth > 0
storyboardHeight += 1
end if
end if
intervalInSeconds = interval / 1000.0
' YouTube template uses the var $M for tile pages
' DASH-IF uses $Number$ in the SegmentTemplate
' https://dashif.org/docs/DASH-IF-IOP-v4.3.pdf
url = storyboard.templateUrl.replace("$M", "$Number$")
tilesPerPage = storyboardWidth * storyboardHeight
duration = tilesPerPage * intervalInSeconds
storyboardWidthInPixels = tileWidthInPixels * storyboardWidth
storyboardHeightInPixels = tileHeightInPixels * storyboardHeight
' Bandwidth is kind of a guess...
bandwidth = ((storyboardWidthInPixels * storyboardHeightInPixels * 0.5) / duration)
if xml.Node("AdaptationSet", {
"id": `${id}`
"mimeType": "image/jpeg"
"contentType": "image"
})
xml.EmptyNode("SegmentTemplate", {
"media": url
"duration": duration
"startNumber": 0
})
if xml.Node("Representation", {
"id": `thumbnails_${id}`
"bandwidth": bandwidth
"width": storyboardWidthInPixels
"height": storyboardHeightInPixels
})
xml.EmptyNode("EssentialProperty", {
"schemeIdUri": "http://dashif.org/guidelines/thumbnail_tile"
"value": `${storyboardWidth}x${storyboardHeight}`
})
xml.End()
end if
xml.End()
end if
id += 1
end for
return id
end function
function getAudioStreams(streams as object) as object
audioStreams = []
for i = 0 to streams.Count() - 1
@@ -90,7 +90,7 @@ namespace InnertubeService
continue while
end if
parsedResponse = Innertube.ParseInnertubePlayerResponse(playerResponseJson, {}, playerRequest, cancellation)
parsedResponse = Innertube.ParseInnertubePlayerResponse(playerRequest, playerResponse, {}, cancellation)
if parsedResponse.error = invalid
exit while
@@ -93,25 +93,26 @@ namespace Innertube
"tvSurfaceContentContinuation": ParseTvSurfaceContentContinuation
"gridButtonRenderer": ParseGridButtonRenderer
"movieRenderer": ParseMovieRenderer
"gridMovieRenderer": ParseGridMovieRenderer
"compactMovieRenderer": ParseCompactMovieRenderer
"horizontalMovieListRenderer": ParseHorizontalMovieListRenderer
' Movies and shows are partially supported, but these renderers are not yet implemented.
' "gridMovieRenderer": ParseNotImplemented
' "gridShowRenderer": ParseNotImplemented
' "playlistShowMetadataRenderer": ParseNotImplemented
' Ignored nodes:
' TODO:P2 handle navigateAction - which are usually a redirect
"navigateAction": ParseNotImplemented
' "navigateAction": ParseNotImplemented
' TODO:P2 radioRenderer seems like a Mix https://github.com/iBicha/playlet/issues/709
"radioRenderer": ParseNotImplemented
"compactRadioRenderer": ParseNotImplemented
"radioRenderer": ParseRadioRenderer
' "compactRadioRenderer": ParseNotImplemented
' TODO:P2 A carousel of videos, found on the home tab of a channel.
' Should probably be parsed.
"carouselItemRenderer": ParseNotImplemented
' "carouselItemRenderer": ParseNotImplemented
' When searching for hashtags, this renderer is used.
' It redirects to a page similar to a channel page, with browseId "FEhashtag"
' the hashtag name is encoded in a proto and passed as a param to the browseEndpoint.
"hashtagTileRenderer": ParseNotImplemented
' Movies and shows are partially supported, but these renderers are not yet implemented.
"horizontalMovieListRenderer": ParseNotImplemented
"gridMovieRenderer": ParseNotImplemented
"gridShowRenderer": ParseNotImplemented
"playlistShowMetadataRenderer": ParseNotImplemented
' Contains comments "teaser".
"commentsEntryPointHeaderRenderer": ParseNotImplemented
' Contains the owner of the video from "videoPrimaryInfoRenderer"
@@ -997,6 +998,33 @@ namespace Innertube
return invalid
end function
function ParseRadioRenderer(nodeData as object, context as object) as object
playlistId = nodeData["playlistId"]
if not IsString(playlistId)
Warning("Invalid playlist ID in radioRenderer", nodeData, context)
return invalid
end if
videoCountText = ParseText(nodeData["videoCountText"])
playlist = {
"type": "playlist"
"playlistId": playlistId
"title": ParseText(nodeData["title"])
"playlistThumbnail": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails", 0, "url"])
"videoCountText": videoCountText
}
' Mixes have a videoId, which is the first video in the mix
videoId = ObjectUtils.Dig(nodeData, ["navigationEndpoint", "watchEndpoint", "videoId"])
if IsString(videoId)
playlist["videoId"] = videoId
end if
PushFeedItem(playlist, context)
return invalid
end function
function ParseGridShelfViewModel(nodeData as object, _context as object) as object
return nodeData["contents"]
end function
@@ -1100,6 +1128,16 @@ namespace Innertube
title = ObjectUtils.Dig(metadata, ["title", "content"])
authorId = ObjectUtils.Dig(metadata, ["image", "decoratedAvatarViewModel", "rendererContext", "commandContext", "onTap", "innertubeCommand", "browseEndpoint", "browseId"])
thumbnailViewModel = ObjectUtils.Dig(nodeData, ["contentImage", "thumbnailViewModel"])
if context.generateVideoThumbnails = true
videoThumbnails = GenerateVideoThumbnails(videoId)
else
videoThumbnails = ObjectUtils.Dig(thumbnailViewModel, ["image", "sources"])
if videoThumbnails = invalid
videoThumbnails = GenerateVideoThumbnails(videoId)
end if
end if
lines = invalid
contentMetadataViewModel = ObjectUtils.Dig(metadata, ["metadata", "contentMetadataViewModel"])
metadataRows = ObjectUtils.Dig(contentMetadataViewModel, ["metadataRows"])
@@ -1126,7 +1164,7 @@ namespace Innertube
"title": title
"authorId": authorId
"lines": lines
"videoThumbnails": GenerateVideoThumbnails(videoId)
"videoThumbnails": videoThumbnails
}
PushFeedItem(video, context)
@@ -1353,10 +1391,8 @@ namespace Innertube
return TileRendererTypePlaylist(nodeData, context)
else if contentType = "TILE_CONTENT_TYPE_CHANNEL"
' Not implemented yet - https://github.com/iBicha/playlet/issues/724
return invalid
else if contentType = "TILE_CONTENT_TYPE_EDU"
' Not implemented yet - https://github.com/iBicha/playlet/issues/751
return invalid
end if
Warning(`Unknown content type: ${contentType}`, nodeData, context)
@@ -1758,6 +1794,59 @@ namespace Innertube
return invalid
end function
function ParseGridMovieRenderer(nodeData as object, context as object) as object
videoId = nodeData["videoId"]
if not IsString(videoId)
Warning("Invalid videoId in gridMovieRenderer", nodeData, context)
return invalid
end if
title = ParseText(nodeData["title"])
metadata = ParseText(nodeData["metadata"])
author = invalid
authorId = invalid
if IsString(context.currentAuthor) and IsString(context.currentAuthorId)
author = context.currentAuthor
authorId = context.currentAuthorId
end if
lines = invalid
if metadata <> ""
lines = [author, metadata]
end if
lengthText = ParseText(nodeData["lengthText"])
if lengthText = ""
thumbnailOverlays = nodeData["thumbnailOverlays"]
if IsArray(thumbnailOverlays)
for each overlay in thumbnailOverlays
parsedTimeStatusRenderer = ParseThumbnailOverlayTimeStatusRenderer(overlay)
if parsedTimeStatusRenderer <> invalid
lengthText = parsedTimeStatusRenderer.text
if lengthText <> ""
exit for
end if
end if
end for
end if
end if
video = {
"type": "video"
"videoId": videoId
"title": title
"author": author
"authorId": authorId
"videoThumbnails": GenerateVideoThumbnails(videoId)
"lines": lines
"lengthText": lengthText
}
PushFeedItem(video, context)
return invalid
end function
function ParseCompactMovieRenderer(nodeData as object, context as object) as object
videoId = nodeData["videoId"]
if not IsString(videoId)
@@ -1800,6 +1889,10 @@ namespace Innertube
return invalid
end function
function ParseHorizontalMovieListRenderer(nodeData as object, _context as object) as object
return nodeData["items"]
end function
function ParseText(data as dynamic) as string
if IsString(data)
return data
@@ -67,7 +67,11 @@ namespace Innertube
return request
end function
function ParseInnertubePlayerResponse(payload as object, parsedResponse as object, playerRequest as dynamic, cancellation as object) as object
function ParseInnertubePlayerResponse(playerRequest as dynamic, playerResponse as dynamic, parsedResponse as object, cancellation as object) as object
WriteAsciiFile("cachefs:/last_player_response.json", playerResponse.Text())
payload = playerResponse.Json()
error = ParsePlayerResponseForError(payload, playerRequest)
if error <> ""
parsedResponse["error"] = error
+13 -28
View File
@@ -129,37 +129,22 @@ namespace Sentry
end function
function ReplaceRequestId(message as string) as dynamic
reqIdStart = `\nRequestId: `
reqIdPlaceholder = "<REQUEST_ID>"
result = message
replaced = false
searchIndex = 0
while true
requestIdIndex = result.InStr(searchIndex, reqIdStart)
if requestIdIndex = -1
exit while
end if
requestIdRegex = m.requestIdRegex
if requestIdRegex = invalid
requestIdRegex = /RequestId:\s*[0-9]+/
m.requestIdRegex = requestIdRegex
end if
reqIdStartIndex = requestIdIndex + reqIdStart.Len()
newLineIndex = result.InStr(reqIdStartIndex, `\n`)
if newLineIndex = -1
exit while
end if
reqIdEndIndex = newLineIndex - 1
if (reqIdEndIndex <= reqIdStartIndex) or ((reqIdEndIndex - reqIdStartIndex) > 20)
exit while
end if
result = result.Mid(0, reqIdStartIndex) + reqIdPlaceholder + result.Mid(reqIdEndIndex + 1)
replaced = true
searchIndex = reqIdStartIndex + reqIdPlaceholder.Len()
end while
if not replaced
matches = requestIdRegex.MatchAll(message)
if not IsArray(matches) or matches.Count() = 0
return invalid
end if
return result
for each match in matches
fullMatch = match[0]
message = message.Replace(fullMatch, "RequestId: <REQUEST_ID>")
end for
return message
end function
end namespace
@@ -17,8 +17,8 @@ function ExecuteJob() as void
return
end if
DeleteFile("tmp:/last_generated_dash.xml")
DeleteFile("tmp:/last_generated_hls.m3u8")
DeleteFile("cachefs:/last_generated_dash.xml")
DeleteFile("cachefs:/last_generated_hls.m3u8")
if StringUtils.IsNullOrEmpty(contentNode.videoId)
JobError("Can't load video information: videoId is missing")
@@ -147,7 +147,10 @@ function CreateStreamUrls(metadata as object, service as Invidious.InvidiousServ
streamUrls = []
if SupportsDrmDashManifest(metadata)
streamUrls.push(metadata.dashUrl)
dashUrl = UrlUtils.AppendQueryParams(`http://127.0.0.1:${playletServerPort}/api/dash`, {
url: metadata.dashUrl
})
streamUrls.push(dashUrl)
else if SupportsHls(metadata)
metadata.hlsUrl = AddInstanceToUrlIfNeeded(metadata.hlsUrl, instance)
AddHlsUrls(streamUrls, metadata, preferredQuality, backend, proxyVideos, playletServerPort)
@@ -557,29 +557,25 @@ function GetPlayerErrorData(videoId as string, errorInfo as object) as object
end function
function ReportVideoError(errorData as object, url as string) as void
if errorData.body.Instr("DRM exception") <> -1
return
end if
attachments = invalid
if errorData.body.Instr("malformed data") <> -1 or errorData.body.Instr("invalid pathname") <> -1
lastGeneratedDash = ReadAsciiFile("tmp:/last_generated_dash.xml")
if not StringUtils.IsNullOrEmpty(lastGeneratedDash)
attachments = [{
filename: "last_generated_dash.xml"
content_type: "plain/text"
data: lastGeneratedDash
}]
else
lastGeneratedHls = ReadAsciiFile("tmp:/last_generated_hls.m3u8")
if not StringUtils.IsNullOrEmpty(lastGeneratedHls)
attachments = [{
filename: "last_generated_hls.m3u8"
content_type: "plain/text"
data: lastGeneratedHls
}]
end if
end if
lastGeneratedDash = ValidString(ReadAsciiFile("cachefs:/last_generated_dash.xml"))
lastGeneratedHls = ValidString(ReadAsciiFile("cachefs:/last_generated_hls.m3u8"))
lastPlayerResponse = ValidString(ReadAsciiFile("cachefs:/last_player_response.json"))
attachments = [{
filename: "last_generated_dash.xml"
content_type: "plain/text"
data: lastGeneratedDash
}, {
filename: "last_generated_hls.m3u8"
content_type: "plain/text"
data: lastGeneratedHls
}, {
filename: "last_player_response.json"
content_type: "application/json"
data: lastPlayerResponse
}]
end if
LogTelemetryEvent({
@@ -23,25 +23,30 @@ namespace Http
request = context.request
response = context.response
url = request.query.url
if not StringUtils.IsNullOrEmpty(url)
return m.GenerateDashManifestAppendStoryboards(context)
end if
v = request.query.v
local = request.query.local
quality = request.query.quality
if StringUtils.IsNullOrEmpty(v)
response.Default(400, "Missing video id")
WriteAsciiFile("tmp:/last_generated_dash.xml", "400 Missing video id")
WriteAsciiFile("cachefs:/last_generated_dash.xml", "400 Missing video id")
return true
end if
metadata = ObjectUtils.DigUnsafe(m.videoQueueNode, ["player", "content", "metadata"])
if not IsAssociativeArray(metadata)
response.Default(500, "videoQueue.player.content.metadata is invalid")
WriteAsciiFile("tmp:/last_generated_dash.xml", "500 videoQueue.player.content.metadata is invalid")
WriteAsciiFile("cachefs:/last_generated_dash.xml", "500 videoQueue.player.content.metadata is invalid")
return true
end if
if metadata.videoId <> v
response.Default(400, "videoQueue.player.content.metadata.videoId does not match the requested video id")
WriteAsciiFile("tmp:/last_generated_dash.xml", "400 videoQueue.player.content.metadata.videoId does not match the requested video id")
WriteAsciiFile("cachefs:/last_generated_dash.xml", "400 videoQueue.player.content.metadata.videoId does not match the requested video id")
return true
end if
@@ -54,7 +59,7 @@ namespace Http
response.SetBodyDataString(xmlContent)
response.ContentType("application/dash+xml")
WriteAsciiFile("tmp:/last_generated_dash.xml", xmlContent)
WriteAsciiFile("cachefs:/last_generated_dash.xml", xmlContent)
return true
end function
@@ -80,6 +85,46 @@ namespace Http
return qualityFilter
end function
function GenerateDashManifestAppendStoryboards(context as object) as boolean
request = context.request
response = context.response
url = request.query.url
storyboards = ObjectUtils.DigUnsafe(m.videoQueueNode, ["player", "content", "metadata", "storyboards"])
if not IsArray(storyboards) or storyboards.count() = 0
response.Redirect(url)
return true
end if
dashRequest = HttpClient.Get(url)
dashResponse = dashRequest.Await()
if not dashResponse.IsSuccess()
LogError("Failed to fetch DASH manifest from URL", dashResponse.ErrorMessage())
response.Redirect(url)
return true
end if
dashContent = ValidString(dashResponse.Text())
storyboardIndex = dashContent.InStr("</Period>")
if storyboardIndex = -1
response.Redirect(url)
return true
end if
xml = new XmlObject()
manifestObj = new DashManifest("")
manifestObj.generateImageAdaptationSets(xml, storyboards, 100)
storyboardXml = xml.ToXmlString(false)
newDashContent = dashContent.Left(storyboardIndex) + storyboardXml + dashContent.Mid(storyboardIndex)
response.http_code = 200
response.SetBodyDataString(newDashContent)
response.ContentType("application/dash+xml")
return true
end function
end class
end namespace
@@ -35,6 +35,8 @@ namespace Http
if not hlsResponse.IsSuccess()
LogError("Failed to fetch HLS manifest:", hlsResponse.ErrorMessage())
response.Redirect(url)
return true
end if
hlsManifest = hlsResponse.Text()
@@ -58,7 +60,7 @@ namespace Http
response.headers["Server"] = "HTTP server (unknown)"
response.SetBodyDataString(hlsManifest)
WriteAsciiFile("tmp:/last_generated_hls.m3u8", hlsManifest)
WriteAsciiFile("cachefs:/last_generated_hls.m3u8", hlsManifest)
return true
end function
@@ -1,6 +1,7 @@
import "HttpRequestState.bs"
import "pkg:/components/Web/WebServer/Http/HttpConnection.bs"
import "pkg:/components/Web/WebServer/Http/HttpUtils.bs"
import "pkg:/source/utils/ByteArrayUtils.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/MathUtils.bs"
import "pkg:/source/utils/Types.bs"
@@ -207,7 +208,7 @@ namespace Http
return false
end if
m.body_bytes = m.buffer.Slice(m.content_index)
m.body_bytes = ByteArrayUtils.Slice(m.buffer, m.content_index)
m.ready_for_response = true
return true
end function
+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=00000
build_version=00002
ui_resolutions=hd
uri_resolution_autosub=$$RES$$,480p,720p,1080p
@@ -1,3 +1,5 @@
import "pkg:/source/utils/ByteArrayUtils.bs"
namespace Protobuf
class BinaryReader
@@ -79,7 +81,7 @@ namespace Protobuf
if endPosition > m.buffer.Count()
return invalid
end if
value = m.buffer.Slice(m.position, endPosition)
value = ByteArrayUtils.Slice(m.buffer, m.position, endPosition)
m.position += length
return value
end function
+5 -2
View File
@@ -64,8 +64,11 @@ class XmlObject
end if
end function
function ToXmlString() as string
xml = `<?xml version="1.0" encoding="UTF-8"?>\n`
function ToXmlString(header = true as boolean) as string
xml = ""
if header
xml = `<?xml version="1.0" encoding="UTF-8"?>\n`
end if
for each item in m.prolog
if item.type = "comment"
xml += `<!-- ${item.comment} -->\n`
@@ -0,0 +1,65 @@
import "StringUtils.bs"
namespace ByteArrayUtils
function Slice(bytearray as object, start_pos = 0 as dynamic, end_pos = invalid as dynamic) as object
if FindMemberFunction(bytearray, "Slice") <> invalid
start_pos = ValidInt(start_pos)
if end_pos = invalid
return bytearray.Slice(start_pos)
end if
return bytearray.Slice(start_pos, end_pos)
end if
return SliceFallback(bytearray, start_pos, end_pos)
end function
function SliceFallback(bytearray as object, start_pos = 0 as dynamic, end_pos = invalid as dynamic) as object
copy = CreateObject("roByteArray")
arrCount = bytearray.Count()
' default end_pos is array length
if end_pos = invalid
end_pos = arrCount
end if
start_pos = ValidInt(start_pos)
' handle negative start_pos
if start_pos < 0
start_pos = arrCount + start_pos
end if
' handle negative end_pos
if end_pos < 0
end_pos = arrCount + end_pos
end if
' clamp start_pos to bounds
if start_pos < 0
start_pos = 0
else if start_pos > arrCount
start_pos = arrCount
end if
' clamp end_pos to bounds
if end_pos < 0
end_pos = 0
else if end_pos > arrCount
end_pos = arrCount
end if
count = end_pos - start_pos
if count <= 0
return copy
end if
tmp = `tmp:/${StringUtils.RandomId()}.bin`
if not bytearray.WriteFile(tmp, start_pos, count)
DeleteFile(tmp)
return copy
end if
copy.ReadFile(tmp)
DeleteFile(tmp)
return copy
end function
end namespace
@@ -0,0 +1,45 @@
namespace Tests
@suite
class ByteArrayUtilsTests extends Rooibos.BaseTestSuite
protected override function beforeEach()
m.ba = CreateObject("roByteArray")
m.ba.FromHexString("00010203040506070809")
end function
@describe("ByteArrayUtils.Slice and SliceFallback")
@it("slices a byte array correctly")
@params("positive start and end", 2, 5, "020304")
@params("to the end if end is not provided", 7, invalid, "070809")
@params("the whole array if no params provided", invalid, invalid, "00010203040506070809")
@params("with negative start", -4, invalid, "06070809")
@params("with negative end", 0, -3, "00010203040506")
@params("with negative start and negative end", -5, -2, "050607")
@params("returns empty array for start greater than end", 5, 2, "")
@params("returns empty for start out of bounds", 20, invalid, "")
@params("clamps end to array length", 8, 20, "0809")
@params("handles empty slice", 3, 3, "")
function testSlice(description as string, start_pos as dynamic, end_pos as dynamic, expectedHex as string)
resultBa = ByteArrayUtils.Slice(m.ba, start_pos, end_pos)
m.assertEqual(resultBa.ToHexString(), expectedHex, "Slice failed for: " + description)
resultBaFallback = ByteArrayUtils.SliceFallback(m.ba, start_pos, end_pos)
m.assertEqual(resultBaFallback.ToHexString(), expectedHex, "SliceFallback failed for: " + description)
end function
@it("handles empty byte array")
function handles_empty_byte_array()
emptyBa = CreateObject("roByteArray")
resultBa = ByteArrayUtils.Slice(emptyBa, 0, 0)
m.assertEqual(resultBa.ToHexString(), "")
resultBaFallback = ByteArrayUtils.SliceFallback(emptyBa, 0, 0)
m.assertEqual(resultBaFallback.ToHexString(), "")
end function
end class
end namespace
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "playlet-web",
"version": "0.43.0",
"version": "0.43.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "playlet-web",
"version": "0.43.0",
"version": "0.43.2",
"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.0",
"version": "0.43.2",
"type": "module",
"scripts": {
"dev": "vite",