Skip to content

Commit

Permalink
Parse more things
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed Dec 22, 2024
1 parent bed93fe commit ac3bbda
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 14 deletions.
8 changes: 7 additions & 1 deletion playlet-lib/src/components/ChannelView/ChannelView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ function OnContentSet() as void

' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
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
if StringUtils.IsNullOrEmpty(content.thumbnail)
m.thumbnail.uri = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<!-- NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation -->
<field id="_author" type="string" />
<field id="authorId" type="string" />
<field id="authorSubTitle" type="string" />
<field id="banner" type="string" />
<field id="channelHandle" type="string" />
<field id="description" type="string" />
Expand Down
90 changes: 89 additions & 1 deletion playlet-lib/src/components/Services/Innertube/NodesParser.bs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ namespace Innertube
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 = ""
Expand Down Expand Up @@ -180,6 +186,8 @@ namespace Innertube
video = {
"type": "video"
"videoId": videoId
"author": author
"authorId": authorId
"title": ParseText(nodeData["title"])
"videoThumbnails": videoThumbnails
"viewCountText": viewCountText
Expand All @@ -206,13 +214,44 @@ namespace Innertube
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
Expand All @@ -225,10 +264,13 @@ namespace Innertube
video = {
"type": "video"
"videoId": videoId
"author": author
"authorId": authorId
"title": ParseText(nodeData["title"])
"videoThumbnails": videoThumbnails
"publishedText": publishedText
"viewCountText": viewCountText
"lengthText": lengthText
}

PushFeedItem(video, context)
Expand All @@ -242,11 +284,22 @@ namespace Innertube
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)
Expand Down Expand Up @@ -298,6 +351,8 @@ namespace Innertube
"authorId": channelId
"author": ParseText(nodeData["title"])
"authorThumbnails": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
"subCountText": ParseText(nodeData["subscriberCountText"])
"videoCountText": ParseText(nodeData["videoCountText"])
}

PushFeedItem(channel, context)
Expand All @@ -316,6 +371,8 @@ namespace Innertube
"authorId": channelId
"author": ParseText(nodeData["title"])
"authorThumbnails": ObjectUtils.Dig(nodeData, ["thumbnail", "thumbnails"])
"subCountText": ParseText(nodeData["subscriberCountText"])
"videoCountText": ParseText(nodeData["videoCountText"])
}

PushFeedItem(channel, context)
Expand Down Expand Up @@ -348,10 +405,19 @@ namespace Innertube
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
}
Expand All @@ -370,13 +436,25 @@ namespace Innertube
metadata = ObjectUtils.Dig(nodeData, ["metadata", "lockupMetadataViewModel"])

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 = {
"type": "playlist"
"playlistId": playlistId
"title": title
"author": author
"authorId": authorId
"playlistThumbnail": thumbnail
"videoCountText": videoCountText
}

PushFeedItem(playlist, context)
Expand All @@ -399,10 +477,20 @@ namespace Innertube
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
}

Expand Down
20 changes: 12 additions & 8 deletions playlet-lib/src/components/Services/Innertube/Parser.bs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "pkg:/source/utils/StringUtils.bs"

namespace Innertube

function ParseResponse(responseData as object) as object
function ParseResponse(responseData as object, context = invalid as object) as object
if responseData = invalid
return []
end if
Expand All @@ -14,7 +14,11 @@ namespace Innertube
return []
end if

context = {
if context = invalid
context = {}
end if

context.Append({
directives: Innertube.GetParsingDirectives()

feeds: []
Expand All @@ -23,7 +27,7 @@ namespace Innertube
items: []
}
generateVideoThumbnails: true
}
})

Innertube.ParseNode(data, context)

Expand All @@ -46,7 +50,8 @@ namespace Innertube
}
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"])
if thumbnails = invalid
Expand All @@ -59,7 +64,6 @@ namespace Innertube
end if
end if

ucid = ObjectUtils.Dig(responseData, ["metadata", "channelMetadataRenderer", "externalId"])
banners = ObjectUtils.Dig(responseData, ["header", "pageHeaderRenderer", "content", "pageHeaderViewModel", "banner", "imageBannerViewModel", "image", "sources"])
if banners = invalid
banners = []
Expand Down Expand Up @@ -123,14 +127,14 @@ namespace Innertube
end if

items = []
feeds = ParseResponse(responseData)
feeds = ParseResponse(responseData, { "currentAuthor": author, "currentAuthorId": authorId })
if feeds.Count() > 0
items = ValidArray(feeds[0].items)
end if

return {
"author": title
"authorId": ucid
"author": author
"authorId": authorId
"authorThumbnails": thumbnails
"authorBanners": banners
"authorSubTitle": authorSubTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ namespace InvidiousContent
SetIfExists(node, "channelHandle", item, "channelHandle")
SetIfExists(node, "description", item, "description")
SetIfExists(node, "subCount", item, "subCount")
SetIfExists(node, "authorSubTitle", item, "authorSubTitle")
node.subCountText = GetChannelSubCountText(item)
SetIfExists(node, "videoCount", item, "videoCount")
node.videoCountText = GetVideoCountText(item)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "pkg:/source/utils/StringUtils.bs"

function OnContentSet() as void
content = m.top.itemContent

Expand All @@ -7,7 +9,14 @@ function OnContentSet() as void

' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
m.top._author = content._author
m.top.subCountText = content.subCountText
subCountText = content.authorSubTitle
if StringUtils.IsNullOrEmpty(subCountText)
subCountText = content.videoCountText
if StringUtils.IsNullOrEmpty(subCountText)
subCountText = content.subCountText
end if
end if
m.top.subCountText = subCountText
m.top.channelHandle = content.channelHandle
m.top.thumbnail = content.thumbnail
end function
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
<Label
id="authorLabel"
width="196"
font="font:SmallestBoldSystemFont"
maxLines="2"
wrap="true" />
wrap="true"
font="font:SmallestBoldSystemFont" />
<Label
id="subCountLabel"
width="196"
height="25"
maxLines="2"
wrap="true"
font="font:SmallestSystemFont" />
<Label
id="handleLabel"
Expand Down

0 comments on commit ac3bbda

Please sign in to comment.