From 66ce75d62e179c5ce5bf34cfc07c8d2a069c42c2 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Fri, 17 Jan 2025 16:29:36 -0500 Subject: [PATCH] Localize channel tabs from innertube --- CHANGELOG.md | 4 ++ .../src/components/ChannelView/ChannelView.bs | 61 +++++++++++++------ .../ContentNode/ChannelContentNode.xml | 1 + .../components/Services/Innertube/Context.bs | 10 ++- .../components/Services/Innertube/Parser.bs | 16 +++-- .../Invidious/InvidiousToContentNode.bs | 1 + 6 files changed, 68 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 038f9d39..3f7724f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ 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] + +- Nothing worth mentioning yet. + ## [0.36.0] - 2025-01-16 ### Added diff --git a/playlet-lib/src/components/ChannelView/ChannelView.bs b/playlet-lib/src/components/ChannelView/ChannelView.bs index 25d61223..d15bdac6 100644 --- a/playlet-lib/src/components/ChannelView/ChannelView.bs +++ b/playlet-lib/src/components/ChannelView/ChannelView.bs @@ -92,11 +92,11 @@ function OnContentSet() as void if (authorId <> m.authorId or author <> m.author) and IsArray(content.tabs) m.authorId = authorId m.author = author - m.rowList.feeds = CreateChannelFeeds(m.authorId, author, content.tabs, content.tabsParams) + m.rowList.feeds = CreateChannelFeeds(m.authorId, author, content.tabs, content.tabsParams, content.tabsTitles) end if end function -function CreateChannelFeeds(authorId as string, author as string, tabs as object, tabsParams as object) as object +function CreateChannelFeeds(authorId as string, author as string, tabs as object, tabsParams as object, tabsTitles as object) as object if authorId = "" return invalid end if @@ -111,7 +111,13 @@ function CreateChannelFeeds(authorId as string, author as string, tabs as object params = "" end if - feeds.Push(m.tabs[tabName](authorId, author, params)) + if tabsTitles <> invalid and tabsTitles.DoesExist(tabName) + title = tabsTitles[tabName] + else + title = "" + end if + + feeds.Push(m.tabs[tabName](authorId, author, title, params)) end if end for @@ -197,26 +203,47 @@ end function function InitializeTabs() m.tabs = { - "videos": function(authorId as string, author as string, params as string) as object - return CreateChannelFeed("Videos", "channel_videos", authorId, author, params) + "videos": function(authorId as string, author as string, title as string, params as string) as object + if StringUtils.IsNullOrEmpty(title) + title = "Videos" + end if + return CreateChannelFeed(title, "channel_videos", authorId, author, params) end function - "shorts": function(authorId as string, author as string, params as string) as object - return CreateChannelFeed("Shorts", "channel_shorts", authorId, author, params) + "shorts": function(authorId as string, author as string, title as string, params as string) as object + if StringUtils.IsNullOrEmpty(title) + title = "Shorts" + end if + return CreateChannelFeed(title, "channel_shorts", authorId, author, params) end function - "streams": function(authorId as string, author as string, params as string) as object - return CreateChannelFeed("Live", "channel_streams", authorId, author, params) + "streams": function(authorId as string, author as string, title as string, params as string) as object + if StringUtils.IsNullOrEmpty(title) + title = "Live" + end if + return CreateChannelFeed(title, "channel_streams", authorId, author, params) end function - "releases": function(authorId as string, author as string, params as string) as object - return CreateChannelFeed("Releases", "channel_releases", authorId, author, params) + "releases": function(authorId as string, author as string, title as string, params as string) as object + if StringUtils.IsNullOrEmpty(title) + title = "Releases" + end if + return CreateChannelFeed(title, "channel_releases", authorId, author, params) end function - "podcasts": function(authorId as string, author as string, params as string) as object - return CreateChannelFeed("Podcasts", "channel_podcasts", authorId, author, params) + "podcasts": function(authorId as string, author as string, title as string, params as string) as object + if StringUtils.IsNullOrEmpty(title) + title = "Podcasts" + end if + return CreateChannelFeed(title, "channel_podcasts", authorId, author, params) end function - "playlists": function(authorId as string, author as string, params as string) as object - return CreateChannelFeed("Playlists", "channel_playlists", authorId, author, params) + "playlists": function(authorId as string, author as string, title as string, params as string) as object + if StringUtils.IsNullOrEmpty(title) + title = "Playlists" + end if + return CreateChannelFeed(title, "channel_playlists", authorId, author, params) end function - "courses": function(authorId as string, author as string, params as string) as object - return CreateChannelFeed("Courses", "channel_courses", authorId, author, params) + "courses": function(authorId as string, author as string, title as string, params as string) as object + if StringUtils.IsNullOrEmpty(title) + title = "Courses" + end if + return CreateChannelFeed(title, "channel_courses", authorId, author, params) end function } end function diff --git a/playlet-lib/src/components/ContentNode/ChannelContentNode.xml b/playlet-lib/src/components/ContentNode/ChannelContentNode.xml index ec1e7474..fb8905f8 100644 --- a/playlet-lib/src/components/ContentNode/ChannelContentNode.xml +++ b/playlet-lib/src/components/ContentNode/ChannelContentNode.xml @@ -18,6 +18,7 @@ + diff --git a/playlet-lib/src/components/Services/Innertube/Context.bs b/playlet-lib/src/components/Services/Innertube/Context.bs index a9faa0d3..c10ce279 100644 --- a/playlet-lib/src/components/Services/Innertube/Context.bs +++ b/playlet-lib/src/components/Services/Innertube/Context.bs @@ -69,7 +69,7 @@ namespace Innertube function CreateContextClientWeb(deviceInfo as object) as object return { - "hl": deviceInfo.GetCurrentLocale() + "hl": GetCurrentLocale(deviceInfo) "gl": GetContentRegion(deviceInfo) "remoteHost": "" "screenDensityFloat": 1 @@ -103,7 +103,7 @@ namespace Innertube function CreateContextClientIOS(deviceInfo as object) as object return { - "hl": deviceInfo.GetCurrentLocale() + "hl": GetCurrentLocale(deviceInfo) "gl": GetContentRegion(deviceInfo) "remoteHost": "" "screenDensityFloat": 1 @@ -129,7 +129,7 @@ namespace Innertube function CreateContextClientTv(deviceInfo as object) as object return { - "hl": deviceInfo.GetCurrentLocale() + "hl": GetCurrentLocale(deviceInfo) "gl": GetContentRegion(deviceInfo) "remoteHost": "" "deviceMake": INNERTUBE_TV_DEVICE_MAKE @@ -159,6 +159,10 @@ namespace Innertube } end function + function GetCurrentLocale(deviceInfo as object) as string + return deviceInfo.GetCurrentLocale() + end function + function GetContentRegion(deviceInfo as object) as string region = deviceInfo.GetUserCountryCode() if region.len() <> 2 or region = "OT" diff --git a/playlet-lib/src/components/Services/Innertube/Parser.bs b/playlet-lib/src/components/Services/Innertube/Parser.bs index ff5bd1fc..23b14835 100644 --- a/playlet-lib/src/components/Services/Innertube/Parser.bs +++ b/playlet-lib/src/components/Services/Innertube/Parser.bs @@ -106,6 +106,7 @@ namespace Innertube tabsNames = [] tabsParams = {} + tabsTitles = {} tabs = ObjectUtils.Dig(responseData, ["contents", "twoColumnBrowseResultsRenderer", "tabs"]) if tabs <> invalid @@ -126,13 +127,17 @@ namespace Innertube continue for end if - tabParams = ObjectUtils.Dig(tabRenderer, ["endpoint", "browseEndpoint", "params"]) - if tabParams = invalid - continue for + tabsNames.Push(tabName) + + tabTitle = tabRenderer["title"] + if IsString(tabTitle) + tabsTitles[tabName] = tabTitle end if - tabsNames.Push(tabName) - tabsParams[tabName] = tabParams + tabParams = ObjectUtils.Dig(tabRenderer, ["endpoint", "browseEndpoint", "params"]) + if IsString(tabParams) + tabsParams[tabName] = tabParams + end if end for end if @@ -154,6 +159,7 @@ namespace Innertube "authorSubTitle": authorSubTitle "tabs": tabsNames "tabsParams": tabsParams + "tabsTitles": tabsTitles "items": items } diff --git a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs index 9f71411f..12a24290 100644 --- a/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs +++ b/playlet-lib/src/components/Services/Invidious/InvidiousToContentNode.bs @@ -134,6 +134,7 @@ namespace InvidiousContent node.banner = GetChannelBanner(item.authorBanners) ' Important: tabsParams should be set first, because settings that tabs triggers the ChannelView to load feeds SetIfExists(node, "tabsParams", item, "tabsParams") + SetIfExists(node, "tabsTitles", item, "tabsTitles") SetIfExists(node, "tabs", item, "tabs") return node