Parse metadata lines on tv feeds

This commit is contained in:
Brahim Hadriche committed 2025-05-15 21:50:40 -04:00
1 parent 4fc44becd2
commit 227a5157a5
8 files changed
+82 -12

No files matched your search

@@ -43,5 +43,6 @@
<field id="statsText" type="string" /> <field id="statsText" type="string" />
<!-- videoId is Mix continuation (playlistId starts with "RD") --> <!-- videoId is Mix continuation (playlistId starts with "RD") -->
<field id="videoId" type="string" /> <field id="videoId" type="string" />
<field id="lines" type="stringarray" />
</interface> </interface>
</component> </component>
@@ -22,5 +22,6 @@
<field id="title" type="string" /> <field id="title" type="string" />
<field id="videoId" type="string" /> <field id="videoId" type="string" />
<field id="viewCountText" type="string" /> <field id="viewCountText" type="string" />
<field id="lines" type="stringarray" />
</interface> </interface>
</component> </component>
@@ -975,6 +975,17 @@ namespace Innertube
end if end if
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 = { video = {
"type": "video" "type": "video"
"videoId": videoId "videoId": videoId
@@ -983,6 +994,7 @@ namespace Innertube
"lengthText": lengthText "lengthText": lengthText
"liveNow": liveNow "liveNow": liveNow
"isUpcoming": isUpcoming "isUpcoming": isUpcoming
"lines": renderedLines
} }
PushFeedItem(video, context) PushFeedItem(video, context)
@@ -1007,12 +1019,24 @@ namespace Innertube
end for end for
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
playlist = { playlist = {
"type": "playlist" "type": "playlist"
"playlistId": playlistId "playlistId": playlistId
"title": ParseText(ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "title"])) "title": ParseText(ObjectUtils.Dig(nodeData, ["metadata", "tileMetadataRenderer", "title"]))
"playlistThumbnail": ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnail", "thumbnails", 0, "url"]) "playlistThumbnail": ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnail", "thumbnails", 0, "url"])
"videoCountText": videoCountText "videoCountText": videoCountText
"lines": renderedLines
} }
PushFeedItem(playlist, context) PushFeedItem(playlist, context)
@@ -51,6 +51,7 @@ namespace InvidiousContent
SetIfExists(node, "videoId", item, "videoId") SetIfExists(node, "videoId", item, "videoId")
node.viewCountText = VideoGetViewCountText(item) node.viewCountText = VideoGetViewCountText(item)
SetIfExists(node, "index", item, "index") SetIfExists(node, "index", item, "index")
SetIfExists(node, "lines", item, "lines")
return node return node
end function end function
@@ -77,6 +78,7 @@ namespace InvidiousContent
SetIfExists(node, "updated", item, "updated") SetIfExists(node, "updated", item, "updated")
node.updatedText = PlaylistGetUpdatedText(item) node.updatedText = PlaylistGetUpdatedText(item)
SetIfExists(node, "statsText", item, "statsText") SetIfExists(node, "statsText", item, "statsText")
SetIfExists(node, "lines", item, "lines")
if item.videos <> invalid if item.videos <> invalid
childCount = node.getChildCount() childCount = node.getChildCount()
@@ -1,4 +1,5 @@
import "pkg:/source/utils/Types.bs" import "pkg:/source/utils/Types.bs"
import "pkg:/source/utils/StringUtils.bs"
function Init() function Init()
m.videoCountRect = m.top.FindNode("videoCountRect") m.videoCountRect = m.top.FindNode("videoCountRect")
@@ -13,9 +14,24 @@ function OnContentSet() as void
end if end if
m.top.title = content.title m.top.title = content.title
lines = content.lines
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. ' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation.
m.top.author = content._author author = content._author
m.top.updated = content.updatedText 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 m.top.thumbnailUri = content.thumbnail
@@ -18,11 +18,20 @@ function OnContentSet() as void
end if end if
m.top.title = content.title m.top.title = content.title
' NOTE: "_author" not "author". See PlaylistContentNode.xml for explanation. lines = content.lines
m.top.author = content._author
' 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 if content.isUpcoming = true
m.top.viewCountDate = content.premiereTimestampText viewCountDate = content.premiereTimestampText
else else
publishedText = content.publishedText publishedText = content.publishedText
viewCountText = content.viewCountText viewCountText = content.viewCountText
@@ -33,8 +42,14 @@ function OnContentSet() as void
end if end if
label += viewCountText label += viewCountText
m.top.viewCountDate = label viewCountDate = label
end if 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 m.top.thumbnailUri = content.thumbnail
@@ -12,6 +12,7 @@
export let videoCountText: string | undefined = undefined; export let videoCountText: string | undefined = undefined;
export let videos: any[] | undefined = undefined; export let videos: any[] | undefined = undefined;
export let updated: number | undefined = undefined; export let updated: number | undefined = undefined;
export let lines: string[] | undefined = undefined;
// svelte-ignore unused-export-let // svelte-ignore unused-export-let
export let type: string = undefined; export let type: string = undefined;
@@ -96,8 +97,10 @@
/> />
<div class="card-body"> <div class="card-body">
<h3 class="card-title text-base line-clamp-2 min-h-12">{title}</h3> <h3 class="card-title text-base line-clamp-2 min-h-12">{title}</h3>
<div class="font-semibold">{author}</div> <div class="font-semibold">
<div>{getUpdatedText()}</div> {author || (lines?.length > 0 ? lines[0] : "")}
</div>
<div>{getUpdatedText() || (lines?.length > 1 ? lines[1] : "")}</div>
</div> </div>
</div> </div>
</button> </button>
+12 -4
View File
@@ -18,6 +18,7 @@
export let lengthSeconds: number = undefined; export let lengthSeconds: number = undefined;
export let lengthText: string | undefined = undefined; export let lengthText: string | undefined = undefined;
export let liveNow: boolean = undefined; export let liveNow: boolean = undefined;
export let lines: string[] | undefined = undefined;
// svelte-ignore unused-export-let // svelte-ignore unused-export-let
export let type: string = undefined; export let type: string = undefined;
@@ -179,6 +180,13 @@
return trFn("1 minute ago"); return trFn("1 minute ago");
} }
} }
function openChannelModal() {
if (!authorId) {
return;
}
channelModal.show();
}
</script> </script>
<button <button
@@ -208,18 +216,18 @@
tabindex="0" tabindex="0"
on:click={(e) => { on:click={(e) => {
e.stopPropagation(); e.stopPropagation();
channelModal.show(); openChannelModal();
}} }}
on:keydown={(e) => { on:keydown={(e) => {
if (e.key === "Enter" || e.key === " ") { if (e.key === "Enter" || e.key === " ") {
e.preventDefault(); e.preventDefault();
channelModal.show(); openChannelModal();
} }
}} }}
> >
{author || ""} {author || (lines?.length > 0 ? lines[0] : "")}
</span> </span>
<div>{getViewCountDateText()}</div> <div>{getViewCountDateText() || (lines?.length > 1 ? lines[1] : "")}</div>
</div> </div>
</div> </div>
</button> </button>