From 227a5157a50f15626ad44b43c832fb6305894644 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 15 May 2025 21:50:40 -0400 Subject: [PATCH] Parse metadata lines on tv feeds --- .../ContentNode/PlaylistContentNode.xml | 1 + .../ContentNode/VideoContentNode.xml | 1 + .../Services/Innertube/NodesParser.bs | 24 +++++++++++++++++++ .../Invidious/InvidiousToContentNode.bs | 2 ++ .../VideoFeed/VideoRowCell/PlaylistRowCell.bs | 20 ++++++++++++++-- .../VideoFeed/VideoRowCell/VideoRowCell.bs | 23 ++++++++++++++---- .../src/lib/VideoFeed/PlaylistCell.svelte | 7 ++++-- .../src/lib/VideoFeed/VideoCell.svelte | 16 +++++++++---- 8 files changed, 82 insertions(+), 12 deletions(-) diff --git a/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml b/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml index 7abd93ab..34980de0 100644 --- a/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml +++ b/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml @@ -43,5 +43,6 @@ + \ No newline at end of file diff --git a/playlet-lib/src/components/ContentNode/VideoContentNode.xml b/playlet-lib/src/components/ContentNode/VideoContentNode.xml index 9ba5d06d..d891e9de 100644 --- a/playlet-lib/src/components/ContentNode/VideoContentNode.xml +++ b/playlet-lib/src/components/ContentNode/VideoContentNode.xml @@ -22,5 +22,6 @@ + \ No newline at end of file diff --git a/playlet-lib/src/components/Services/Innertube/NodesParser.bs b/playlet-lib/src/components/Services/Innertube/NodesParser.bs index 1c098543..8da18a24 100644 --- a/playlet-lib/src/components/Services/Innertube/NodesParser.bs +++ b/playlet-lib/src/components/Services/Innertube/NodesParser.bs @@ -975,6 +975,17 @@ namespace Innertube end if end if + renderedLines = [] + lines = ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "lines"]) + if IsArray(lines) + for each line in lines + if not IsAssociativeArray(line) + continue for + end if + renderedLines.Push(ParseLineRenderer(line["lineRenderer"])) + end for + end if + video = { "type": "video" "videoId": videoId @@ -983,6 +994,7 @@ namespace Innertube "lengthText": lengthText "liveNow": liveNow "isUpcoming": isUpcoming + "lines": renderedLines } PushFeedItem(video, context) @@ -1007,12 +1019,24 @@ namespace Innertube end for end if + renderedLines = [] + lines = ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "lines"]) + if IsArray(lines) + for each line in lines + if not IsAssociativeArray(line) + continue for + end if + renderedLines.Push(ParseLineRenderer(line["lineRenderer"])) + 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 + "lines": renderedLines } PushFeedItem(playlist, context) diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs index f9b8c3f9..a9d257d9 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs @@ -51,6 +51,7 @@ namespace InvidiousContent SetIfExists(node, "videoId", item, "videoId") node.viewCountText = VideoGetViewCountText(item) SetIfExists(node, "index", item, "index") + SetIfExists(node, "lines", item, "lines") return node end function @@ -77,6 +78,7 @@ namespace InvidiousContent SetIfExists(node, "updated", item, "updated") node.updatedText = PlaylistGetUpdatedText(item) SetIfExists(node, "statsText", item, "statsText") + SetIfExists(node, "lines", item, "lines") if item.videos <> invalid childCount = node.getChildCount() diff --git a/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.bs b/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.bs index e8cfbb14..266c4a88 100644 --- a/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.bs +++ b/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.bs @@ -1,4 +1,5 @@ import "pkg:/source/utils/Types.bs" +import "pkg:/source/utils/StringUtils.bs" function Init() m.videoCountRect = m.top.FindNode("videoCountRect") @@ -13,9 +14,24 @@ function OnContentSet() as void end if m.top.title = content.title + lines = content.lines ' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. - m.top.author = content._author - m.top.updated = content.updatedText + author = content._author + if StringUtils.IsNullOrEmpty(author) + if IsArray(lines) and lines.Count() > 0 + author = lines[0] + end if + end if + m.top.author = author + + updatedText = content.updatedText + if StringUtils.IsNullOrEmpty(updatedText) + if IsArray(lines) and lines.Count() > 1 + updatedText = lines[1] + end if + end if + m.top.updated = updatedText + m.top.thumbnailUri = content.thumbnail diff --git a/playlet-lib/src/components/VideoFeed/VideoRowCell/VideoRowCell.bs b/playlet-lib/src/components/VideoFeed/VideoRowCell/VideoRowCell.bs index 91c7974a..f7b8ec4c 100644 --- a/playlet-lib/src/components/VideoFeed/VideoRowCell/VideoRowCell.bs +++ b/playlet-lib/src/components/VideoFeed/VideoRowCell/VideoRowCell.bs @@ -18,11 +18,20 @@ function OnContentSet() as void end if m.top.title = content.title - ' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. - m.top.author = content._author + lines = content.lines + ' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. + author = content._author + if StringUtils.IsNullOrEmpty(author) + if IsArray(lines) and lines.Count() > 0 + author = lines[0] + end if + end if + m.top.author = author + + viewCountDate = "" if content.isUpcoming = true - m.top.viewCountDate = content.premiereTimestampText + viewCountDate = content.premiereTimestampText else publishedText = content.publishedText viewCountText = content.viewCountText @@ -33,8 +42,14 @@ function OnContentSet() as void end if label += viewCountText - m.top.viewCountDate = label + viewCountDate = label end if + if StringUtils.IsNullOrEmpty(viewCountDate) + if IsArray(lines) and lines.Count() > 1 + viewCountDate = lines[1] + end if + end if + m.top.viewCountDate = viewCountDate m.top.thumbnailUri = content.thumbnail diff --git a/playlet-web/src/lib/VideoFeed/PlaylistCell.svelte b/playlet-web/src/lib/VideoFeed/PlaylistCell.svelte index 6fa034fa..21344148 100644 --- a/playlet-web/src/lib/VideoFeed/PlaylistCell.svelte +++ b/playlet-web/src/lib/VideoFeed/PlaylistCell.svelte @@ -12,6 +12,7 @@ export let videoCountText: string | undefined = undefined; export let videos: any[] | undefined = undefined; export let updated: number | undefined = undefined; + export let lines: string[] | undefined = undefined; // svelte-ignore unused-export-let export let type: string = undefined; @@ -96,8 +97,10 @@ />

{title}

-
{author}
-
{getUpdatedText()}
+
+ {author || (lines?.length > 0 ? lines[0] : "")} +
+
{getUpdatedText() || (lines?.length > 1 ? lines[1] : "")}
diff --git a/playlet-web/src/lib/VideoFeed/VideoCell.svelte b/playlet-web/src/lib/VideoFeed/VideoCell.svelte index 3f753ed6..fec84d69 100644 --- a/playlet-web/src/lib/VideoFeed/VideoCell.svelte +++ b/playlet-web/src/lib/VideoFeed/VideoCell.svelte @@ -18,6 +18,7 @@ export let lengthSeconds: number = undefined; export let lengthText: string | undefined = undefined; export let liveNow: boolean = undefined; + export let lines: string[] | undefined = undefined; // svelte-ignore unused-export-let export let type: string = undefined; @@ -179,6 +180,13 @@ return trFn("1 minute ago"); } } + + function openChannelModal() { + if (!authorId) { + return; + } + channelModal.show(); + }