diff --git a/CHANGELOG.md b/CHANGELOG.md index afc8c010..384a1163 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Crash in player when video ID is invalid - [Perf] better caching in Playlet backend +- Mixes in in Playlet backend ## [0.35.2] - 2024-12-27 diff --git a/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml b/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml index 4699bf3b..7abd93ab 100644 --- a/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml +++ b/playlet-lib/src/components/ContentNode/PlaylistContentNode.xml @@ -41,5 +41,7 @@ + + \ No newline at end of file diff --git a/playlet-lib/src/components/ContentNode/PlaylistContentTask.bs b/playlet-lib/src/components/ContentNode/PlaylistContentTask.bs index 2b93befa..220e42b4 100644 --- a/playlet-lib/src/components/ContentNode/PlaylistContentTask.bs +++ b/playlet-lib/src/components/ContentNode/PlaylistContentTask.bs @@ -17,11 +17,19 @@ function PlaylistContentTask(input as object) as object instance = service.GetInstance() while true + playlistId = contentNode.playlistId index = contentNode.getChildCount() continuation = contentNode.continuation hadContinuation = not StringUtils.IsNullOrEmpty(continuation) - response = service.GetPlaylist(contentNode.playlistId, index, continuation, m.top.cancellation) + if playlistId.StartsWith("RD") and not hadContinuation + videoId = contentNode.videoId + if not StringUtils.IsNullOrEmpty(videoId) + continuation = videoId + end if + end if + + response = service.GetPlaylist(playlistId, index, continuation, m.top.cancellation) if m.top.cancel contentNode.loadState = FeedLoadState.None diff --git a/playlet-lib/src/components/PlaylistView/PlaylistViewCell.bs b/playlet-lib/src/components/PlaylistView/PlaylistViewCell.bs index 8340b7d0..3c34a287 100644 --- a/playlet-lib/src/components/PlaylistView/PlaylistViewCell.bs +++ b/playlet-lib/src/components/PlaylistView/PlaylistViewCell.bs @@ -18,15 +18,16 @@ function OnContentSet() as void m.top.author = content._author m.top.thumbnailUri = content.thumbnail - if ValidInt(content.lengthSeconds) <> 0 - SetDurationText(content.lengthText) - m.top.durationRectVisible = true - else - m.top.durationRectVisible = false - end if + SetDurationText(content.lengthText) end function function SetDurationText(text as string) as void + hasText = text <> "" + m.top.durationRectVisible = hasText + if not hasText + return + end if + m.top.duration = text label = m.durationLabel diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs index 2b19d237..2cc04ecc 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": videoId }, ctt) nextRequest.Cancellation(cancellation) nextRequest.Send() end if @@ -92,7 +92,7 @@ namespace InnertubeService end if params = Innertube.GetEncodedNextParams(videoIds) - request = Innertube.CreateNextRequest("", params, "") + request = Innertube.CreateNextRequest({ "params": params }, "") request.Cancellation(cancellation) response = request.Await() @@ -332,6 +332,33 @@ namespace InnertubeService return result end function + function GetMix(mixId as string, options = invalid as object) as object + videoId = "" + cancellation = invalid + + if options <> invalid + if options.DoesExist("videoId") + videoId = options.videoId + end if + if options.DoesExist("cancellation") + cancellation = options.cancellation + end if + end if + + request = Innertube.CreateNextRequest({ "videoId": videoId, "playlistId": mixId }, "") + request.Cancellation(cancellation) + + response = request.Await() + if not response.IsSuccess() + return { + error: response.ErrorMessage() + } + end if + + json = response.Json() + return Innertube.ParseMixPageResponseData(json) + end function + function ResolveUrl(url as string, options = invalid as object) as object cancellation = invalid diff --git a/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs b/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs index a63e0e57..24e69ef4 100644 --- a/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs +++ b/playlet-lib/src/components/Services/Innertube/NextEndpoint.bs @@ -8,20 +8,13 @@ import "pkg:/source/utils/Types.bs" namespace Innertube - function CreateNextRequest(videoId as string, params as string, ctt as string) as object + function CreateNextRequest(payloadArgs as object, ctt as string) as object deviceInfo = CreateObject("roDeviceInfo") payload = { "context": Innertube.CreateContext(Innertube.ClientType.Web, deviceInfo, ctt) } - - if videoId <> "" - payload["videoId"] = videoId - end if - - if params <> "" - payload["params"] = params - end if + payload.Append(payloadArgs) request = HttpClient.PostJson("https://www.youtube.com/youtubei/v1/next?prettyPrint=false&alt=json", payload) headers = { diff --git a/playlet-lib/src/components/Services/Innertube/NodesParser.bs b/playlet-lib/src/components/Services/Innertube/NodesParser.bs index cd76a482..ad215298 100644 --- a/playlet-lib/src/components/Services/Innertube/NodesParser.bs +++ b/playlet-lib/src/components/Services/Innertube/NodesParser.bs @@ -682,6 +682,14 @@ namespace Innertube "videoCountText": videoCountText } + ' Mixes have a videoId, which is the first video in the mix + if playlistId.StartsWith("RD") + videoId = ObjectUtils.Dig(nodeData, ["rendererContext", "commandContext", "onTap", "innertubeCommand", "watchEndpoint", "videoId"]) + if IsString(videoId) + playlist["videoId"] = videoId + end if + end if + PushFeedItem(playlist, context) return invalid end function diff --git a/playlet-lib/src/components/Services/Innertube/Parser.bs b/playlet-lib/src/components/Services/Innertube/Parser.bs index b5d2d1f0..33473a45 100644 --- a/playlet-lib/src/components/Services/Innertube/Parser.bs +++ b/playlet-lib/src/components/Services/Innertube/Parser.bs @@ -224,6 +224,59 @@ namespace Innertube return playlist end function + function ParseMixPageResponseData(responseData as object) as object + if responseData = invalid + return { + error: "Invalid response data" + } + end if + + error = Innertube.ParseResponseDataForError(responseData) + if error <> "" + return { + error: error + } + end if + + playlist = ObjectUtils.Dig(responseData, ["contents", "twoColumnWatchNextResults", "playlist", "playlist"]) + if playlist = invalid + return { + error: "Invalid playlist data" + } + end if + + playlistId = playlist["playlistId"] + + title = ParseText(playlist["title"]) + if title = "" + title = ParseText(playlist["titleText"]) + end if + + author = ParseText(playlist["ownerName"]) + if author = "" + author = ParseText(playlist["shortBylineText"]) + if author = "" + author = ParseText(playlist["longBylineText"]) + end if + end if + + result = { + "playlistId": playlistId + "title": title + "author": author + "videos": [] + "videoCount": -1 + "videoCountText": "" + } + + feeds = ParseResponseDataForFeeds(playlist) + if feeds.Count() > 0 + result["videos"] = ValidArray(feeds[0].items) + end if + + return result + end function + function ParseResponseDataForError(responseData as object) as string if responseData = invalid return "" diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs index f61114d4..85415233 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs @@ -68,9 +68,10 @@ namespace InvidiousContent SetIfExists(node, "description", item, "description") SetIfExists(node, "id", item, "playlistId") SetIfExists(node, "playlistId", item, "playlistId") + SetIfExists(node, "videoId", item, "videoId") SetIfExists(node, "title", item, "title") SetIfExists(node, "videoCount", item, "videoCount") - node.videoCountText = GetVideoCountText(item) + SetVideoCountText(item, node) SetIfExists(node, "viewCount", item, "viewCount") node.viewCountText = PlaylistGetViewCountText(item) SetIfExists(node, "updated", item, "updated") @@ -122,7 +123,7 @@ namespace InvidiousContent SetIfExists(node, "authorSubTitle", item, "authorSubTitle") node.subCountText = GetChannelSubCountText(item) SetIfExists(node, "videoCount", item, "videoCount") - node.videoCountText = GetVideoCountText(item) + SetVideoCountText(item, node) node.thumbnail = GetChannelThumbnail(item.authorThumbnails) node.banner = GetChannelBanner(item.authorBanners) ' Important: tabsParams should be set first, because settings that tabs triggers the ChannelView to load feeds @@ -293,12 +294,17 @@ namespace InvidiousContent return authorBanners[0].url end function - function GetVideoCountText(item as object) as string - if not StringUtils.IsNullOrEmpty(item.videoCountText) - return item.videoCountText + function SetVideoCountText(item as object, node as object) as void + videoCountText = item.videoCountText + if not StringUtils.IsNullOrEmpty(videoCountText) + node.videoCountText = videoCountText + return end if videoCount = ValidInt(item.videoCount) - return LocaleUtils.GetPluralString(videoCount, Locale.RowCell.ZeroVideos, Locale.RowCell.OneVideo, Locale.RowCell.NVideos) + if videoCount = -1 + return + end if + node.videoCountText = LocaleUtils.GetPluralString(videoCount, Locale.RowCell.ZeroVideos, Locale.RowCell.OneVideo, Locale.RowCell.NVideos) end function function GetChannelSubCountText(channel as object) as string diff --git a/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.bs b/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.bs index 55ceb8e1..e8cfbb14 100644 --- a/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.bs +++ b/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.bs @@ -19,16 +19,16 @@ function OnContentSet() as void m.top.thumbnailUri = content.thumbnail - videoCountText = content.videoCountText - if content.videoCount = -1 and videoCountText = "" - m.top.videoCountLabelVisible = false - else - m.top.videoCountLabelVisible = true - SetVideoCount(videoCountText) - end if + SetVideoCount(content.videoCountText) end function function SetVideoCount(videoCountText as string) as void + hasText = videoCountText <> "" + m.top.videoCountRectVisible = hasText + if not hasText + return + end if + m.top.videoCount = videoCountText label = m.videoCountLabel diff --git a/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.xml b/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.xml index f8e92a6f..6dd4e7f8 100644 --- a/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.xml +++ b/playlet-lib/src/components/VideoFeed/VideoRowCell/PlaylistRowCell.xml @@ -7,7 +7,7 @@ - + invalid response.Json(playlist) response.http_code = 500