diff --git a/CHANGELOG.md b/CHANGELOG.md
index dba9a952..8e56e11c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [Unreleased]
+
+### Fixed
+
+- Watch history now has more info (title, channel, duration)
+
## [0.35.1] - 2024-12-26
### Added
diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs
index 0ae4829d..9a173170 100644
--- a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs
+++ b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs
@@ -38,7 +38,7 @@ namespace InnertubeService
nextRequest = invalid
nextResponse = invalid
if fetchNext
- nextRequest = Innertube.CreateNextRequest(videoId, ctt)
+ nextRequest = Innertube.CreateNextRequest(videoId, "", ctt)
nextRequest.Cancellation(cancellation)
nextRequest.Send()
end if
@@ -74,6 +74,60 @@ namespace InnertubeService
return playerResponse
end function
+ function GetVideoInfoBatched(videoIds as object, options = invalid as object) as object
+ if not IsArray(videoIds) or videoIds.Count() = 0
+ return []
+ end if
+
+ cancellation = invalid
+ retry = true
+
+ if options <> invalid
+ if options.DoesExist("cancellation")
+ cancellation = options.cancellation
+ end if
+ if options.DoesExist("retry")
+ retry = options.retry
+ end if
+ end if
+
+ params = Innertube.GetEncodedNextParams(videoIds)
+ request = Innertube.CreateNextRequest("", params, "")
+ request.Cancellation(cancellation)
+
+ response = request.Await()
+ if not response.IsSuccess()
+ return []
+ end if
+
+ responseData = ObjectUtils.Dig(response.Json(), ["contents", "twoColumnWatchNextResults", "playlist", "playlist"])
+ if responseData = invalid
+ ' Sometimes the response doesn't contain a playlist.
+ ' The theory here is that Innertube creates a playlist for the videoIds, and sometimes
+ ' it chooses to respond without the playlist (perhaps to avoid slow responses).
+ ' A retry after a short sleep usually fixes this.
+ if retry
+ LogWarn("Response data missing playlist. Retrying in a bit...")
+ newOptions = {}
+ if options <> invalid
+ newOptions.Append(options)
+ end if
+ newOptions["retry"] = false
+ sleep(200 + Rnd(500))
+ return GetVideoInfoBatched(videoIds, newOptions)
+ else
+ LogWarn("Response data missing playlist. Not retrying.")
+ end if
+ end if
+
+ feeds = Innertube.ParseResponse(responseData)
+ if feeds.Count() > 0
+ return ValidArray(feeds[0].items)
+ end if
+
+ return []
+ end function
+
function SearchSuggestions(q as string, cancellation = invalid as object) as object
suggestions = Innertube.SearchSuggestions(q, cancellation)
if suggestions = invalid
diff --git a/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs b/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs
index b5ee6fec..defda88b 100644
--- a/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs
+++ b/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs
@@ -1,13 +1,27 @@
+import "pkg:/components/Services/Innertube/Context.bs"
+import "pkg:/components/Services/Innertube/protos/params.proto.gen.bs"
+import "pkg:/source/services/HttpClient.bs"
+import "pkg:/source/utils/Logging.bs"
+import "pkg:/source/utils/ObjectUtils.bs"
+import "pkg:/source/utils/Types.bs"
+
namespace Innertube
- function CreateNextRequest(videoId as string, ctt as string) as object
+ function CreateNextRequest(videoId as string, params as string, ctt as string) as object
deviceInfo = CreateObject("roDeviceInfo")
payload = {
- "videoId": videoId
"context": Innertube.CreateContext(Innertube.ClientType.Web, deviceInfo, ctt)
}
+ if videoId <> ""
+ payload["videoId"] = videoId
+ end if
+
+ if params <> ""
+ payload["params"] = params
+ end if
+
request = HttpClient.PostJson("https://www.youtube.com/youtubei/v1/next?prettyPrint=false&alt=json", payload)
request.Headers({
"accept": "*/*"
@@ -20,6 +34,16 @@ namespace Innertube
return request
end function
+ function GetEncodedNextParams(videoIds as object) as string
+ if not IsArray(videoIds) or videoIds.Count() = 0
+ return ""
+ end if
+
+ return Protobuf.Generated.misc.encodeNextParams({
+ "video_id": videoIds
+ })
+ end function
+
function ParseInnertubeNextResponse(payload as object, parsedResponse as object) as object
if not parsedResponse.Success
LogWarn("Invalid parsed response", parsedResponse)
diff --git a/playlet-lib/src/components/Services/Innertube/NodesParser.bs b/playlet-lib/src/components/Services/Innertube/NodesParser.bs
index e5424386..fe3260fb 100644
--- a/playlet-lib/src/components/Services/Innertube/NodesParser.bs
+++ b/playlet-lib/src/components/Services/Innertube/NodesParser.bs
@@ -45,6 +45,7 @@ namespace Innertube
"gridVideoRenderer": ParseGridVideoRenderer
"channelVideoPlayerRenderer": ParseChannelVideoPlayerRenderer
"playlistVideoRenderer": ParsePlaylistVideoRenderer
+ "playlistPanelVideoRenderer": ParsePlaylistPanelVideoRenderer
"channelRenderer": ParseChannelRenderer
"gridChannelRenderer": ParseGridChannelRenderer
"playlistRenderer": ParsePlaylistRenderer
@@ -69,6 +70,9 @@ namespace Innertube
"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
+ ' Obviously ignored.
"clickTrackingParams": ParseNotImplemented
}
end function
@@ -380,6 +384,62 @@ namespace Innertube
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 ParseChannelRenderer(nodeData as object, context as object) as object
channelId = nodeData["channelId"]
if not IsString(channelId)
diff --git a/playlet-lib/src/components/Services/Innertube/protos/params.proto b/playlet-lib/src/components/Services/Innertube/protos/params.proto
index 41e30e18..b0e7e13f 100644
--- a/playlet-lib/src/components/Services/Innertube/protos/params.proto
+++ b/playlet-lib/src/components/Services/Innertube/protos/params.proto
@@ -56,3 +56,8 @@ message SearchFilter {
optional Filters filters = 2;
}
+
+// https://github.com/LuanRT/YouTube.js/blob/5f83a7416d5dc3167e6af2767e9b90f4bf89f3dc/protos/misc/params.proto#L229-L231
+message NextParams {
+ repeated string video_id = 5;
+}
\ No newline at end of file
diff --git a/playlet-lib/src/components/Services/Innertube/protos/params.proto.gen.bs b/playlet-lib/src/components/Services/Innertube/protos/params.proto.gen.bs
index c02fec65..5a0bc4ac 100644
--- a/playlet-lib/src/components/Services/Innertube/protos/params.proto.gen.bs
+++ b/playlet-lib/src/components/Services/Innertube/protos/params.proto.gen.bs
@@ -1,5 +1,5 @@
' Auto-generated file - do not modify manually
-' md5:dfefe3075a9c6332b6072e7c02fdccf8
+' md5:ab48a52d517ca819a9720973f690d0e5
import "pkg:/source/Protobuf/BinaryReader.bs"
import "pkg:/source/Protobuf/BinaryWriter.bs"
@@ -131,6 +131,23 @@ namespace Protobuf
end if
end function
+ function encodeNextParams(message as dynamic, asByteArray = false as boolean) as dynamic
+ buffer = CreateObject("roByteArray")
+ writer = new Protobuf.BinaryWriter()
+ writer.SetBuffer(buffer)
+ encoder = new Protobuf.Encoder(writer)
+ if message.DoesExist("video_id")
+ for each value in message["video_id"]
+ encoder.EncodeString(5, value)
+ end for
+ end if
+ if asByteArray
+ return buffer
+ else
+ return buffer.ToBase64String().EncodeUriComponent()
+ end if
+ end function
+
end namespace
diff --git a/playlet-lib/src/components/Services/Innertube/tests/InnertubeTestNode.xml b/playlet-lib/src/components/Services/Innertube/tests/InnertubeTestNode.xml
new file mode 100644
index 00000000..62ca5036
--- /dev/null
+++ b/playlet-lib/src/components/Services/Innertube/tests/InnertubeTestNode.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/playlet-lib/src/components/Services/Innertube/tests/SearchFiltersTestNode.xml b/playlet-lib/src/components/Services/Innertube/tests/SearchFiltersTestNode.xml
deleted file mode 100644
index d22c3d67..00000000
--- a/playlet-lib/src/components/Services/Innertube/tests/SearchFiltersTestNode.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs
index 48ad68b8..f5e0698c 100644
--- a/playlet-lib/src/components/Services/Invidious/InvidiousService.bs
+++ b/playlet-lib/src/components/Services/Invidious/InvidiousService.bs
@@ -1,4 +1,5 @@
import "pkg:/components/Dialog/DialogUtils.bs"
+import "pkg:/components/Services/Innertube/InnertubeService.bs"
import "pkg:/components/VideoFeed/PaginationType.bs"
import "pkg:/source/AsyncTask/AsyncTask.bs"
import "pkg:/source/AsyncTask/Tasks.bs"
@@ -562,22 +563,39 @@ namespace Invidious
end if
json = response.Json()
- if json = invalid
+ if not IsArray(json)
return invalid
end if
videos = []
- for each item in json
- videos.push({
- "type": "video"
- "videoId": item
- "videoThumbnails": [{
- "quality": "medium"
- "url": `https://i.ytimg.com/vi/${item}/mqdefault.jpg`
- "width": 320
- "height": 180
- }]
- })
+ if json.Count() = 0
+ return {
+ items: videos
+ }
+ end if
+
+ videoMetadata = InnertubeService.GetVideoInfoBatched(json)
+ videoDictionary = {}
+ for each video in videoMetadata
+ videoDictionary[video.videoId] = video
+ end for
+
+ for each videoId in json
+ video = videoDictionary[videoId]
+ if video = invalid
+ video = {
+ "type": "video"
+ "videoId": videoId
+ "videoThumbnails": [{
+ "quality": "medium"
+ "url": `https://i.ytimg.com/vi/${videoId}/mqdefault.jpg`
+ "width": 320
+ "height": 180
+ }]
+ }
+ end if
+
+ videos.push(video)
end for
return {
diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs
index 37856377..f61114d4 100644
--- a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs
+++ b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs
@@ -177,7 +177,7 @@ namespace InvidiousContent
end function
function VideoIsUpcoming(videoItem as object) as boolean
- return videoItem.isUpcoming = true and ValidInt(videoItem.premiereTimestamp) <> 0
+ return videoItem.isUpcoming = true
end function
function VideoSetPremiereTimestampText(node as object, videoItem as object) as void
@@ -185,8 +185,8 @@ namespace InvidiousContent
node.isUpcoming = true
timestamp = videoItem.premiereTimestamp
- if timestamp = invalid
- node.premiereTimestampText = "N/A"
+ if not IsInt(timestamp)
+ node.premiereTimestampText = ""
return
end if
diff --git a/playlet-lib/src/source/components/tests/NextParams.spec.bs b/playlet-lib/src/source/components/tests/NextParams.spec.bs
new file mode 100644
index 00000000..b005256e
--- /dev/null
+++ b/playlet-lib/src/source/components/tests/NextParams.spec.bs
@@ -0,0 +1,27 @@
+namespace Tests
+
+ @SGNode("InnertubeTestNode")
+ @suite
+ class NextParamsTests extends Rooibos.BaseTestSuite
+
+ @describe("NextParams")
+
+ @it("Encodes next params")
+ function _()
+ testCases = m.GetEncodingTestCases()
+ for each testCase in testCases
+ encoded = m.top@.Innertube_GetEncodedNextParams(testCase.input)
+ m.assertEqual(encoded, testCase.encoded)
+ end for
+ end function
+
+ function GetEncodingTestCases() as object
+ return [{
+ input: ["jNQXAC9IVRw", "9bZkp7q19f0"]
+ encoded: "KgtqTlFYQUM5SVZSdyoLOWJaa3A3cTE5ZjA%3D"
+ }]
+ end function
+
+ end class
+
+end namespace
diff --git a/playlet-lib/src/source/components/tests/SearchFilters.spec.bs b/playlet-lib/src/source/components/tests/SearchFilters.spec.bs
index 7160dab5..12952bd4 100644
--- a/playlet-lib/src/source/components/tests/SearchFilters.spec.bs
+++ b/playlet-lib/src/source/components/tests/SearchFilters.spec.bs
@@ -1,6 +1,6 @@
namespace Tests
- @SGNode("SearchFiltersTestNode")
+ @SGNode("InnertubeTestNode")
@suite
class SearchFiltersTests extends Rooibos.BaseTestSuite