diff --git a/CHANGELOG.md b/CHANGELOG.md index d361de38..88a917d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- Nothing worth mentioning yet. +### Added + +- New settings category: `Content Feed` + - New setting: `Disable Shorts` ## [0.38.2] - 2025-05-22 diff --git a/playlet-lib/src/components/ChannelView/ChannelView.bs b/playlet-lib/src/components/ChannelView/ChannelView.bs index bbfb4a24..c712880c 100644 --- a/playlet-lib/src/components/ChannelView/ChannelView.bs +++ b/playlet-lib/src/components/ChannelView/ChannelView.bs @@ -101,9 +101,16 @@ function CreateChannelFeeds(authorId as string, author as string, tabs as object return invalid end if + disableShorts = m.preferences["content_feed.disable_shorts"] + feeds = [] for i = 0 to tabs.count() - 1 tabName = tabs[i] + if tabName = "shorts" and disableShorts + LogInfo(`Skipping "Shorts" tab based on user settings`) + continue for + end if + if m.tabs.DoesExist(tabName) if tabsParams <> invalid and tabsParams.DoesExist(tabName) params = tabsParams[tabName] diff --git a/playlet-lib/src/components/ChannelView/ChannelView.xml b/playlet-lib/src/components/ChannelView/ChannelView.xml index 6d8bee4d..561b370a 100644 --- a/playlet-lib/src/components/ChannelView/ChannelView.xml +++ b/playlet-lib/src/components/ChannelView/ChannelView.xml @@ -5,6 +5,7 @@ + diff --git a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs index 8bc9e97a..9fd4e099 100644 --- a/playlet-lib/src/components/Services/Innertube/InnertubeService.bs +++ b/playlet-lib/src/components/Services/Innertube/InnertubeService.bs @@ -182,32 +182,13 @@ namespace InnertubeService end function function Search(query as string, options = invalid as object) as object - searchFilters = invalid - continuation = "" - cancellation = invalid - raw = false - - if options <> invalid - if options.DoesExist("searchFilters") - searchFilters = options.searchFilters - end if - if options.DoesExist("continuation") - continuation = options.continuation - end if - if options.DoesExist("cancellation") - cancellation = options.cancellation - end if - if options.DoesExist("raw") - raw = options.raw - end if - end if - - return Innertube.Search(query, searchFilters, continuation, cancellation, raw) + return Innertube.Search(query, options) end function function GetTrending(options = invalid as object) as object cancellation = invalid params = "" + disableShorts = false raw = false if options <> invalid @@ -228,6 +209,9 @@ namespace InnertubeService params = "4gIKGgh0cmFpbGVycw%3D%3D" end if end if + if options.DoesExist("disableShorts") + disableShorts = options.disableShorts + end if if options.DoesExist("raw") raw = options.raw end if @@ -252,7 +236,10 @@ namespace InnertubeService return response.Json() end if - feeds = Innertube.ParseResponseDataForFeeds(response.Json(), { skipCreatorOnTheRise: true }) + feeds = Innertube.ParseResponseDataForFeeds(response.Json(), { + disableCreatorOnTheRise: true + disableShorts: disableShorts + }) result = { feeds: feeds @@ -286,6 +273,7 @@ namespace InnertubeService cancellation = invalid accessToken = invalid continuation = "" + disableShorts = false if options <> invalid if options.DoesExist("cancellation") @@ -297,6 +285,9 @@ namespace InnertubeService if options.DoesExist("continuation") continuation = options.continuation end if + if options.DoesExist("disableShorts") + disableShorts = options.disableShorts + end if end if request = Innertube.CreateBrowseRequest(browserId, Innertube.ClientType.Tv, "", continuation) @@ -312,7 +303,7 @@ namespace InnertubeService } end if - feeds = Innertube.ParseResponseDataForFeeds(response.Json()) + feeds = Innertube.ParseResponseDataForFeeds(response.Json(), { disableShorts: disableShorts }) result = { feeds: feeds diff --git a/playlet-lib/src/components/Services/Innertube/NodesParser.bs b/playlet-lib/src/components/Services/Innertube/NodesParser.bs index 054370b9..210b223f 100644 --- a/playlet-lib/src/components/Services/Innertube/NodesParser.bs +++ b/playlet-lib/src/components/Services/Innertube/NodesParser.bs @@ -156,13 +156,13 @@ namespace Innertube end function function ParseShelfRenderer(nodeData as object, context as object) as object - if context.skipCreatorOnTheRise = true + if context.disableCreatorOnTheRise = true badges = nodeData["badges"] if IsArray(badges) for each badge in badges if ValidString(ObjectUtils.Dig(badge, ["metadataBadgeRenderer", "style"])) = "BADGE_STYLE_TYPE_FEATURED" label = ParseText(ObjectUtils.Dig(badge, ["metadataBadgeRenderer", "label"])) - LogInfo(`Skipping 'Create on the Rise' shelf (${label})`) + LogInfo(`Skipping 'Creator on the Rise' shelf (${label})`) return invalid end if end for @@ -179,7 +179,11 @@ namespace Innertube return nodeData["contents"] end function - function ParseReelShelfRenderer(nodeData as object, _context as object) as object + function ParseReelShelfRenderer(nodeData as object, context as object) as object + if context.disableShorts = true + LogInfo("Skipping ReelShelfRenderer based on user settings") + return invalid + end if ' TODO: handle reelShelfRenderer.title return nodeData["items"] end function @@ -276,20 +280,33 @@ namespace Innertube end if end if - liveNow = ValidString(ObjectUtils.Dig(nodeData, ["badges", 0, "metadataBadgeRenderer", "icon", "iconType"])) = "LIVE" - if not liveNow - thumbnailOverlays = nodeData["thumbnailOverlays"] - if IsArray(thumbnailOverlays) - for each overlay in thumbnailOverlays - if ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "LIVE" - liveNow = true - exit for + isUpcoming = false + liveNow = false + + thumbnailOverlays = nodeData["thumbnailOverlays"] + if IsArray(thumbnailOverlays) + for each overlay in thumbnailOverlays + parsedTimeStatusRenderer = ParseThumbnailOverlayTimeStatusRenderer(overlay) + if parsedTimeStatusRenderer = invalid + continue for + end if + + if parsedTimeStatusRenderer.isShort + if context.disableShorts = true + LogInfo("Skipping Short based on user settings") + return invalid end if - end for - end if + end if + + liveNow = liveNow or parsedTimeStatusRenderer.isLive + isUpcoming = isUpcoming or parsedTimeStatusRenderer.isUpcoming + end for + end if + + if ValidString(ObjectUtils.Dig(nodeData, ["badges", 0, "metadataBadgeRenderer", "icon", "iconType"])) = "LIVE" + liveNow = true end if - isUpcoming = false premiereTimestamp = ObjectUtils.Dig(nodeData, ["upcomingEventData", "startTime"]) if IsString(premiereTimestamp) premiereTimestamp = premiereTimestamp.ToInt() @@ -362,7 +379,11 @@ namespace Innertube thumbnailOverlays = nodeData["thumbnailOverlays"] if IsArray(thumbnailOverlays) for each overlay in thumbnailOverlays - lengthText = ParseText(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "text"])) + parsedTimeStatusRenderer = ParseThumbnailOverlayTimeStatusRenderer(overlay) + if parsedTimeStatusRenderer = invalid + continue for + end if + lengthText = parsedTimeStatusRenderer.text if lengthText <> "" exit for end if @@ -518,8 +539,20 @@ namespace Innertube 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") + parsedTimeStatusRenderer = ParseThumbnailOverlayTimeStatusRenderer(overlay) + if parsedTimeStatusRenderer = invalid + continue for + end if + + 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 for end if @@ -869,6 +902,11 @@ namespace Innertube end function function ParseShortsLockupViewModel(nodeData as object, context as object) as object + if context.disableShorts = true + LogInfo("Skipping Short based on user settings") + return invalid + end if + videoId = ObjectUtils.Dig(nodeData, ["onTap", "innertubeCommand", "reelWatchEndpoint", "videoId"]) if not IsString(videoId) LogWarn("Invalid video ID", nodeData) @@ -978,17 +1016,32 @@ namespace Innertube thumbnailOverlays = ObjectUtils.Dig(nodeData, ["header", "tileHeaderRenderer", "thumbnailOverlays"]) if IsArray(thumbnailOverlays) for each overlay in thumbnailOverlays - maybeLengthText = ParseText(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "text"])) + parsedTimeStatusRenderer = ParseThumbnailOverlayTimeStatusRenderer(overlay) + if parsedTimeStatusRenderer = invalid + continue for + end if + + if parsedTimeStatusRenderer.isShort + if context.disableShorts = true + LogInfo("Skipping Short based on user settings") + return invalid + end if + end if + + maybeLengthText = parsedTimeStatusRenderer.text if maybeLengthText <> "" lengthText = maybeLengthText end if + + liveNow = liveNow or parsedTimeStatusRenderer.isLive + isUpcoming = isUpcoming or parsedTimeStatusRenderer.isUpcoming + maybePercentDurationWatched = ObjectUtils.Dig(overlay, ["thumbnailOverlayResumePlaybackRenderer", "percentDurationWatched"]) if maybePercentDurationWatched <> invalid percentDurationWatched = maybePercentDurationWatched end if - liveNow = liveNow or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "LIVE") - isUpcoming = isUpcoming or (ValidString(ObjectUtils.Dig(overlay, ["thumbnailOverlayTimeStatusRenderer", "style"])) = "UPCOMING") end for + if liveNow or isUpcoming lengthText = "" end if @@ -1022,6 +1075,11 @@ namespace Innertube end function function TileRendererTypeShorts(nodeData as object, context as object) as object + if context.disableShorts = true + LogInfo("Skipping Short based on user settings") + return invalid + end if + videoId = nodeData["contentId"] if not IsString(videoId) LogWarn("Invalid video ID", nodeData) @@ -1204,6 +1262,34 @@ namespace Innertube return ParseText(data["text"]) end function + function ParseThumbnailOverlayTimeStatusRenderer(data as object) as object + if data = invalid + return invalid + end if + if not IsAssociativeArray(data) or not data.DoesExist("thumbnailOverlayTimeStatusRenderer") + return invalid + end if + + renderer = data["thumbnailOverlayTimeStatusRenderer"] + if not IsAssociativeArray(renderer) + return invalid + end if + + text = ParseText(renderer["text"]) + + overlayStyle = ValidString(renderer["style"]) + isLive = overlayStyle = "LIVE" + isUpcoming = overlayStyle = "UPCOMING" + isShort = overlayStyle = "SHORTS" + + return { + "text": text + "isLive": isLive + "isUpcoming": isUpcoming + "isShort": isShort + } + end function + function StartNewFeed(title as string, context as object) as void if context.currentFeed <> invalid if context.currentFeed.items.Count() = 0 and context.currentFeed.title = "" diff --git a/playlet-lib/src/components/Services/Innertube/SearchEndpoint.bs b/playlet-lib/src/components/Services/Innertube/SearchEndpoint.bs index ed2d28a9..da2cfd60 100644 --- a/playlet-lib/src/components/Services/Innertube/SearchEndpoint.bs +++ b/playlet-lib/src/components/Services/Innertube/SearchEndpoint.bs @@ -6,7 +6,31 @@ import "pkg:/source/utils/Types.bs" namespace Innertube - function Search(query as string, searchFilters as object, continuation = "" as string, cancellation = invalid as object, raw = false as boolean) as object + function Search(query as string, options = invalid as object) as object + searchFilters = invalid + continuation = "" + cancellation = invalid + disableShorts = false + raw = false + + if options <> invalid + if options.DoesExist("searchFilters") + searchFilters = options.searchFilters + end if + if options.DoesExist("continuation") + continuation = options.continuation + end if + if options.DoesExist("cancellation") + cancellation = options.cancellation + end if + if options.DoesExist("disableShorts") + disableShorts = options.disableShorts + end if + if options.DoesExist("raw") + raw = options.raw + end if + end if + deviceInfo = CreateObject("roDeviceInfo") payload = { @@ -51,7 +75,7 @@ namespace Innertube return response.Json() end if - feeds = ParseResponseDataForFeeds(response.Json()) + feeds = ParseResponseDataForFeeds(response.Json(), { disableShorts: disableShorts }) result = { feeds: feeds diff --git a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs index 04e55444..bb1d3cdc 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/Middleware/PlayletInvidiousBackendRouter.bs @@ -8,7 +8,9 @@ namespace Http function new(server as object) super() - m.innertube = server.task.innertube + task = server.task + m.innertube = task.innertube + m.preferences = task.preferences end function @get("/playlet-invidious-backend/authorize_token") @@ -65,6 +67,7 @@ namespace Http options = { "accessToken": accessToken.Mid("Bearer ".Len()) + "disableShorts": m.preferences["content_feed.disable_shorts"] } continuation = request.query.continuation if not StringUtils.IsNullOrEmpty(continuation) @@ -247,6 +250,7 @@ namespace Http raw = request.query.raw <> invalid options = { + "disableShorts": m.preferences["content_feed.disable_shorts"] raw: raw type: request.query.type } @@ -295,6 +299,7 @@ namespace Http options = { "accessToken": accessToken.Mid("Bearer ".Len()) + "disableShorts": m.preferences["content_feed.disable_shorts"] } continuation = request.query.continuation @@ -360,6 +365,7 @@ namespace Http raw = request.query.raw <> invalid options = { + "disableShorts": m.preferences["content_feed.disable_shorts"] raw: raw } diff --git a/playlet-lib/src/config/preferences.json5 b/playlet-lib/src/config/preferences.json5 index 695e5de0..06ad11ef 100644 --- a/playlet-lib/src/config/preferences.json5 +++ b/playlet-lib/src/config/preferences.json5 @@ -53,6 +53,20 @@ }, ], }, + { + displayText: "Content Feed", + key: "content_feed", + description: "Feed preferences", + children: [ + { + displayText: "Disable Shorts", + key: "content_feed.disable_shorts", + description: "Disable short videos.", + type: "boolean", + defaultValue: false, + }, + ], + }, { displayText: "Invidious", key: "invidious", diff --git a/playlet-lib/src/locale/en_US/translations.ts b/playlet-lib/src/locale/en_US/translations.ts index 821b894e..b315edb0 100644 --- a/playlet-lib/src/locale/en_US/translations.ts +++ b/playlet-lib/src/locale/en_US/translations.ts @@ -768,6 +768,22 @@ The backend used for browsing and playing videos. The backend used for browsing and playing videos. + + Content Feed + Content Feed + + + Feed preferences + Feed preferences + + + Disable Shorts + Disable Shorts + + + Disable short videos. + Disable short videos. + Invidious preferences Invidious preferences diff --git a/playlet-lib/src/source/utils/Locale.bs b/playlet-lib/src/source/utils/Locale.bs index c9f97e5f..292c8d62 100644 --- a/playlet-lib/src/source/utils/Locale.bs +++ b/playlet-lib/src/source/utils/Locale.bs @@ -250,6 +250,11 @@ namespace Locale SelectedBackend = "Selected backend" SelectedBackendDescription = "The backend used for browsing and playing videos." + ContentFeed = "Content Feed" + ContentPreferences = "Feed preferences" + DisableShorts = "Disable Shorts" + DisableShortsDescription = "Disable short videos." + ' "Invidious" is used as node id, so we can't use it before refactoring node ids. ' Either way, Invidious doesn't translate, so it's fine to skip it here ' Invidious = "Invidious"