Disable shorts (#620)

* Disable shorts

* Rename setting

* changelog
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2025-05-22 22:13:44 -04:00
1 parent 6d9117a2a0
commit eb67d9e4c0
10 files changed
+200 -47

No files matched your search

+4 -1
View File
@@ -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
@@ -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]
@@ -5,6 +5,7 @@
<field id="isSubscribed" type="boolean" onChange="OnSubscriptionChanged" />
<field id="appController" type="node" bind="/AppController" />
<field id="invidious" type="node" bind="/Invidious" />
<field id="preferences" type="node" bind="/Preferences" />
<field id="bookmarksService" type="node" bind="/BookmarksService" />
<function name="ShowSortDialog" />
</interface>
@@ -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
@@ -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 = ""
@@ -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
@@ -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
}
+14
View File
@@ -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",
@@ -768,6 +768,22 @@
<source>The backend used for browsing and playing videos.</source>
<translation>The backend used for browsing and playing videos.</translation>
</message>
<message>
<source>Content Feed</source>
<translation>Content Feed</translation>
</message>
<message>
<source>Feed preferences</source>
<translation>Feed preferences</translation>
</message>
<message>
<source>Disable Shorts</source>
<translation>Disable Shorts</translation>
</message>
<message>
<source>Disable short videos.</source>
<translation>Disable short videos.</translation>
</message>
<message>
<source>Invidious preferences</source>
<translation>Invidious preferences</translation>
+5
View File
@@ -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"