Improve performance of video bookmarks (#662)
* Improve performance of video bookmarks * remove test code
This commit is contained in:
1 parent
63f8ba8617
commit
d8417ee90c
8 files changed
+229
-5
No files matched your search
+3
-1
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
- Nothing worth mentioning yet.
|
### Fixed
|
||||||
|
|
||||||
|
- Improve performance of video bookmarks, by avoiding `/player` endpoint and caching results
|
||||||
|
|
||||||
## [0.40.5] - 2025-06-19
|
## [0.40.5] - 2025-06-19
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ end function
|
|||||||
function AddVideoBookmark(id as string, groupName as string)
|
function AddVideoBookmark(id as string, groupName as string)
|
||||||
bookmarkGroupNode = GetOrCreateBookmarkGroup(groupName)
|
bookmarkGroupNode = GetOrCreateBookmarkGroup(groupName)
|
||||||
|
|
||||||
|
' TODO:P1 instead of just storying the video id, we should store
|
||||||
|
' enough metadata for display (videoId, author, authorId, title,
|
||||||
|
' duration, isLive) that way all data is offline and avoid making
|
||||||
|
' a request altogether.
|
||||||
feedSource = {
|
feedSource = {
|
||||||
"apiType": "Invidious"
|
"apiType": "Invidious"
|
||||||
"endpoint": "video_info"
|
"endpoint": "video_info"
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ namespace InnertubeService
|
|||||||
}
|
}
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
' If we're fetching more than one video, we want to search for the playlist
|
||||||
|
if videoIds.Count() > 1
|
||||||
responseData = ObjectUtils.Dig(responseData, ["contents", "twoColumnWatchNextResults", "playlist", "playlist"])
|
responseData = ObjectUtils.Dig(responseData, ["contents", "twoColumnWatchNextResults", "playlist", "playlist"])
|
||||||
if responseData = invalid
|
if responseData = invalid
|
||||||
' Sometimes the response doesn't contain a playlist.
|
' Sometimes the response doesn't contain a playlist.
|
||||||
@@ -134,13 +136,28 @@ namespace InnertubeService
|
|||||||
LogWarn("Response data missing playlist. Not retrying.")
|
LogWarn("Response data missing playlist. Not retrying.")
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
feeds = Innertube.ParseResponseDataForFeeds(responseData)
|
feeds = Innertube.ParseResponseDataForFeeds(responseData)
|
||||||
|
|
||||||
|
if videoIds.Count() > 1
|
||||||
if feeds.Count() > 0
|
if feeds.Count() > 0
|
||||||
return {
|
return {
|
||||||
videos: ValidArray(feeds[0].items)
|
videos: ValidArray(feeds[0].items)
|
||||||
}
|
}
|
||||||
end if
|
end if
|
||||||
|
else
|
||||||
|
if feeds.Count() > 0
|
||||||
|
foundVideos = feeds[0].items
|
||||||
|
for each video in foundVideos
|
||||||
|
if video.videoId = videoIds[0]
|
||||||
|
return {
|
||||||
|
videos: [video]
|
||||||
|
}
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
return {
|
return {
|
||||||
videos: []
|
videos: []
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ namespace Innertube
|
|||||||
"twoColumnSearchResultsRenderer": ParseTwoColumnSearchResultsRenderer
|
"twoColumnSearchResultsRenderer": ParseTwoColumnSearchResultsRenderer
|
||||||
"singleColumnBrowseResultsRenderer": ParseSingleColumnBrowseResultsRenderer
|
"singleColumnBrowseResultsRenderer": ParseSingleColumnBrowseResultsRenderer
|
||||||
"twoColumnBrowseResultsRenderer": ParseTwoColumnBrowseResultsRenderer
|
"twoColumnBrowseResultsRenderer": ParseTwoColumnBrowseResultsRenderer
|
||||||
|
"twoColumnWatchNextResults": ParseTwoColumnWatchNextResults
|
||||||
"watchNextEndScreenRenderer": ParseWatchNextEndScreenRenderer
|
"watchNextEndScreenRenderer": ParseWatchNextEndScreenRenderer
|
||||||
"tabRenderer": ParseTabRenderer
|
"tabRenderer": ParseTabRenderer
|
||||||
"sectionListRenderer": ParseSectionListRenderer
|
"sectionListRenderer": ParseSectionListRenderer
|
||||||
@@ -61,6 +62,8 @@ namespace Innertube
|
|||||||
"playlistVideoListContinuation": ParsePlaylistVideoListContinuation
|
"playlistVideoListContinuation": ParsePlaylistVideoListContinuation
|
||||||
"videoRenderer": ParseVideoRenderer
|
"videoRenderer": ParseVideoRenderer
|
||||||
"gridVideoRenderer": ParseGridVideoRenderer
|
"gridVideoRenderer": ParseGridVideoRenderer
|
||||||
|
"compactVideoRenderer": ParseCompactVideoRenderer
|
||||||
|
"videoPrimaryInfoRenderer": ParseVideoPrimaryInfoRenderer
|
||||||
"channelVideoPlayerRenderer": ParseChannelVideoPlayerRenderer
|
"channelVideoPlayerRenderer": ParseChannelVideoPlayerRenderer
|
||||||
"playlistVideoRenderer": ParsePlaylistVideoRenderer
|
"playlistVideoRenderer": ParsePlaylistVideoRenderer
|
||||||
"playlistPanelVideoRenderer": ParsePlaylistPanelVideoRenderer
|
"playlistPanelVideoRenderer": ParsePlaylistPanelVideoRenderer
|
||||||
@@ -88,6 +91,14 @@ namespace Innertube
|
|||||||
"gridContinuation": ParseGridContinuation
|
"gridContinuation": ParseGridContinuation
|
||||||
"tvSurfaceContentContinuation": ParseTvSurfaceContentContinuation
|
"tvSurfaceContentContinuation": ParseTvSurfaceContentContinuation
|
||||||
' Ignored nodes:
|
' Ignored nodes:
|
||||||
|
' Contains comments "teaser".
|
||||||
|
"commentsEntryPointHeaderRenderer": ParseNotImplemented
|
||||||
|
' Contains the owner of the video from "videoPrimaryInfoRenderer"
|
||||||
|
"videoSecondaryInfoRenderer": ParseNotImplemented
|
||||||
|
' Empty node? Perhaps used in some cases
|
||||||
|
"compositeVideoPrimaryInfoRenderer": ParseNotImplemented
|
||||||
|
' An information panel, could contain a link to some website, or a message.
|
||||||
|
"infoPanelContainerRenderer": ParseNotImplemented
|
||||||
' When you mispell something in the search bar, this renderer shows
|
' When you mispell something in the search bar, this renderer shows
|
||||||
"didYouMeanRenderer": ParseNotImplemented
|
"didYouMeanRenderer": ParseNotImplemented
|
||||||
' A list of subscribers in a channel with a CTA to subscribe.
|
' A list of subscribers in a channel with a CTA to subscribe.
|
||||||
@@ -136,6 +147,32 @@ namespace Innertube
|
|||||||
return nodeData["tabs"]
|
return nodeData["tabs"]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function ParseTwoColumnWatchNextResults(nodeData as object, _context as object) as object
|
||||||
|
subItems = []
|
||||||
|
|
||||||
|
results = ObjectUtils.Dig(nodeData, ["results", "results", "contents"])
|
||||||
|
if results <> invalid
|
||||||
|
subItems.Push(results)
|
||||||
|
end if
|
||||||
|
|
||||||
|
secondaryResults = ObjectUtils.Dig(nodeData, ["secondaryResults", "secondaryResults", "results"])
|
||||||
|
if secondaryResults <> invalid
|
||||||
|
subItems.Push(secondaryResults)
|
||||||
|
end if
|
||||||
|
' Technically, this playlist would have its own title, and should count as a separate feed.
|
||||||
|
' For now, we just add it to the current feed.
|
||||||
|
playlist = ObjectUtils.Dig(nodeData, ["playlist", "playlist", "contents"])
|
||||||
|
if playlist <> invalid
|
||||||
|
subItems.Push(playlist)
|
||||||
|
end if
|
||||||
|
|
||||||
|
if subItems.Count() = 0
|
||||||
|
LogWarn("No results found in TwoColumnWatchNextResults", nodeData)
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
return subItems
|
||||||
|
end function
|
||||||
|
|
||||||
function ParseWatchNextEndScreenRenderer(nodeData as object, _context as object) as object
|
function ParseWatchNextEndScreenRenderer(nodeData as object, _context as object) as object
|
||||||
return nodeData["results"]
|
return nodeData["results"]
|
||||||
end function
|
end function
|
||||||
@@ -451,6 +488,137 @@ namespace Innertube
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function ParseCompactVideoRenderer(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
|
||||||
|
|
||||||
|
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
|
||||||
|
parsedTimeStatusRenderer = ParseThumbnailOverlayTimeStatusRenderer(overlay)
|
||||||
|
if parsedTimeStatusRenderer <> invalid
|
||||||
|
lengthText = parsedTimeStatusRenderer.text
|
||||||
|
if lengthText <> ""
|
||||||
|
exit for
|
||||||
|
end if
|
||||||
|
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
|
||||||
|
liveNow = ValidString(ObjectUtils.Dig(nodeData, ["badges", 0, "metadataBadgeRenderer", "icon", "iconType"])) = "LIVE"
|
||||||
|
thumbnailOverlays = nodeData["thumbnailOverlays"]
|
||||||
|
if IsArray(thumbnailOverlays)
|
||||||
|
for each overlay in thumbnailOverlays
|
||||||
|
parsedTimeStatusRenderer = ParseThumbnailOverlayTimeStatusRenderer(overlay)
|
||||||
|
if parsedTimeStatusRenderer <> invalid
|
||||||
|
if parsedTimeStatusRenderer.isShort
|
||||||
|
if context.disableShorts = true
|
||||||
|
LogInfo("Skipping Short based on user settings")
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
liveNow = liveNow or parsedTimeStatusRenderer.isLive
|
||||||
|
isUpcoming = isUpcoming or parsedTimeStatusRenderer.isUpcoming
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
end if
|
||||||
|
|
||||||
|
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 isUpcoming
|
||||||
|
video["isUpcoming"] = true
|
||||||
|
video["premiereTimestamp"] = premiereTimestamp
|
||||||
|
end if
|
||||||
|
PushFeedItem(video, context)
|
||||||
|
return invalid
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ParseVideoPrimaryInfoRenderer(nodeData as object, context as object) as object
|
||||||
|
videoId = nodeData["videoId"]
|
||||||
|
if not IsString(videoId)
|
||||||
|
videoId = ObjectUtils.Dig(nodeData, ["updatedMetadataEndpoint", "updatedMetadataEndpoint", "videoId"])
|
||||||
|
if not IsString(videoId)
|
||||||
|
LogWarn("Invalid video ID", nodeData)
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
title = ParseText(nodeData["title"])
|
||||||
|
videoThumbnails = GenerateVideoThumbnails(videoId)
|
||||||
|
|
||||||
|
publishedText = ParseText(nodeData["relativeDateText"])
|
||||||
|
if publishedText = ""
|
||||||
|
publishedText = ParseText(nodeData["dateText"])
|
||||||
|
end if
|
||||||
|
|
||||||
|
viewCountText = ParseText(ObjectUtils.Dig(nodeData, ["viewCount", "videoViewCountRenderer", "viewCount"]))
|
||||||
|
|
||||||
|
' TODO:P2 the owner of the video is under videoSecondaryInfoRenderer in a neibouring node.
|
||||||
|
video = {
|
||||||
|
"type": "video"
|
||||||
|
"videoId": videoId
|
||||||
|
"title": title
|
||||||
|
"videoThumbnails": videoThumbnails
|
||||||
|
"viewCountText": viewCountText
|
||||||
|
"publishedText": publishedText
|
||||||
|
}
|
||||||
|
|
||||||
|
PushFeedItem(video, context)
|
||||||
|
return invalid
|
||||||
|
end function
|
||||||
|
|
||||||
function ParseChannelVideoPlayerRenderer(nodeData as object, context as object) as object
|
function ParseChannelVideoPlayerRenderer(nodeData as object, context as object) as object
|
||||||
videoId = nodeData["videoId"]
|
videoId = nodeData["videoId"]
|
||||||
if not IsString(videoId)
|
if not IsString(videoId)
|
||||||
|
|||||||
@@ -26,10 +26,11 @@ function VideoQueueViewContentTask(input as object) as object
|
|||||||
visitorData: innertubeNode.visitorData
|
visitorData: innertubeNode.visitorData
|
||||||
}
|
}
|
||||||
|
|
||||||
' TODO:P1: Use InnertubeService.GetVideoInfoBatched instead of loading each video individually
|
' TODO:P1: Use InnertubeService.GetVideoInfoBatched with an array instead of loading each video individually
|
||||||
' TODO:P1: It turns out this might be too much. With a large number of videos
|
' TODO:P1: It turns out this might be too much. With a large number of videos
|
||||||
' YouTube starts to rate limit us.
|
' YouTube starts to rate limit us.
|
||||||
' Need to change it to load on demand using render tracking
|
' Need to change it to load on demand using render tracking
|
||||||
|
' Or maybe not load this stuff at all.
|
||||||
for i = index to videoNodes.Count() - 1
|
for i = index to videoNodes.Count() - 1
|
||||||
videoNode = videoNodes[i]
|
videoNode = videoNodes[i]
|
||||||
if not LoadVideoDetail(videoNode, service, instance, requestOptions, backend)
|
if not LoadVideoDetail(videoNode, service, instance, requestOptions, backend)
|
||||||
@@ -57,12 +58,19 @@ function VideoQueueViewContentTask(input as object) as object
|
|||||||
return invalid
|
return invalid
|
||||||
end function
|
end function
|
||||||
|
|
||||||
' Returns true if the video was loaded from cache.
|
|
||||||
function LoadVideoDetail(videoNode as object, service as object, instance as string, requestOptions as object, backend as string) as boolean
|
function LoadVideoDetail(videoNode as object, service as object, instance as string, requestOptions as object, backend as string) as boolean
|
||||||
videoId = videoNode.videoId
|
videoId = videoNode.videoId
|
||||||
|
|
||||||
if backend = "playlet"
|
if backend = "playlet"
|
||||||
metadata = InnertubeService.GetVideoMetadata(videoId, requestOptions)
|
requestOptions["retry"] = false
|
||||||
|
metadata = InnertubeService.GetVideoInfoBatched([videoId], requestOptions)
|
||||||
|
if IsArray(metadata.videos) and metadata.videos.Count() > 0
|
||||||
|
metadata = metadata.videos[0]
|
||||||
|
else
|
||||||
|
metadata = {
|
||||||
|
"error": "Failed to get video info with video_info_batched=true"
|
||||||
|
}
|
||||||
|
end if
|
||||||
else
|
else
|
||||||
metadata = service.GetVideoMetadata(videoId, requestOptions)
|
metadata = service.GetVideoMetadata(videoId, requestOptions)
|
||||||
end if
|
end if
|
||||||
|
|||||||
+21
@@ -572,17 +572,38 @@ namespace Http
|
|||||||
videoId = videoId.Left(videoId.InStr("?"))
|
videoId = videoId.Left(videoId.InStr("?"))
|
||||||
end if
|
end if
|
||||||
raw = request.query.raw <> invalid
|
raw = request.query.raw <> invalid
|
||||||
|
videoInfoBatched = request.query.video_info_batched <> invalid
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
"raw": raw
|
"raw": raw
|
||||||
"visitorData": m.innertube.visitorData
|
"visitorData": m.innertube.visitorData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if videoInfoBatched
|
||||||
|
options["retry"] = false
|
||||||
|
metadata = InnertubeService.GetVideoInfoBatched([videoId], options)
|
||||||
|
if IsArray(metadata.videos) and metadata.videos.Count() > 0
|
||||||
|
metadata = metadata.videos[0]
|
||||||
|
else
|
||||||
|
metadata = {
|
||||||
|
"error": "Failed to get video info with video_info_batched=true"
|
||||||
|
}
|
||||||
|
end if
|
||||||
|
else
|
||||||
metadata = InnertubeService.GetVideoMetadata(videoId, options)
|
metadata = InnertubeService.GetVideoMetadata(videoId, options)
|
||||||
|
end if
|
||||||
|
|
||||||
response.Json(metadata)
|
response.Json(metadata)
|
||||||
|
|
||||||
if metadata.error <> invalid
|
if metadata.error <> invalid
|
||||||
response.http_code = 500
|
response.http_code = 500
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
' If we're only interested in video info and not streaming data,
|
||||||
|
' we can return longer cache time.
|
||||||
|
if videoInfoBatched
|
||||||
|
response.headers["cache-control"] = "public, max-age=259200" ' 3 days
|
||||||
end if
|
end if
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ video_info:
|
|||||||
url: /api/v1/videos/{id}
|
url: /api/v1/videos/{id}
|
||||||
responseHandler: VideoInfoHandler
|
responseHandler: VideoInfoHandler
|
||||||
cacheSeconds: 259200 # 3 days
|
cacheSeconds: 259200 # 3 days
|
||||||
|
queryParams:
|
||||||
|
video_info_batched:
|
||||||
|
type: boolean
|
||||||
|
default: true
|
||||||
|
|
||||||
playlist_info:
|
playlist_info:
|
||||||
title: Playlist
|
title: Playlist
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export class PlayletApi {
|
|||||||
static host = () => `http://${getHost()}`
|
static host = () => `http://${getHost()}`
|
||||||
|
|
||||||
static async getVideoInfo(videoId) {
|
static async getVideoInfo(videoId) {
|
||||||
const response = await fetch(`${PlayletApi.host()}/playlet-invidious-backend/api/v1/videos/${videoId}`);
|
const response = await fetch(`${PlayletApi.host()}/playlet-invidious-backend/api/v1/videos/${videoId}?video_info_batched=true`);
|
||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user