[Part 2] Innertube (#513)

* Parse author in videoRenderer

* Parse more fields

* Parse live badge

* playlist video count

* Parse more things

* parse playlists and albums

* More parsing work

* announcement and changelog

* Lint fix

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
Brahim Hadricheandgithub-action linter authored and GitHub committed 2024-12-22 16:04:36 -05:00
1 parent 9f3eee900f
commit bed8223e76
16 files changed
+444 -37

No files matched your search

+2 -2
View File
@@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Built-in Playlet backend, which supports channels, playlists, and search - Built-in Playlet backend, which supports channels, playlists, and search
- This backend is not finished, and provides the bare minimum to watch videos. - This backend is experimental, and has a few missing features.
- More features to come. - To use it, set the Invidious instance to an empty string.
### Fixed ### Fixed
@@ -66,7 +66,13 @@ function OnContentSet() as void
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. ' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
m.authorLabel.text = content._author m.authorLabel.text = content._author
m.subCountLabel.text = content.subCountText
subCountText = content.authorSubTitle
if StringUtils.IsNullOrEmpty(subCountText)
subCountText = content.subCountText
end if
m.subCountLabel.text = subCountText
m.banner.uri = content.banner m.banner.uri = content.banner
if StringUtils.IsNullOrEmpty(content.thumbnail) if StringUtils.IsNullOrEmpty(content.thumbnail)
m.thumbnail.uri = "" m.thumbnail.uri = ""
@@ -10,6 +10,7 @@
<!-- NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation --> <!-- NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation -->
<field id="_author" type="string" /> <field id="_author" type="string" />
<field id="authorId" type="string" /> <field id="authorId" type="string" />
<field id="authorSubTitle" type="string" />
<field id="banner" type="string" /> <field id="banner" type="string" />
<field id="channelHandle" type="string" /> <field id="channelHandle" type="string" />
<field id="description" type="string" /> <field id="description" type="string" />
@@ -39,5 +39,6 @@
<field id="videoCountText" type="string" /> <field id="videoCountText" type="string" />
<field id="viewCount" type="integer" /> <field id="viewCount" type="integer" />
<field id="viewCountText" type="string" /> <field id="viewCountText" type="string" />
<field id="statsText" type="string" />
</interface> </interface>
</component> </component>
+23
View File
@@ -2,6 +2,7 @@ import "pkg:/components/EcpArgs.bs"
import "pkg:/components/parts/AutoBind/AutoBind.part.bs" import "pkg:/components/parts/AutoBind/AutoBind.part.bs"
import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs" import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs"
import "pkg:/source/utils/LoadingScreen.bs" import "pkg:/source/utils/LoadingScreen.bs"
import "pkg:/source/utils/Locale.bs"
function Init() function Init()
m.scene = m.top.getScene() m.scene = m.top.getScene()
@@ -18,6 +19,7 @@ function MainSceneContainerChanged()
InitEcpArgs() InitEcpArgs()
m.scene.signalBeacon("AppLaunchComplete") m.scene.signalBeacon("AppLaunchComplete")
CopyLoadingMessagesToCache() CopyLoadingMessagesToCache()
ShowAnnouncement()
end function end function
function StartWebServer() function StartWebServer()
@@ -30,3 +32,24 @@ function StartWebServer()
m.dialServer = m.top.findNode("DialServer") m.dialServer = m.top.findNode("DialServer")
m.dialServer@.StartServer() m.dialServer@.StartServer()
end function end function
function ShowAnnouncement()
title = "Announcement - Playlet backend"
message = [
"An experimental built-in backend has been added to Playlet."
"This allows you to access YouTube content without the need for an Invidious instance."
"To use it, go to the Settings > Invidious > Instance and set the field to empty (Edit, and delete the url)."
"Please note that it's missing some features and may not work as expected."
"Thank you for using Playlet!"
]
buttons = [Tr(Locale.Buttons.OK)]
dialog = CreateObject("roSGNode", "SimpleDialog")
dialog.title = title
dialog.message = message
dialog.buttons = buttons
deviceInfo = CreateObject("roDeviceInfo")
displaySize = deviceInfo.GetDisplaySize()
dialog.width = displaySize.w - 180
m.top.getScene().dialog = dialog
end function
@@ -2,6 +2,7 @@
'import "pkg:/components/parts/AutoBind/AutoBind.part.bs" 'import "pkg:/components/parts/AutoBind/AutoBind.part.bs"
'import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs" 'import "pkg:/components/parts/AutoBind/OnNodeReadyNoOp.bs"
'import "pkg:/source/utils/LoadingScreen.bs" 'import "pkg:/source/utils/LoadingScreen.bs"
'import "pkg:/source/utils/Locale.bs"
function Init() function Init()
InitializeBindings() ' auto-generated! InitializeBindings() ' auto-generated!
@@ -19,6 +20,7 @@ function MainSceneContainerChanged()
InitEcpArgs() InitEcpArgs()
m.scene.signalBeacon("AppLaunchComplete") m.scene.signalBeacon("AppLaunchComplete")
CopyLoadingMessagesToCache() CopyLoadingMessagesToCache()
ShowAnnouncement()
end function end function
function StartWebServer() function StartWebServer()
@@ -29,4 +31,26 @@ function StartWebServer()
m.dialServer = m.top.findNode("DialServer") m.dialServer = m.top.findNode("DialServer")
m.dialServer.callfunc("StartServer", invalid) m.dialServer.callfunc("StartServer", invalid)
end function end function
function ShowAnnouncement()
title = "Announcement - Playlet backend"
message = [
"An experimental built-in backend has been added to Playlet."
"This allows you to access YouTube content without the need for an Invidious instance."
"To use it, go to the Settings > Invidious > Instance and set the field to empty (Edit, and delete the url)."
"Please note that it's missing some features and may not work as expected."
"Thank you for using Playlet!"
]
buttons = [
Tr("OK")
]
dialog = CreateObject("roSGNode", "SimpleDialog")
dialog.title = title
dialog.message = message
dialog.buttons = buttons
deviceInfo = CreateObject("roDeviceInfo")
displaySize = deviceInfo.GetDisplaySize()
dialog.width = displaySize.w - 180
m.top.getScene().dialog = dialog
end function
'//# sourceMappingURL=./MainScene.brs.map '//# sourceMappingURL=./MainScene.brs.map
@@ -46,8 +46,13 @@ function OnContentSet() as void
if content.playlistId.StartsWith("RD") if content.playlistId.StartsWith("RD")
m.subtitleLabel.text = "" m.subtitleLabel.text = ""
else else
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. statsText = content.statsText
m.subtitleLabel.text = `${content._author} • ${content.videoCountText} • ${content.viewCountText}` if statsText.Len() > 0
m.subtitleLabel.text = statsText
else
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
m.subtitleLabel.text = `${content._author} • ${content.videoCountText} • ${content.viewCountText}`
end if
end if end if
m.updatedLabel.text = content.updatedText m.updatedLabel.text = content.updatedText
m.descriptionLabel.text = content.description m.descriptionLabel.text = content.description
@@ -47,6 +47,7 @@ namespace Innertube
"playlistVideoRenderer": ParsePlaylistVideoRenderer "playlistVideoRenderer": ParsePlaylistVideoRenderer
"channelRenderer": ParseChannelRenderer "channelRenderer": ParseChannelRenderer
"gridChannelRenderer": ParseGridChannelRenderer "gridChannelRenderer": ParseGridChannelRenderer
"playlistRenderer": ParsePlaylistRenderer
"lockupViewModel": ParseLockupViewModel "lockupViewModel": ParseLockupViewModel
"shortsLockupViewModel": ParseShortsLockupViewModel "shortsLockupViewModel": ParseShortsLockupViewModel
"tvBrowseRenderer": ParseTvBrowseRenderer "tvBrowseRenderer": ParseTvBrowseRenderer
@@ -135,6 +136,32 @@ namespace Innertube
return invalid return invalid
end if end if
author = invalid
authorId = invalid
authorPossibleNodes = ["ownerText", "shortBylineText", "longBylineText"]
for each authorPossibleNode in authorPossibleNodes
node = nodeData[authorPossibleNode]
author = ParseText(node)
authorId = ObjectUtils.Dig(node, ["runs", 0, "navigationEndpoint", "browseEndpoint", "browseId"])
if author <> "" and authorId <> invalid
exit for
end if
end for
if StringUtils.IsNullOrEmpty(author) and StringUtils.IsNullOrEmpty(authorId)
if IsString(context.currentAuthor) and IsString(context.currentAuthorId)
author = context.currentAuthor
authorId = context.currentAuthorId
end if
end if
viewCountText = ParseText(nodeData["shortViewCountText"])
if viewCountText = ""
viewCountText = ParseText(nodeData["viewCountText"])
end if
publishedText = ParseText(nodeData["publishedTimeText"])
lengthText = ParseText(nodeData["lengthText"])
if context.generateVideoThumbnails = true if context.generateVideoThumbnails = true
videoThumbnails = GenerateVideoThumbnails(videoId) videoThumbnails = GenerateVideoThumbnails(videoId)
else else
@@ -144,13 +171,51 @@ namespace Innertube
end if end if
end if end if
liveNow = ValidString(ObjectUtils.Dig(nodeData, ["badges", 0, "metadataBadgeRenderer", "icon", "iconType"])) = "LIVE"
if not liveNow
thumbnailOverlays = nodeData["thumbnailOverlays"]
if IsArray(thumbnailOverlays)
for each overlay in thumbnailOverlays
if ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "LIVE"
liveNow = true
exit for
end if
end for
end if
end if
isUpcoming = false
premiereTimestamp = ObjectUtils.Dig(nodeData, ["upcomingEventData", "startTime"])
if IsString(premiereTimestamp)
premiereTimestamp = premiereTimestamp.ToInt()
isUpcoming = true
end if
video = { video = {
"type": "video" "type": "video"
"videoId": videoId "videoId": videoId
"author": author
"authorId": authorId
"title": ParseText(nodeData["title"]) "title": ParseText(nodeData["title"])
"videoThumbnails": videoThumbnails "videoThumbnails": videoThumbnails
"viewCountText": viewCountText
"publishedText": publishedText
"lengthText": lengthText
"liveNow": liveNow
} }
if author <> ""
video["author"] = author
end if
if authorId <> invalid
video["authorId"] = authorId
end if
if isUpcoming
video["isUpcoming"] = true
video["premiereTimestamp"] = premiereTimestamp
end if
PushFeedItem(video, context) PushFeedItem(video, context)
return invalid return invalid
end function end function
@@ -162,6 +227,44 @@ namespace Innertube
return invalid return invalid
end if end if
author = invalid
authorId = invalid
authorPossibleNodes = ["ownerText", "shortBylineText", "longBylineText"]
for each authorPossibleNode in authorPossibleNodes
node = nodeData[authorPossibleNode]
author = ParseText(node)
authorId = ObjectUtils.Dig(node, ["runs", 0, "navigationEndpoint", "browseEndpoint", "browseId"])
if author <> "" and authorId <> invalid
exit for
end if
end for
if StringUtils.IsNullOrEmpty(author) and StringUtils.IsNullOrEmpty(authorId)
if IsString(context.currentAuthor) and IsString(context.currentAuthorId)
author = context.currentAuthor
authorId = context.currentAuthorId
end if
end if
viewCountText = ParseText(nodeData["shortViewCountText"])
if viewCountText = ""
viewCountText = ParseText(nodeData["viewCountText"])
end if
publishedText = ParseText(nodeData["publishedTimeText"])
lengthText = ParseText(nodeData["lengthText"])
if lengthText = ""
thumbnailOverlays = nodeData["thumbnailOverlays"]
if IsArray(thumbnailOverlays)
for each overlay in thumbnailOverlays
lengthText = ParseText(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "text"]))
if lengthText <> ""
exit for
end if
end for
end if
end if
if context.generateVideoThumbnails = true if context.generateVideoThumbnails = true
videoThumbnails = GenerateVideoThumbnails(videoId) videoThumbnails = GenerateVideoThumbnails(videoId)
else else
@@ -171,13 +274,30 @@ namespace Innertube
end if end if
end if end if
isUpcoming = false
premiereTimestamp = ObjectUtils.Dig(nodeData, ["upcomingEventData", "startTime"])
if IsString(premiereTimestamp)
premiereTimestamp = premiereTimestamp.ToInt()
isUpcoming = true
end if
video = { video = {
"type": "video" "type": "video"
"videoId": videoId "videoId": videoId
"author": author
"authorId": authorId
"title": ParseText(nodeData["title"]) "title": ParseText(nodeData["title"])
"videoThumbnails": videoThumbnails "videoThumbnails": videoThumbnails
"publishedText": publishedText
"viewCountText": viewCountText
"lengthText": lengthText
} }
if isUpcoming
video["isUpcoming"] = true
video["premiereTimestamp"] = premiereTimestamp
end if
PushFeedItem(video, context) PushFeedItem(video, context)
return invalid return invalid
end function end function
@@ -189,11 +309,22 @@ namespace Innertube
return invalid return invalid
end if end if
author = invalid
authorId = invalid
if IsString(context.currentAuthor) and IsString(context.currentAuthorId)
author = context.currentAuthor
authorId = context.currentAuthorId
end if
video = { video = {
"type": "video" "type": "video"
"videoId": videoId "videoId": videoId
"author": author
"authorId": authorId
"title": ParseText(nodeData["title"]) "title": ParseText(nodeData["title"])
"videoThumbnails": GenerateVideoThumbnails(videoId) "videoThumbnails": GenerateVideoThumbnails(videoId)
"viewCountText": ParseText(nodeData["viewCountText"])
"publishedText": ParseText(nodeData["publishedTimeText"])
} }
PushFeedItem(video, context) PushFeedItem(video, context)
@@ -207,6 +338,21 @@ namespace Innertube
return invalid return invalid
end if end if
lengthText = ParseText(nodeData["lengthText"])
lengthSeconds = ValidString(nodeData["lengthSeconds"]).ToInt()
author = invalid
authorId = invalid
authorPossibleNodes = ["shortBylineText", "ownerText", "longBylineText"]
for each authorPossibleNode in authorPossibleNodes
node = nodeData[authorPossibleNode]
author = ParseText(node)
authorId = ObjectUtils.Dig(node, ["runs", 0, "navigationEndpoint", "browseEndpoint", "browseId"])
if author <> "" and authorId <> invalid
exit for
end if
end for
if context.generateVideoThumbnails = true if context.generateVideoThumbnails = true
videoThumbnails = GenerateVideoThumbnails(videoId) videoThumbnails = GenerateVideoThumbnails(videoId)
else else
@@ -219,9 +365,13 @@ namespace Innertube
video = { video = {
"type": "video" "type": "video"
"videoId": videoId "videoId": videoId
"author": author
"authorId": authorId
"title": ParseText(nodeData["title"]) "title": ParseText(nodeData["title"])
"videoThumbnails": videoThumbnails "videoThumbnails": videoThumbnails
"index": ParseText(nodeData["index"]).ToInt() "index": ParseText(nodeData["index"]).ToInt()
"lengthText": lengthText
"lengthSeconds": lengthSeconds
} }
PushFeedItem(video, context) PushFeedItem(video, context)
@@ -240,6 +390,8 @@ namespace Innertube
"authorId": channelId "authorId": channelId
"author": ParseText(nodeData["title"]) "author": ParseText(nodeData["title"])
"authorThumbnails": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"]) "authorThumbnails": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
"subCountText": ParseText(nodeData["subscriberCountText"])
"videoCountText": ParseText(nodeData["videoCountText"])
} }
PushFeedItem(channel, context) PushFeedItem(channel, context)
@@ -258,21 +410,75 @@ namespace Innertube
"authorId": channelId "authorId": channelId
"author": ParseText(nodeData["title"]) "author": ParseText(nodeData["title"])
"authorThumbnails": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"]) "authorThumbnails": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
"subCountText": ParseText(nodeData["subscriberCountText"])
"videoCountText": ParseText(nodeData["videoCountText"])
} }
PushFeedItem(channel, context) PushFeedItem(channel, context)
return invalid return invalid
end function end function
function ParsePlaylistRenderer(nodeData as object, context as object) as object
playlistId = nodeData["playlistId"]
if not IsString(playlistId)
LogWarn("Invalid playlist ID", nodeData)
return invalid
end if
author = invalid
authorId = invalid
authorPossibleNodes = ["shortBylineText", "ownerText", "longBylineText"]
for each authorPossibleNode in authorPossibleNodes
node = nodeData[authorPossibleNode]
author = ParseText(node)
authorId = ObjectUtils.Dig(node, ["runs", 0, "navigationEndpoint", "browseEndpoint", "browseId"])
if author <> "" and authorId <> invalid
exit for
end if
end for
videoCountText = ""
thumbnailOverlays = nodeData["thumbnailOverlays"]
if IsArray(thumbnailOverlays)
for each overlay in thumbnailOverlays
videoCountText = ParseText(ObjectUtils.Dig(overlay, ["thumbnailOverlayBottomPanelRenderer", "text"]))
if videoCountText <> ""
exit for
end if
end for
end if
if videoCountText = ""
videoCountText = ParseText(nodeData["videoCountText"])
end if
videoCount = ParseText(nodeData["videoCount"]).ToInt()
playlist = {
"type": "playlist"
"playlistId": playlistId
"title": ParseText(nodeData["title"])
"playlistThumbnail": ObjectUtils.Dig(nodeData, ["thumbnails", 0, "thumbnails", 0, "url"])
"author": author
"authorId": authorId
"videoCount": videoCount
"videoCountText": videoCountText
}
PushFeedItem(playlist, context)
return invalid
end function
function ParseLockupViewModel(nodeData as object, context as object) as object function ParseLockupViewModel(nodeData as object, context as object) as object
contentType = ValidString(nodeData["contentType"]) contentType = ValidString(nodeData["contentType"])
if contentType = "LOCKUP_CONTENT_TYPE_PLAYLIST" if contentType = "LOCKUP_CONTENT_TYPE_PLAYLIST"
return LockupViewModelTypePlaylist(nodeData, context) return LockupViewModelTypePlaylist(nodeData, context)
else if contentType = "LOCKUP_CONTENT_TYPE_PODCAST" else if contentType = "LOCKUP_CONTENT_TYPE_PODCAST"
return LockupViewModelTypePodcast(nodeData, context) return LockupViewModelTypePodcast(nodeData, context)
else if contentType = "LOCKUP_CONTENT_TYPE_ALBUM"
return LockupViewModelTypeAlbum(nodeData, context)
end if end if
LogWarn("Unknown content type:", nodeData) LogWarn("Unknown content type:", contentType, `\n`, nodeData)
return invalid return invalid
end function end function
@@ -286,13 +492,31 @@ namespace Innertube
metadata = ObjectUtils.Dig(nodeData, ["metadata", "lockupMetadataViewModel"]) metadata = ObjectUtils.Dig(nodeData, ["metadata", "lockupMetadataViewModel"])
title = ObjectUtils.Dig(metadata, ["title", "content"]) title = ObjectUtils.Dig(metadata, ["title", "content"])
thumbnail = ObjectUtils.Dig(nodeData, ["contentImage", "collectionThumbnailViewModel", "primaryThumbnail", "thumbnailViewModel", "image", "sources", 0, "url"]) thumbnailViewModel = ObjectUtils.Dig(nodeData, ["contentImage", "collectionThumbnailViewModel", "primaryThumbnail", "thumbnailViewModel"])
thumbnail = ObjectUtils.Dig(thumbnailViewModel, ["image", "sources", 0, "url"])
videoCountText = ObjectUtils.Dig(thumbnailViewModel, ["overlays", 0, "thumbnailOverlayBadgeViewModel", "thumbnailBadges", 0, "thumbnailBadgeViewModel", "text"])
author = invalid
authorId = invalid
maybeAuthorNode = ObjectUtils.Dig(nodeData, ["metadata", "lockupMetadataViewModel", "metadata", "contentMetadataViewModel", "metadataRows", 0, "metadataParts", 0, "text"])
maybeAuthorId = ObjectUtils.Dig(maybeAuthorNode, ["commandRuns", 0, "onTap", "innertubeCommand", "browseEndpoint", "browseId"])
if IsString(maybeAuthorId) and maybeAuthorId.StartsWith("UC")
authorId = maybeAuthorId
author = ValidString(maybeAuthorNode["content"])
else if IsString(context.currentAuthor) and IsString(context.currentAuthorId)
author = context.currentAuthor
authorId = context.currentAuthorId
end if
playlist = { playlist = {
"type": "playlist" "type": "playlist"
"playlistId": playlistId "playlistId": playlistId
"title": title "title": title
"author": author
"authorId": authorId
"playlistThumbnail": thumbnail "playlistThumbnail": thumbnail
"videoCountText": videoCountText
} }
PushFeedItem(playlist, context) PushFeedItem(playlist, context)
@@ -309,13 +533,60 @@ namespace Innertube
metadata = ObjectUtils.Dig(nodeData, ["metadata", "lockupMetadataViewModel"]) metadata = ObjectUtils.Dig(nodeData, ["metadata", "lockupMetadataViewModel"])
title = ObjectUtils.Dig(metadata, ["title", "content"]) title = ObjectUtils.Dig(metadata, ["title", "content"])
thumbnail = ObjectUtils.Dig(nodeData, ["contentImage", "collectionThumbnailViewModel", "primaryThumbnail", "thumbnailViewModel", "image", "sources", 0, "url"]) thumbnailViewModel = ObjectUtils.Dig(nodeData, ["contentImage", "collectionThumbnailViewModel", "primaryThumbnail", "thumbnailViewModel"])
thumbnail = ObjectUtils.Dig(thumbnailViewModel, ["image", "sources", 0, "url"])
videoCountText = ObjectUtils.Dig(thumbnailViewModel, ["overlays", 0, "thumbnailOverlayBadgeViewModel", "thumbnailBadges", 0, "thumbnailBadgeViewModel", "text"])
author = invalid
authorId = invalid
if IsString(context.currentAuthor) and IsString(context.currentAuthorId)
author = context.currentAuthor
authorId = context.currentAuthorId
end if
playlist = { playlist = {
"type": "playlist" "type": "playlist"
"playlistId": playlistId "playlistId": playlistId
"title": title "title": title
"author": author
"authorId": authorId
"playlistThumbnail": thumbnail "playlistThumbnail": thumbnail
"videoCountText": videoCountText
}
PushFeedItem(playlist, context)
return invalid
end function
function LockupViewModelTypeAlbum(nodeData as object, context as object) as object
playlistId = nodeData["contentId"]
if not IsString(playlistId)
LogWarn("Invalid playlist ID", nodeData)
return invalid
end if
metadata = ObjectUtils.Dig(nodeData, ["metadata", "lockupMetadataViewModel"])
title = ObjectUtils.Dig(metadata, ["title", "content"])
thumbnailViewModel = ObjectUtils.Dig(nodeData, ["contentImage", "collectionThumbnailViewModel", "primaryThumbnail", "thumbnailViewModel"])
thumbnail = ObjectUtils.Dig(thumbnailViewModel, ["image", "sources", 0, "url"])
videoCountText = ObjectUtils.Dig(thumbnailViewModel, ["overlays", 0, "thumbnailOverlayBadgeViewModel", "thumbnailBadges", 0, "thumbnailBadgeViewModel", "text"])
author = invalid
authorId = invalid
if IsString(context.currentAuthor) and IsString(context.currentAuthorId)
author = context.currentAuthor
authorId = context.currentAuthorId
end if
playlist = {
"type": "playlist"
"playlistId": playlistId
"title": title
"author": author
"authorId": authorId
"playlistThumbnail": thumbnail
"videoCountText": videoCountText
} }
PushFeedItem(playlist, context) PushFeedItem(playlist, context)
@@ -338,11 +609,20 @@ namespace Innertube
end if end if
end if end if
author = invalid
authorId = invalid
if IsString(context.currentAuthor) and IsString(context.currentAuthorId)
author = context.currentAuthor
authorId = context.currentAuthorId
end if
video = { video = {
"type": "video" "type": "video"
"videoId": videoId "videoId": videoId
"author": author
"authorId": authorId
"title": ObjectUtils.Dig(nodeData, ["overlayMetadata", "primaryText", "content"]) "title": ObjectUtils.Dig(nodeData, ["overlayMetadata", "primaryText", "content"])
"viewCountText": ObjectUtils.Dig(nodeData, ["overlayMetadata", "secondaryText", "content"])
"videoThumbnails": videoThumbnails "videoThumbnails": videoThumbnails
} }
@@ -375,7 +655,7 @@ namespace Innertube
return TileRendererTypePlaylist(nodeData, context) return TileRendererTypePlaylist(nodeData, context)
end if end if
LogWarn("Unknown content type:", nodeData) LogWarn("Unknown content type:", contentType, `\n`, nodeData)
return invalid return invalid
end function end function
@@ -4,7 +4,7 @@ import "pkg:/source/utils/StringUtils.bs"
namespace Innertube namespace Innertube
function ParseResponse(responseData as object) as object function ParseResponse(responseData as object, context = invalid as object) as object
if responseData = invalid if responseData = invalid
return [] return []
end if end if
@@ -14,7 +14,11 @@ namespace Innertube
return [] return []
end if end if
context = { if context = invalid
context = {}
end if
context.Append({
directives: Innertube.GetParsingDirectives() directives: Innertube.GetParsingDirectives()
feeds: [] feeds: []
@@ -23,7 +27,7 @@ namespace Innertube
items: [] items: []
} }
generateVideoThumbnails: true generateVideoThumbnails: true
} })
Innertube.ParseNode(data, context) Innertube.ParseNode(data, context)
@@ -46,7 +50,8 @@ namespace Innertube
} }
end if end if
title = ObjectUtils.Dig(responseData, ["metadata", "channelMetadataRenderer", "title"]) author = ObjectUtils.Dig(responseData, ["metadata", "channelMetadataRenderer", "title"])
authorId = ObjectUtils.Dig(responseData, ["metadata", "channelMetadataRenderer", "externalId"])
thumbnails = ObjectUtils.Dig(responseData, ["metadata", "channelMetadataRenderer", "avatar", "thumbnails"]) thumbnails = ObjectUtils.Dig(responseData, ["metadata", "channelMetadataRenderer", "avatar", "thumbnails"])
if thumbnails = invalid if thumbnails = invalid
@@ -59,7 +64,6 @@ namespace Innertube
end if end if
end if end if
ucid = ObjectUtils.Dig(responseData, ["metadata", "channelMetadataRenderer", "externalId"])
banners = ObjectUtils.Dig(responseData, ["header", "pageHeaderRenderer", "content", "pageHeaderViewModel", "banner", "imageBannerViewModel", "image", "sources"]) banners = ObjectUtils.Dig(responseData, ["header", "pageHeaderRenderer", "content", "pageHeaderViewModel", "banner", "imageBannerViewModel", "image", "sources"])
if banners = invalid if banners = invalid
banners = [] banners = []
@@ -123,14 +127,14 @@ namespace Innertube
end if end if
items = [] items = []
feeds = ParseResponse(responseData) feeds = ParseResponse(responseData, { "currentAuthor": author, "currentAuthorId": authorId })
if feeds.Count() > 0 if feeds.Count() > 0
items = ValidArray(feeds[0].items) items = ValidArray(feeds[0].items)
end if end if
return { return {
"author": title "author": author
"authorId": ucid "authorId": authorId
"authorThumbnails": thumbnails "authorThumbnails": thumbnails
"authorBanners": banners "authorBanners": banners
"authorSubTitle": authorSubTitle "authorSubTitle": authorSubTitle
@@ -155,19 +159,40 @@ namespace Innertube
playlistSidebarRendererItems = ObjectUtils.Dig(responseData, ["sidebar", "playlistSidebarRenderer", "items"]) playlistSidebarRendererItems = ObjectUtils.Dig(responseData, ["sidebar", "playlistSidebarRenderer", "items"])
primaryInfo = ObjectUtils.Dig(playlistSidebarRendererItems, [0, "playlistSidebarPrimaryInfoRenderer"]) primaryInfo = ObjectUtils.Dig(playlistSidebarRendererItems, [0, "playlistSidebarPrimaryInfoRenderer"])
' secondaryInfo = ObjectUtils.Dig(playlistSidebarRendererItems, [1, "playlistSidebarSecondaryInfoRenderer"]) secondaryInfo = ObjectUtils.Dig(playlistSidebarRendererItems, [1, "playlistSidebarSecondaryInfoRenderer"])
playlistId = ObjectUtils.Dig(primaryInfo, ["navigationEndpoint", "watchEndpoint", "playlistId"])
title = ParseText(ObjectUtils.Dig(primaryInfo, ["title"])) title = ParseText(ObjectUtils.Dig(primaryInfo, ["title"]))
description = ParseText(ObjectUtils.Dig(primaryInfo, ["description"])) description = ParseText(ObjectUtils.Dig(primaryInfo, ["description"]))
videoCount = ParseText(ObjectUtils.Dig(primaryInfo, ["stats", 0, "runs", 0, "text"])).ToInt() videoCount = ParseText(ObjectUtils.Dig(primaryInfo, ["stats", 0, "runs", 0, "text"])).ToInt()
thumbnail = ObjectUtils.Dig(primaryInfo, ["thumbnailRenderer", "playlistVideoThumbnailRenderer", "thumbnail", "thumbnails", 0, "url"]) thumbnail = ObjectUtils.Dig(primaryInfo, ["thumbnailRenderer", "playlistVideoThumbnailRenderer", "thumbnail", "thumbnails", 0, "url"])
author = ParseText(ObjectUtils.Dig(secondaryInfo, ["videoOwner", "videoOwnerRenderer", "title"]))
authorId = ObjectUtils.Dig(secondaryInfo, ["videoOwner", "videoOwnerRenderer", "navigationEndpoint", "browseEndpoint", "browseId"])
statsText = ""
stats = ObjectUtils.Dig(primaryInfo, ["stats"])
if IsArray(stats)
statsTexts = []
for each stat in stats
statText = ParseText(stat)
if statText <> ""
statsTexts.Push(statText)
end if
end for
statsText = statsTexts.Join(" • ")
end if
playlist = { playlist = {
"playlistId": playlistId
"title": title "title": title
"author": author
"authorId": authorId
"description": description "description": description
"videoCount": videoCount "videoCount": videoCount
"thumbnail": thumbnail "thumbnail": thumbnail
"videos": [] "videos": []
"statsText": statsText
} }
feeds = ParseResponse(responseData) feeds = ParseResponse(responseData)
@@ -40,7 +40,7 @@ namespace InvidiousContent
SetIfExists(node, "_author", item, "author") SetIfExists(node, "_author", item, "author")
SetIfExists(node, "authorId", item, "authorId") SetIfExists(node, "authorId", item, "authorId")
SetIfExists(node, "lengthSeconds", item, "lengthSeconds") SetIfExists(node, "lengthSeconds", item, "lengthSeconds")
node.lengthText = TimeUtils.GetFormattedTime(item.lengthSeconds) node.lengthText = VideoGetLengthText(item)
node.liveNow = VideoIsLive(item) node.liveNow = VideoIsLive(item)
VideoSetPremiereTimestampText(node, item) VideoSetPremiereTimestampText(node, item)
node.publishedText = VideoGetPublishedText(item) node.publishedText = VideoGetPublishedText(item)
@@ -75,6 +75,7 @@ namespace InvidiousContent
node.viewCountText = PlaylistGetViewCountText(item) node.viewCountText = PlaylistGetViewCountText(item)
SetIfExists(node, "updated", item, "updated") SetIfExists(node, "updated", item, "updated")
node.updatedText = PlaylistGetUpdatedText(item) node.updatedText = PlaylistGetUpdatedText(item)
SetIfExists(node, "statsText", item, "statsText")
if item.videos <> invalid if item.videos <> invalid
childCount = node.getChildCount() childCount = node.getChildCount()
@@ -116,6 +117,7 @@ namespace InvidiousContent
SetIfExists(node, "channelHandle", item, "channelHandle") SetIfExists(node, "channelHandle", item, "channelHandle")
SetIfExists(node, "description", item, "description") SetIfExists(node, "description", item, "description")
SetIfExists(node, "subCount", item, "subCount") SetIfExists(node, "subCount", item, "subCount")
SetIfExists(node, "authorSubTitle", item, "authorSubTitle")
node.subCountText = GetChannelSubCountText(item) node.subCountText = GetChannelSubCountText(item)
SetIfExists(node, "videoCount", item, "videoCount") SetIfExists(node, "videoCount", item, "videoCount")
node.videoCountText = GetVideoCountText(item) node.videoCountText = GetVideoCountText(item)
@@ -232,6 +234,11 @@ namespace InvidiousContent
end function end function
function VideoGetViewCountText(videoItem as object) as string function VideoGetViewCountText(videoItem as object) as string
viewCountText = videoItem.viewCountText
if not StringUtils.IsNullOrEmpty(viewCountText)
return viewCountText
end if
viewCount = videoItem.viewCount viewCount = videoItem.viewCount
if viewCount = invalid if viewCount = invalid
return "" return ""
@@ -285,6 +292,9 @@ namespace InvidiousContent
end function end function
function GetVideoCountText(item as object) as string function GetVideoCountText(item as object) as string
if not StringUtils.IsNullOrEmpty(item.videoCountText)
return item.videoCountText
end if
videoCount = ValidInt(item.videoCount) videoCount = ValidInt(item.videoCount)
return LocaleUtils.GetPluralString(videoCount, Locale.RowCell.ZeroVideos, Locale.RowCell.OneVideo, Locale.RowCell.NVideos) return LocaleUtils.GetPluralString(videoCount, Locale.RowCell.ZeroVideos, Locale.RowCell.OneVideo, Locale.RowCell.NVideos)
end function end function
@@ -356,6 +366,13 @@ namespace InvidiousContent
end if end if
end function end function
function VideoGetLengthText(videoItem as object) as string
if not StringUtils.IsNullOrEmpty(videoItem.lengthText)
return videoItem.lengthText
end if
return TimeUtils.GetFormattedTime(videoItem.lengthSeconds)
end function
function PlaylistGetUpdatedText(playlistItem as object) as string function PlaylistGetUpdatedText(playlistItem as object) as string
updated = playlistItem.updated updated = playlistItem.updated
if not IsInt(updated) if not IsInt(updated)
@@ -1,3 +1,5 @@
import "pkg:/source/utils/StringUtils.bs"
function OnContentSet() as void function OnContentSet() as void
content = m.top.itemContent content = m.top.itemContent
@@ -7,7 +9,21 @@ function OnContentSet() as void
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. ' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
m.top._author = content._author m.top._author = content._author
m.top.subCountText = content.subCountText subCountText = content.authorSubTitle
if StringUtils.IsNullOrEmpty(subCountText)
if content.subCount > 0
subCountText = content.subCountText
if StringUtils.IsNullOrEmpty(subCountText)
subCountText = content.videoCountText
end if
else
subCountText = content.videoCountText
if StringUtils.IsNullOrEmpty(subCountText)
subCountText = content.subCountText
end if
end if
end if
m.top.subCountText = subCountText
m.top.channelHandle = content.channelHandle m.top.channelHandle = content.channelHandle
m.top.thumbnail = content.thumbnail m.top.thumbnail = content.thumbnail
end function end function
@@ -20,13 +20,14 @@
<Label <Label
id="authorLabel" id="authorLabel"
width="196" width="196"
font="font:SmallestBoldSystemFont"
maxLines="2" maxLines="2"
wrap="true" /> wrap="true"
font="font:SmallestBoldSystemFont" />
<Label <Label
id="subCountLabel" id="subCountLabel"
width="196" width="196"
height="25" maxLines="2"
wrap="true"
font="font:SmallestSystemFont" /> font="font:SmallestSystemFont" />
<Label <Label
id="handleLabel" id="handleLabel"
@@ -19,11 +19,12 @@ function OnContentSet() as void
m.top.thumbnailUri = content.thumbnail m.top.thumbnailUri = content.thumbnail
if content.videoCount = -1 videoCountText = content.videoCountText
if content.videoCount = -1 and videoCountText = ""
m.top.videoCountLabelVisible = false m.top.videoCountLabelVisible = false
else else
m.top.videoCountLabelVisible = true m.top.videoCountLabelVisible = true
SetVideoCount(content.videoCountText) SetVideoCount(videoCountText)
end if end if
end function end function
@@ -23,19 +23,22 @@ function OnContentSet() as void
if content.isUpcoming = true if content.isUpcoming = true
m.top.viewCountDate = content.premiereTimestampText m.top.viewCountDate = content.premiereTimestampText
else if not StringUtils.IsNullOrEmpty(content.publishedText)
label = content.publishedText
if not StringUtils.IsNullOrEmpty(content.viewCountText)
label = `${label} • ${content.viewCountText}`
end if
m.top.viewCountDate = label
else else
m.top.viewCountDate = "" publishedText = content.publishedText
viewCountText = content.viewCountText
label = publishedText
if publishedText.Len() > 0 and viewCountText.Len() > 0
label += " • "
end if
label += viewCountText
m.top.viewCountDate = label
end if end if
m.top.thumbnailUri = content.thumbnail m.top.thumbnailUri = content.thumbnail
if ValidInt(content.lengthSeconds) <> 0 if not StringUtils.IsNullOrEmpty(content.lengthText)
SetDurationLabel(content.lengthText, "#161616FF", 0.8, m.smallestSystemFont) SetDurationLabel(content.lengthText, "#161616FF", 0.8, m.smallestSystemFont)
m.top.durationRectVisible = true m.top.durationRectVisible = true
else else
+6 -2
View File
@@ -1,13 +1,17 @@
namespace ObjectUtils namespace ObjectUtils
function Dig(obj as object, keys as object) as object function Dig(obj as object, keys as object) as object
if obj = invalid
return invalid
end if
for each key in keys for each key in keys
if IsArray(obj) and IsInt(key) and key >= 0 and key < obj.Count() if (GetInterface(obj, "ifAssociativeArray") <> invalid) and (GetInterface(key, "ifString") <> invalid) and obj.DoesExist(key)
obj = obj[key] obj = obj[key]
continue for continue for
end if end if
if IsAssociativeArray(obj) and obj.DoesExist(key) if (GetInterface(obj, "ifArray") <> invalid) and (GetInterface(key, "ifInt") <> invalid) and key >= 0 and key < obj.Count()
obj = obj[key] obj = obj[key]
continue for continue for
end if end if
+2 -2
View File
@@ -5,8 +5,8 @@ namespace TimeUtils
' Helper function convert seconds to [hh:]mm:ss format ' Helper function convert seconds to [hh:]mm:ss format
' GetFormattedTime(138) returns 2:18 ' GetFormattedTime(138) returns 2:18
function GetFormattedTime(length as dynamic) as string function GetFormattedTime(length as dynamic) as string
if length = invalid or length < 0 if length = invalid or length <= 0
return "0:00" return ""
end if end if
hours = length \ 3600 hours = length \ 3600