Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d1da36e28 | ||
|
|
c61c8aecc6 | ||
|
|
7a63b26c73 | ||
|
|
0d949b1752 | ||
|
|
33518607c5 | ||
|
|
8a47c02179 | ||
|
|
a1251c065d |
No files matched your search
@@ -5,8 +5,18 @@ 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/),
|
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).
|
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
|
## [0.43.1] - 2025-10-28
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Support for additional nodes parsing
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Trickplay storyboards on DRM videos
|
- Trickplay storyboards on DRM videos
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "playlet",
|
"name": "playlet",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "playlet",
|
"name": "playlet",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rokucommunity/bslint": "^0.8.37",
|
"@rokucommunity/bslint": "^0.8.37",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "playlet",
|
"name": "playlet",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"description": "Unofficial YouTube client for Roku",
|
"description": "Unofficial YouTube client for Roku",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rokucommunity/bslint": "^0.8.37",
|
"@rokucommunity/bslint": "^0.8.37",
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "playlet-app",
|
"name": "playlet-app",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "playlet-app",
|
"name": "playlet-app",
|
||||||
"version": "0.43.1"
|
"version": "0.43.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "playlet-app",
|
"name": "playlet-app",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"description": "Unofficial YouTube client for Roku",
|
"description": "Unofficial YouTube client for Roku",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "node ../tools/rm.js ../build/playlet-app",
|
"prebuild": "node ../tools/rm.js ../build/playlet-app",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ title=Playlet
|
|||||||
# Do not update version manually, it is auto updated from package.json
|
# Do not update version manually, it is auto updated from package.json
|
||||||
major_version=0
|
major_version=0
|
||||||
minor_version=43
|
minor_version=43
|
||||||
build_version=00001
|
build_version=00002
|
||||||
|
|
||||||
ui_resolutions=hd
|
ui_resolutions=hd
|
||||||
uri_resolution_autosub=$$RES$$,480p,720p,1080p
|
uri_resolution_autosub=$$RES$$,480p,720p,1080p
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "playlet-lib",
|
"name": "playlet-lib",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "playlet-lib",
|
"name": "playlet-lib",
|
||||||
"version": "0.43.1"
|
"version": "0.43.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "playlet-lib",
|
"name": "playlet-lib",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"description": "Unofficial YouTube client for Roku",
|
"description": "Unofficial YouTube client for Roku",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prebuild": "node ../tools/rm.js ../build/playlet-lib",
|
"prebuild": "node ../tools/rm.js ../build/playlet-lib",
|
||||||
|
|||||||
@@ -93,9 +93,10 @@ namespace Innertube
|
|||||||
"tvSurfaceContentContinuation": ParseTvSurfaceContentContinuation
|
"tvSurfaceContentContinuation": ParseTvSurfaceContentContinuation
|
||||||
"gridButtonRenderer": ParseGridButtonRenderer
|
"gridButtonRenderer": ParseGridButtonRenderer
|
||||||
"movieRenderer": ParseMovieRenderer
|
"movieRenderer": ParseMovieRenderer
|
||||||
|
"gridMovieRenderer": ParseGridMovieRenderer
|
||||||
"compactMovieRenderer": ParseCompactMovieRenderer
|
"compactMovieRenderer": ParseCompactMovieRenderer
|
||||||
|
"horizontalMovieListRenderer": ParseHorizontalMovieListRenderer
|
||||||
' Movies and shows are partially supported, but these renderers are not yet implemented.
|
' Movies and shows are partially supported, but these renderers are not yet implemented.
|
||||||
' "horizontalMovieListRenderer": ParseNotImplemented
|
|
||||||
' "gridMovieRenderer": ParseNotImplemented
|
' "gridMovieRenderer": ParseNotImplemented
|
||||||
' "gridShowRenderer": ParseNotImplemented
|
' "gridShowRenderer": ParseNotImplemented
|
||||||
' "playlistShowMetadataRenderer": ParseNotImplemented
|
' "playlistShowMetadataRenderer": ParseNotImplemented
|
||||||
@@ -103,7 +104,7 @@ namespace Innertube
|
|||||||
' TODO:P2 handle navigateAction - which are usually a redirect
|
' 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
|
' TODO:P2 radioRenderer seems like a Mix https://github.com/iBicha/playlet/issues/709
|
||||||
' "radioRenderer": ParseNotImplemented
|
"radioRenderer": ParseRadioRenderer
|
||||||
' "compactRadioRenderer": ParseNotImplemented
|
' "compactRadioRenderer": ParseNotImplemented
|
||||||
' TODO:P2 A carousel of videos, found on the home tab of a channel.
|
' TODO:P2 A carousel of videos, found on the home tab of a channel.
|
||||||
' Should probably be parsed.
|
' Should probably be parsed.
|
||||||
@@ -997,6 +998,33 @@ namespace Innertube
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
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
|
function ParseGridShelfViewModel(nodeData as object, _context as object) as object
|
||||||
return nodeData["contents"]
|
return nodeData["contents"]
|
||||||
end function
|
end function
|
||||||
@@ -1006,8 +1034,6 @@ namespace Innertube
|
|||||||
if contentType = "LOCKUP_CONTENT_TYPE_VIDEO"
|
if contentType = "LOCKUP_CONTENT_TYPE_VIDEO"
|
||||||
return LockupViewModelTypeVideo(nodeData, context)
|
return LockupViewModelTypeVideo(nodeData, context)
|
||||||
else if contentType = "LOCKUP_CONTENT_TYPE_SHORT"
|
else if contentType = "LOCKUP_CONTENT_TYPE_SHORT"
|
||||||
' Additional capture for LOCKUP_CONTENT_TYPE_SHORT
|
|
||||||
Warning(`Unknown content type: ${contentType}`, nodeData, context)
|
|
||||||
return LockupViewModelTypeShort(nodeData, context)
|
return LockupViewModelTypeShort(nodeData, context)
|
||||||
else if contentType = "LOCKUP_CONTENT_TYPE_PLAYLIST"
|
else if contentType = "LOCKUP_CONTENT_TYPE_PLAYLIST"
|
||||||
return LockupViewModelTypePlaylist(nodeData, context)
|
return LockupViewModelTypePlaylist(nodeData, context)
|
||||||
@@ -1102,6 +1128,16 @@ namespace Innertube
|
|||||||
title = ObjectUtils.Dig(metadata, ["title", "content"])
|
title = ObjectUtils.Dig(metadata, ["title", "content"])
|
||||||
authorId = ObjectUtils.Dig(metadata, ["image", "decoratedAvatarViewModel", "rendererContext", "commandContext", "onTap", "innertubeCommand", "browseEndpoint", "browseId"])
|
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
|
lines = invalid
|
||||||
contentMetadataViewModel = ObjectUtils.Dig(metadata, ["metadata", "contentMetadataViewModel"])
|
contentMetadataViewModel = ObjectUtils.Dig(metadata, ["metadata", "contentMetadataViewModel"])
|
||||||
metadataRows = ObjectUtils.Dig(contentMetadataViewModel, ["metadataRows"])
|
metadataRows = ObjectUtils.Dig(contentMetadataViewModel, ["metadataRows"])
|
||||||
@@ -1128,7 +1164,7 @@ namespace Innertube
|
|||||||
"title": title
|
"title": title
|
||||||
"authorId": authorId
|
"authorId": authorId
|
||||||
"lines": lines
|
"lines": lines
|
||||||
"videoThumbnails": GenerateVideoThumbnails(videoId)
|
"videoThumbnails": videoThumbnails
|
||||||
}
|
}
|
||||||
|
|
||||||
PushFeedItem(video, context)
|
PushFeedItem(video, context)
|
||||||
@@ -1355,10 +1391,8 @@ namespace Innertube
|
|||||||
return TileRendererTypePlaylist(nodeData, context)
|
return TileRendererTypePlaylist(nodeData, context)
|
||||||
else if contentType = "TILE_CONTENT_TYPE_CHANNEL"
|
else if contentType = "TILE_CONTENT_TYPE_CHANNEL"
|
||||||
' Not implemented yet - https://github.com/iBicha/playlet/issues/724
|
' Not implemented yet - https://github.com/iBicha/playlet/issues/724
|
||||||
return invalid
|
|
||||||
else if contentType = "TILE_CONTENT_TYPE_EDU"
|
else if contentType = "TILE_CONTENT_TYPE_EDU"
|
||||||
' Not implemented yet - https://github.com/iBicha/playlet/issues/751
|
' Not implemented yet - https://github.com/iBicha/playlet/issues/751
|
||||||
return invalid
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
Warning(`Unknown content type: ${contentType}`, nodeData, context)
|
Warning(`Unknown content type: ${contentType}`, nodeData, context)
|
||||||
@@ -1760,6 +1794,59 @@ namespace Innertube
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
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
|
function ParseCompactMovieRenderer(nodeData as object, context as object) as object
|
||||||
videoId = nodeData["videoId"]
|
videoId = nodeData["videoId"]
|
||||||
if not IsString(videoId)
|
if not IsString(videoId)
|
||||||
@@ -1802,6 +1889,10 @@ namespace Innertube
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function ParseHorizontalMovieListRenderer(nodeData as object, _context as object) as object
|
||||||
|
return nodeData["items"]
|
||||||
|
end function
|
||||||
|
|
||||||
function ParseText(data as dynamic) as string
|
function ParseText(data as dynamic) as string
|
||||||
if IsString(data)
|
if IsString(data)
|
||||||
return data
|
return data
|
||||||
|
|||||||
@@ -129,37 +129,22 @@ namespace Sentry
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function ReplaceRequestId(message as string) as dynamic
|
function ReplaceRequestId(message as string) as dynamic
|
||||||
reqIdStart = `\nRequestId: `
|
requestIdRegex = m.requestIdRegex
|
||||||
reqIdPlaceholder = "<REQUEST_ID>"
|
if requestIdRegex = invalid
|
||||||
result = message
|
requestIdRegex = /RequestId:\s*[0-9]+/
|
||||||
replaced = false
|
m.requestIdRegex = requestIdRegex
|
||||||
searchIndex = 0
|
end if
|
||||||
while true
|
|
||||||
requestIdIndex = result.InStr(searchIndex, reqIdStart)
|
|
||||||
if requestIdIndex = -1
|
|
||||||
exit while
|
|
||||||
end if
|
|
||||||
|
|
||||||
reqIdStartIndex = requestIdIndex + reqIdStart.Len()
|
matches = requestIdRegex.MatchAll(message)
|
||||||
newLineIndex = result.InStr(reqIdStartIndex, `\n`)
|
if not IsArray(matches) or matches.Count() = 0
|
||||||
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
|
|
||||||
return invalid
|
return invalid
|
||||||
end if
|
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 function
|
||||||
end namespace
|
end namespace
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import "HttpRequestState.bs"
|
import "HttpRequestState.bs"
|
||||||
import "pkg:/components/Web/WebServer/Http/HttpConnection.bs"
|
import "pkg:/components/Web/WebServer/Http/HttpConnection.bs"
|
||||||
import "pkg:/components/Web/WebServer/Http/HttpUtils.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/Logging.bs"
|
||||||
import "pkg:/source/utils/MathUtils.bs"
|
import "pkg:/source/utils/MathUtils.bs"
|
||||||
import "pkg:/source/utils/Types.bs"
|
import "pkg:/source/utils/Types.bs"
|
||||||
@@ -207,7 +208,7 @@ namespace Http
|
|||||||
return false
|
return false
|
||||||
end if
|
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
|
m.ready_for_response = true
|
||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ title=PlayletLib
|
|||||||
# Do not update version manually, it is auto updated from package.json
|
# Do not update version manually, it is auto updated from package.json
|
||||||
major_version=0
|
major_version=0
|
||||||
minor_version=43
|
minor_version=43
|
||||||
build_version=00001
|
build_version=00002
|
||||||
|
|
||||||
ui_resolutions=hd
|
ui_resolutions=hd
|
||||||
uri_resolution_autosub=$$RES$$,480p,720p,1080p
|
uri_resolution_autosub=$$RES$$,480p,720p,1080p
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import "pkg:/source/utils/ByteArrayUtils.bs"
|
||||||
|
|
||||||
namespace Protobuf
|
namespace Protobuf
|
||||||
|
|
||||||
class BinaryReader
|
class BinaryReader
|
||||||
@@ -79,7 +81,7 @@ namespace Protobuf
|
|||||||
if endPosition > m.buffer.Count()
|
if endPosition > m.buffer.Count()
|
||||||
return invalid
|
return invalid
|
||||||
end if
|
end if
|
||||||
value = m.buffer.Slice(m.position, endPosition)
|
value = ByteArrayUtils.Slice(m.buffer, m.position, endPosition)
|
||||||
m.position += length
|
m.position += length
|
||||||
return value
|
return value
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -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
|
||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "playlet-web",
|
"name": "playlet-web",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "playlet-web",
|
"name": "playlet-web",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
||||||
"@tailwindcss/postcss": "^4.1.16",
|
"@tailwindcss/postcss": "^4.1.16",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "playlet-web",
|
"name": "playlet-web",
|
||||||
"version": "0.43.1",
|
"version": "0.43.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
Reference in new issue
Block a user