* qrcode * add stuff * Some oauth stuff * remove some test code * Lint fix * Revert "add stuff" This reverts commit 8508471e4a0a2bfa06d4f04bfdece1f3c9191e1c. * Lint fix --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
1039 lines
39 KiB
Plaintext
1039 lines
39 KiB
Plaintext
import "pkg:/source/utils/Logging.bs"
|
|
import "pkg:/source/utils/ObjectUtils.bs"
|
|
import "pkg:/source/utils/StringUtils.bs"
|
|
import "pkg:/source/utils/Types.bs"
|
|
|
|
namespace Innertube
|
|
|
|
function ParseNode(nodeData as object, context as object) as void
|
|
if IsArray(nodeData)
|
|
for each item in nodeData
|
|
ParseNode(item, context)
|
|
end for
|
|
return
|
|
end if
|
|
|
|
if not IsAssociativeArray(nodeData)
|
|
return
|
|
end if
|
|
|
|
directives = context["directives"]
|
|
for each key in nodeData
|
|
directive = directives[key]
|
|
if directive = invalid
|
|
LogWarn("Unknown node", key)
|
|
continue for
|
|
end if
|
|
|
|
subdata = directive(nodeData[key], context)
|
|
ParseNode(subdata, context)
|
|
end for
|
|
end function
|
|
|
|
function GetParsingDirectives() as object
|
|
return {
|
|
"twoColumnSearchResultsRenderer": ParseTwoColumnSearchResultsRenderer
|
|
"twoColumnBrowseResultsRenderer": ParseTwoColumnBrowseResultsRenderer
|
|
"watchNextEndScreenRenderer": ParseWatchNextEndScreenRenderer
|
|
"tabRenderer": ParseTabRenderer
|
|
"sectionListRenderer": ParseSectionListRenderer
|
|
"itemSectionRenderer": ParseItemSectionRenderer
|
|
"shelfRenderer": ParseShelfRenderer
|
|
"reelShelfRenderer": ParseReelShelfRenderer
|
|
"verticalListRenderer": ParseVerticalListRenderer
|
|
"horizontalListRenderer": ParseHorizontalListRenderer
|
|
"expandedShelfContentsRenderer": ParseExpandedShelfContentsRenderer
|
|
"channelFeaturedContentRenderer": ParseChannelFeaturedContentRenderer
|
|
"playlistVideoListRenderer": ParsePlaylistVideoListRenderer
|
|
"videoRenderer": ParseVideoRenderer
|
|
"gridVideoRenderer": ParseGridVideoRenderer
|
|
"channelVideoPlayerRenderer": ParseChannelVideoPlayerRenderer
|
|
"playlistVideoRenderer": ParsePlaylistVideoRenderer
|
|
"playlistPanelVideoRenderer": ParsePlaylistPanelVideoRenderer
|
|
"endScreenVideoRenderer": ParseEndScreenVideoRenderer
|
|
"channelRenderer": ParseChannelRenderer
|
|
"gridChannelRenderer": ParseGridChannelRenderer
|
|
"playlistRenderer": ParsePlaylistRenderer
|
|
"gridPlaylistRenderer": ParseGridPlaylistRenderer
|
|
"lockupViewModel": ParseLockupViewModel
|
|
"shortsLockupViewModel": ParseShortsLockupViewModel
|
|
"tvBrowseRenderer": ParseTvBrowseRenderer
|
|
"tvSurfaceContentRenderer": ParseTvSurfaceContentRenderer
|
|
"tvSecondaryNavRenderer": ParseTvSecondaryNavRenderer
|
|
"tvSecondaryNavSectionRenderer": ParseTvSecondaryNavSectionRenderer
|
|
"tileRenderer": ParseTileRenderer
|
|
"gridRenderer": ParseGridRenderer
|
|
"richGridRenderer": ParseRichGridRenderer
|
|
"richItemRenderer": ParseRichItemRenderer
|
|
"continuationItemRenderer": ParseContinuationItemRenderer
|
|
"appendContinuationItemsAction": ParseAppendContinuationItemsAction
|
|
"gridContinuation": ParseGridContinuation
|
|
"tvSurfaceContentContinuation": ParseTvSurfaceContentContinuation
|
|
' Ignored nodes:
|
|
' Posts not yet supported
|
|
"postRenderer": ParseNotImplemented
|
|
' a "View all posts" button
|
|
"buttonCardViewModel": ParseNotImplemented
|
|
' to show chapters of a particular video in the search results
|
|
"horizontalCardListRenderer": ParseNotImplemented
|
|
' expandableTabRenderer contains the search tab with a channel. Ignored.
|
|
"expandableTabRenderer": ParseNotImplemented
|
|
' Usually contains a "X unavailable video(s) are hidden" message. Ignored.
|
|
"messageRenderer": ParseNotImplemented
|
|
"clickTrackingParams": ParseNotImplemented
|
|
"promoShelfRenderer": ParseNotImplemented
|
|
}
|
|
end function
|
|
|
|
function ParseTwoColumnSearchResultsRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["primaryContents"]
|
|
end function
|
|
|
|
function ParseTwoColumnBrowseResultsRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["tabs"]
|
|
end function
|
|
|
|
function ParseWatchNextEndScreenRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["results"]
|
|
end function
|
|
|
|
function ParseTabRenderer(nodeData as object, context as object) as object
|
|
selected = nodeData["selected"]
|
|
if not ValidBool(selected)
|
|
return invalid
|
|
end if
|
|
|
|
StartNewFeed(ParseText(nodeData["title"]), context)
|
|
return nodeData["content"]
|
|
end function
|
|
|
|
function ParseSectionListRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["contents"]
|
|
end function
|
|
|
|
function ParseItemSectionRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["contents"]
|
|
end function
|
|
|
|
function ParseShelfRenderer(nodeData as object, _context as object) as object
|
|
' TODO: handle shelfRenderer.title
|
|
' TODO: handle shelfRenderer.headerRenderer.shelfHeaderRenderer.avatarLockup.avatarLockupRenderer.title
|
|
return nodeData["content"]
|
|
end function
|
|
|
|
function ParseReelShelfRenderer(nodeData as object, _context as object) as object
|
|
' TODO: handle reelShelfRenderer.title
|
|
return nodeData["items"]
|
|
end function
|
|
|
|
function ParseVerticalListRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["items"]
|
|
end function
|
|
|
|
function ParseHorizontalListRenderer(nodeData as object, _context as object) as object
|
|
' TODO: handle continuations
|
|
return nodeData["items"]
|
|
end function
|
|
|
|
function ParseExpandedShelfContentsRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["items"]
|
|
end function
|
|
|
|
function ParseChannelFeaturedContentRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["items"]
|
|
end function
|
|
|
|
function ParsePlaylistVideoListRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["contents"]
|
|
end function
|
|
|
|
function ParseVideoRenderer(nodeData as object, context as object) as object
|
|
videoId = nodeData["videoId"]
|
|
if not IsString(videoId)
|
|
LogWarn("Invalid video ID", nodeData)
|
|
return invalid
|
|
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
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
else
|
|
videoThumbnails = ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
|
|
if videoThumbnails = invalid
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
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 = {
|
|
"type": "video"
|
|
"videoId": videoId
|
|
"author": author
|
|
"authorId": authorId
|
|
"title": ParseText(nodeData["title"])
|
|
"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)
|
|
return invalid
|
|
end function
|
|
|
|
function ParseGridVideoRenderer(nodeData as object, context as object) as object
|
|
videoId = nodeData["videoId"]
|
|
if not IsString(videoId)
|
|
LogWarn("Invalid video ID", nodeData)
|
|
return invalid
|
|
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
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
else
|
|
videoThumbnails = ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
|
|
if videoThumbnails = invalid
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
end if
|
|
end if
|
|
|
|
isUpcoming = false
|
|
premiereTimestamp = ObjectUtils.Dig(nodeData, ["upcomingEventData", "startTime"])
|
|
if IsString(premiereTimestamp)
|
|
premiereTimestamp = premiereTimestamp.ToInt()
|
|
isUpcoming = true
|
|
end if
|
|
|
|
video = {
|
|
"type": "video"
|
|
"videoId": videoId
|
|
"author": author
|
|
"authorId": authorId
|
|
"title": ParseText(nodeData["title"])
|
|
"videoThumbnails": videoThumbnails
|
|
"publishedText": publishedText
|
|
"viewCountText": viewCountText
|
|
"lengthText": lengthText
|
|
}
|
|
|
|
if isUpcoming
|
|
video["isUpcoming"] = true
|
|
video["premiereTimestamp"] = premiereTimestamp
|
|
end if
|
|
|
|
PushFeedItem(video, context)
|
|
return invalid
|
|
end function
|
|
|
|
function ParseChannelVideoPlayerRenderer(nodeData as object, context as object) as object
|
|
videoId = nodeData["videoId"]
|
|
if not IsString(videoId)
|
|
LogWarn("Invalid video ID", nodeData)
|
|
return invalid
|
|
end if
|
|
|
|
author = invalid
|
|
authorId = invalid
|
|
if IsString(context.currentAuthor) and IsString(context.currentAuthorId)
|
|
author = context.currentAuthor
|
|
authorId = context.currentAuthorId
|
|
end if
|
|
|
|
video = {
|
|
"type": "video"
|
|
"videoId": videoId
|
|
"author": author
|
|
"authorId": authorId
|
|
"title": ParseText(nodeData["title"])
|
|
"videoThumbnails": GenerateVideoThumbnails(videoId)
|
|
"viewCountText": ParseText(nodeData["viewCountText"])
|
|
"publishedText": ParseText(nodeData["publishedTimeText"])
|
|
}
|
|
|
|
PushFeedItem(video, context)
|
|
return invalid
|
|
end function
|
|
|
|
function ParsePlaylistVideoRenderer(nodeData as object, context as object) as object
|
|
videoId = nodeData["videoId"]
|
|
if not IsString(videoId)
|
|
LogWarn("Invalid video ID", nodeData)
|
|
return invalid
|
|
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
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
else
|
|
videoThumbnails = ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
|
|
if videoThumbnails = invalid
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
end if
|
|
end if
|
|
|
|
video = {
|
|
"type": "video"
|
|
"videoId": videoId
|
|
"author": author
|
|
"authorId": authorId
|
|
"title": ParseText(nodeData["title"])
|
|
"videoThumbnails": videoThumbnails
|
|
"index": ParseText(nodeData["index"]).ToInt()
|
|
"lengthText": lengthText
|
|
"lengthSeconds": lengthSeconds
|
|
}
|
|
|
|
PushFeedItem(video, context)
|
|
return invalid
|
|
end function
|
|
|
|
function ParsePlaylistPanelVideoRenderer(nodeData as object, context as object) as object
|
|
videoId = nodeData["videoId"]
|
|
if not IsString(videoId)
|
|
LogWarn("Invalid video 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
|
|
|
|
if context.generateVideoThumbnails = true
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
else
|
|
videoThumbnails = ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
|
|
if videoThumbnails = invalid
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
end if
|
|
end if
|
|
|
|
isUpcoming = false
|
|
liveNow = ValidString(ObjectUtils.Dig(nodeData, ["badges", 0, "metadataBadgeRenderer", "icon", "iconType"])) = "LIVE"
|
|
thumbnailOverlays = nodeData["thumbnailOverlays"]
|
|
if IsArray(thumbnailOverlays)
|
|
for each overlay in thumbnailOverlays
|
|
liveNow = liveNow or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "LIVE")
|
|
isUpcoming = isUpcoming or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "UPCOMING")
|
|
end for
|
|
end if
|
|
|
|
lengthText = ParseText(nodeData["lengthText"])
|
|
|
|
video = {
|
|
"type": "video"
|
|
"videoId": videoId
|
|
"author": author
|
|
"authorId": authorId
|
|
"title": ParseText(nodeData["title"])
|
|
"videoThumbnails": videoThumbnails
|
|
"lengthText": lengthText
|
|
"liveNow": liveNow
|
|
"isUpcoming": isUpcoming
|
|
}
|
|
|
|
PushFeedItem(video, context)
|
|
return invalid
|
|
end function
|
|
|
|
function ParseEndScreenVideoRenderer(nodeData as object, context as object) as object
|
|
videoId = nodeData["videoId"]
|
|
if not IsString(videoId)
|
|
LogWarn("Invalid video 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
|
|
|
|
video = {
|
|
"type": "video"
|
|
"videoId": videoId
|
|
"author": author
|
|
"authorId": authorId
|
|
"title": ParseText(nodeData["title"])
|
|
"videoThumbnails": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
|
|
}
|
|
|
|
PushFeedItem(video, context)
|
|
return invalid
|
|
end function
|
|
|
|
function ParseChannelRenderer(nodeData as object, context as object) as object
|
|
channelId = nodeData["channelId"]
|
|
if not IsString(channelId)
|
|
LogWarn("Invalid channel ID", nodeData)
|
|
return invalid
|
|
end if
|
|
|
|
channel = {
|
|
"type": "channel"
|
|
"authorId": channelId
|
|
"author": ParseText(nodeData["title"])
|
|
"authorThumbnails": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
|
|
"subCountText": ParseText(nodeData["subscriberCountText"])
|
|
"videoCountText": ParseText(nodeData["videoCountText"])
|
|
}
|
|
|
|
PushFeedItem(channel, context)
|
|
return invalid
|
|
end function
|
|
|
|
function ParseGridChannelRenderer(nodeData as object, context as object) as object
|
|
channelId = nodeData["channelId"]
|
|
if not IsString(channelId)
|
|
LogWarn("Invalid channel ID", nodeData)
|
|
return invalid
|
|
end if
|
|
|
|
channel = {
|
|
"type": "channel"
|
|
"authorId": channelId
|
|
"author": ParseText(nodeData["title"])
|
|
"authorThumbnails": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
|
|
"subCountText": ParseText(nodeData["subscriberCountText"])
|
|
"videoCountText": ParseText(nodeData["videoCountText"])
|
|
}
|
|
|
|
PushFeedItem(channel, context)
|
|
return invalid
|
|
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 ParseGridPlaylistRenderer(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
|
|
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
|
|
|
|
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
|
|
if videoCountText = ""
|
|
videoCountText = ParseText(nodeData["videoCountShortText"])
|
|
end if
|
|
|
|
videoCount = ParseText(nodeData["videoCount"])
|
|
if videoCount = ""
|
|
videoCount = ParseText(nodeData["videoCountShortText"])
|
|
end if
|
|
videoCount = videoCount.ToInt()
|
|
|
|
playlist = {
|
|
"type": "playlist"
|
|
"playlistId": playlistId
|
|
"title": ParseText(nodeData["title"])
|
|
"playlistThumbnail": ObjectUtils.Dig(nodeData, ["thumbnail", "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
|
|
contentType = ValidString(nodeData["contentType"])
|
|
if contentType = "LOCKUP_CONTENT_TYPE_PLAYLIST"
|
|
return LockupViewModelTypePlaylist(nodeData, context)
|
|
else if contentType = "LOCKUP_CONTENT_TYPE_PODCAST"
|
|
return LockupViewModelTypePodcast(nodeData, context)
|
|
else if contentType = "LOCKUP_CONTENT_TYPE_ALBUM"
|
|
return LockupViewModelTypeAlbum(nodeData, context)
|
|
end if
|
|
|
|
LogWarn("Unknown content type:", contentType, `\n`, nodeData)
|
|
return invalid
|
|
end function
|
|
|
|
function LockupViewModelTypePlaylist(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
|
|
|
|
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 = {
|
|
"type": "playlist"
|
|
"playlistId": playlistId
|
|
"title": title
|
|
"author": author
|
|
"authorId": authorId
|
|
"playlistThumbnail": thumbnail
|
|
"videoCountText": videoCountText
|
|
}
|
|
|
|
' Mixes have a videoId, which is the first video in the mix
|
|
if playlistId.StartsWith("RD")
|
|
videoId = ObjectUtils.Dig(nodeData, ["rendererContext", "commandContext", "onTap", "innertubeCommand", "watchEndpoint", "videoId"])
|
|
if IsString(videoId)
|
|
playlist["videoId"] = videoId
|
|
end if
|
|
end if
|
|
|
|
PushFeedItem(playlist, context)
|
|
return invalid
|
|
end function
|
|
|
|
function LockupViewModelTypePodcast(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)
|
|
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)
|
|
return invalid
|
|
end function
|
|
|
|
function ParseShortsLockupViewModel(nodeData as object, context as object) as object
|
|
videoId = ObjectUtils.Dig(nodeData, ["onTap", "innertubeCommand", "reelWatchEndpoint", "videoId"])
|
|
if not IsString(videoId)
|
|
LogWarn("Invalid video ID", nodeData)
|
|
return invalid
|
|
end if
|
|
|
|
if context.generateVideoThumbnails = true
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
else
|
|
videoThumbnails = ObjectUtils.Dig(nodeData, ["thumbnail", "sources"])
|
|
if videoThumbnails = invalid
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
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 = {
|
|
"type": "video"
|
|
"videoId": videoId
|
|
"author": author
|
|
"authorId": authorId
|
|
"title": ObjectUtils.Dig(nodeData, ["overlayMetadata", "primaryText", "content"])
|
|
"viewCountText": ObjectUtils.Dig(nodeData, ["overlayMetadata", "secondaryText", "content"])
|
|
"videoThumbnails": videoThumbnails
|
|
}
|
|
|
|
PushFeedItem(video, context)
|
|
return invalid
|
|
end function
|
|
|
|
function ParseTvBrowseRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["content"]
|
|
end function
|
|
|
|
function ParseTvSurfaceContentRenderer(nodeData as object, _context as object) as object
|
|
' TODO: handle tvSurfaceContentRenderer.continuation
|
|
return nodeData["content"]
|
|
end function
|
|
|
|
function ParseTvSecondaryNavRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["sections"]
|
|
end function
|
|
|
|
function ParseTvSecondaryNavSectionRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["tabs"]
|
|
end function
|
|
|
|
function ParseTileRenderer(nodeData as object, context as object) as object
|
|
contentType = ValidString(nodeData["contentType"])
|
|
if contentType = "TILE_CONTENT_TYPE_VIDEO"
|
|
return TileRendererTypeVideo(nodeData, context)
|
|
else if contentType = "TILE_CONTENT_TYPE_PLAYLIST"
|
|
return TileRendererTypePlaylist(nodeData, context)
|
|
end if
|
|
|
|
LogWarn("Unknown content type:", contentType, `\n`, nodeData)
|
|
return invalid
|
|
end function
|
|
|
|
function TileRendererTypeVideo(nodeData as object, context as object) as object
|
|
videoId = nodeData["contentId"]
|
|
if not IsString(videoId)
|
|
LogWarn("Invalid video ID", nodeData)
|
|
return invalid
|
|
end if
|
|
|
|
if context.generateVideoThumbnails = true
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
else
|
|
videoThumbnails = ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnail", "thumbnails"])
|
|
if videoThumbnails = invalid
|
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
|
end if
|
|
end if
|
|
|
|
lengthText = ""
|
|
isUpcoming = false
|
|
liveNow = false
|
|
thumbnailOverlays = ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnailOverlays"])
|
|
if IsArray(thumbnailOverlays)
|
|
for each overlay in thumbnailOverlays
|
|
maybeLengthText = ParseText(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "text"]))
|
|
if maybeLengthText <> ""
|
|
lengthText = maybeLengthText
|
|
end if
|
|
liveNow = liveNow or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "LIVE")
|
|
isUpcoming = isUpcoming or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "UPCOMING")
|
|
end for
|
|
if liveNow or isUpcoming
|
|
lengthText = ""
|
|
end if
|
|
end if
|
|
|
|
video = {
|
|
"type": "video"
|
|
"videoId": videoId
|
|
"title": ParseText(ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "title"]))
|
|
"videoThumbnails": videoThumbnails
|
|
"lengthText": lengthText
|
|
"liveNow": liveNow
|
|
"isUpcoming": isUpcoming
|
|
}
|
|
|
|
PushFeedItem(video, context)
|
|
return invalid
|
|
end function
|
|
|
|
function TileRendererTypePlaylist(nodeData as object, context as object) as object
|
|
playlistId = nodeData["contentId"]
|
|
if not IsString(playlistId)
|
|
LogWarn("Invalid playlist ID", nodeData)
|
|
return invalid
|
|
end if
|
|
|
|
videoCountText = ""
|
|
thumbnailOverlays = ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnailOverlays"])
|
|
if IsArray(thumbnailOverlays)
|
|
for each overlay in thumbnailOverlays
|
|
videoCountText = ParseText(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "text"]))
|
|
if videoCountText <> ""
|
|
exit for
|
|
end if
|
|
end for
|
|
end if
|
|
|
|
playlist = {
|
|
"type": "playlist"
|
|
"playlistId": playlistId
|
|
"title": ParseText(ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "title"]))
|
|
"playlistThumbnail": ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnail", "thumbnails", 0, "url"])
|
|
"videoCountText": videoCountText
|
|
}
|
|
|
|
PushFeedItem(playlist, context)
|
|
return invalid
|
|
end function
|
|
|
|
function ParseGridRenderer(nodeData as object, context as object) as object
|
|
continuation = ObjectUtils.Dig(nodeData, ["continuations", 0, "nextContinuationData", "continuation"])
|
|
if IsString(continuation)
|
|
context.currentFeed.continuation = continuation
|
|
end if
|
|
return nodeData["items"]
|
|
end function
|
|
|
|
function ParseRichGridRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["contents"]
|
|
end function
|
|
|
|
function ParseRichItemRenderer(nodeData as object, _context as object) as object
|
|
return nodeData["content"]
|
|
end function
|
|
|
|
function ParseContinuationItemRenderer(nodeData as object, context as object) as object
|
|
continuation = ObjectUtils.Dig(nodeData, ["continuationEndpoint", "continuationCommand", "token"])
|
|
if IsString(continuation)
|
|
' In Playlists there are 2 continuation items, and one of them is useless...
|
|
' TODO:P1 figure this out
|
|
if StringUtils.IsNullOrEmpty(context.currentFeed.continuation)
|
|
context.currentFeed.continuation = continuation
|
|
end if
|
|
end if
|
|
return invalid
|
|
end function
|
|
|
|
function ParseAppendContinuationItemsAction(nodeData as object, _context as object) as object
|
|
return nodeData["continuationItems"]
|
|
end function
|
|
|
|
function ParseGridContinuation(nodeData as object, context as object) as object
|
|
continuation = ObjectUtils.Dig(nodeData, ["continuations", 0, "nextContinuationData", "continuation"])
|
|
if IsString(continuation)
|
|
context.currentFeed.continuation = continuation
|
|
end if
|
|
return nodeData["items"]
|
|
end function
|
|
|
|
function ParseTvSurfaceContentContinuation(nodeData as object, context as object) as object
|
|
' title = ParseText(ObjectUtils.Dig(nodeData, ["header", "tvSurfaceHeaderRenderer", "title"]))
|
|
return nodeData["content"]
|
|
end function
|
|
|
|
function ParseText(data as object) as string
|
|
if data = invalid
|
|
return ""
|
|
end if
|
|
if IsString(data)
|
|
return data
|
|
end if
|
|
if data.DoesExist("simpleText")
|
|
return data["simpleText"]
|
|
end if
|
|
if data.DoesExist("runs")
|
|
text = ""
|
|
for each _run in data["runs"]
|
|
text += _run["text"]
|
|
end for
|
|
return text
|
|
end if
|
|
return ""
|
|
end function
|
|
|
|
function StartNewFeed(title as string, context as object) as void
|
|
if context.currentFeed <> invalid
|
|
if context.currentFeed.items.Count() = 0 and context.currentFeed.title = ""
|
|
context.currentFeed.title = title
|
|
return
|
|
end if
|
|
context.feeds.Push(context.currentFeed)
|
|
end if
|
|
context.currentFeed = {
|
|
"title": title
|
|
"items": []
|
|
}
|
|
end function
|
|
|
|
function PushFeedItem(item as object, context as object) as void
|
|
if context.currentFeed = invalid
|
|
context.currentFeed = {
|
|
"title": ""
|
|
"items": []
|
|
}
|
|
end if
|
|
context.currentFeed.items.Push(item)
|
|
end function
|
|
|
|
function ParseNotImplemented(_data as object, _context as object) as object
|
|
return invalid
|
|
end function
|
|
|
|
function GenerateVideoThumbnails(videoId as string) as object
|
|
return [
|
|
{
|
|
"quality": "maxres"
|
|
"url": `https://i.ytimg.com/vi/${videoId}/maxresdefault.jpg`
|
|
"width": 1280
|
|
"height": 720
|
|
}
|
|
{
|
|
"quality": "sddefault"
|
|
"url": `https://i.ytimg.com/vi/${videoId}/sddefault.jpg`
|
|
"width": 640
|
|
"height": 480
|
|
}
|
|
{
|
|
"quality": "high"
|
|
"url": `https://i.ytimg.com/vi/${videoId}/hqdefault.jpg`
|
|
"width": 480
|
|
"height": 360
|
|
}
|
|
{
|
|
"quality": "medium"
|
|
"url": `https://i.ytimg.com/vi/${videoId}/mqdefault.jpg`
|
|
"width": 320
|
|
"height": 180
|
|
}
|
|
]
|
|
end function
|
|
end namespace
|