Playlet backend channel sort options (#649)
* Playlet backend channel sort options * tweak
This commit is contained in:
1 parent
68aeec3d6f
commit
d054dd64a5
7 files changed
+150
-17
No files matched your search
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Channel sort options in Playlet backend (sort videos by Newest, Oldest, Popular)
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- [Perf] reverted a perf fix that wasn't helping
|
- [Perf] reverted a perf fix that wasn't helping
|
||||||
|
|||||||
@@ -349,14 +349,17 @@ function GetSortingContextMenuOptionsForItem(video as object) as object
|
|||||||
end if
|
end if
|
||||||
|
|
||||||
feedSource = feedSources[0]
|
feedSource = feedSources[0]
|
||||||
|
sortOptions = feedSource.state.sortOptions
|
||||||
|
if not IsArray(sortOptions)
|
||||||
endpoint = feedSource.endpoint
|
endpoint = feedSource.endpoint
|
||||||
if not m.sortOptions.DoesExist(endpoint)
|
if not m.sortOptions.DoesExist(endpoint)
|
||||||
return []
|
return []
|
||||||
end if
|
end if
|
||||||
|
|
||||||
title = Tr(Locale.Dialogs.SortFeedBy).replace("%1", `"${feedSource.title}"`)
|
|
||||||
sortOptions = m.sortOptions[endpoint]
|
sortOptions = m.sortOptions[endpoint]
|
||||||
|
end if
|
||||||
|
|
||||||
|
title = Tr(Locale.Dialogs.SortFeedBy).replace("%1", `"${feedSource.title}"`)
|
||||||
return [ContextMenuUtils.CreateOption(title + "...", m.top, "ShowSortDialog", [title, sortOptions, feedContentNode])]
|
return [ContextMenuUtils.CreateOption(title + "...", m.top, "ShowSortDialog", [title, sortOptions, feedContentNode])]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|||||||
@@ -81,8 +81,10 @@ namespace Innertube
|
|||||||
"gridRenderer": ParseGridRenderer
|
"gridRenderer": ParseGridRenderer
|
||||||
"richGridRenderer": ParseRichGridRenderer
|
"richGridRenderer": ParseRichGridRenderer
|
||||||
"richItemRenderer": ParseRichItemRenderer
|
"richItemRenderer": ParseRichItemRenderer
|
||||||
|
"feedFilterChipBarRenderer": ParseFeedFilterChipBarRenderer
|
||||||
"continuationItemRenderer": ParseContinuationItemRenderer
|
"continuationItemRenderer": ParseContinuationItemRenderer
|
||||||
"appendContinuationItemsAction": ParseAppendContinuationItemsAction
|
"appendContinuationItemsAction": ParseAppendContinuationItemsAction
|
||||||
|
"reloadContinuationItemsCommand": ParseReloadContinuationItemsCommand
|
||||||
"gridContinuation": ParseGridContinuation
|
"gridContinuation": ParseGridContinuation
|
||||||
"tvSurfaceContentContinuation": ParseTvSurfaceContentContinuation
|
"tvSurfaceContentContinuation": ParseTvSurfaceContentContinuation
|
||||||
' Ignored nodes:
|
' Ignored nodes:
|
||||||
@@ -144,7 +146,26 @@ namespace Innertube
|
|||||||
return nodeData["content"]
|
return nodeData["content"]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function ParseSectionListRenderer(nodeData as object, _context as object) as object
|
function ParseSectionListRenderer(nodeData as object, context as object) as object
|
||||||
|
sortSubMenuItems = ObjectUtils.Dig(nodeData, ["subMenu", "channelSubMenuRenderer", "sortSetting", "sortFilterSubMenuRenderer", "subMenuItems"])
|
||||||
|
if IsArray(sortSubMenuItems)
|
||||||
|
sortOptions = []
|
||||||
|
for each item in sortSubMenuItems
|
||||||
|
params = ValidString(ObjectUtils.Dig(item, ["navigationEndpoint", "browseEndpoint", "params"]))
|
||||||
|
title = ParseText(item["title"])
|
||||||
|
isSelected = ValidBool(item["selected"])
|
||||||
|
if params <> "" and title <> ""
|
||||||
|
sortOptions.Push({
|
||||||
|
"title": title
|
||||||
|
"params": params
|
||||||
|
"isSelected": isSelected
|
||||||
|
})
|
||||||
|
end if
|
||||||
|
end for
|
||||||
|
if sortOptions.Count() > 0
|
||||||
|
context.currentFeed.sortOptions = sortOptions
|
||||||
|
end if
|
||||||
|
end if
|
||||||
return nodeData["contents"]
|
return nodeData["contents"]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -1198,7 +1219,11 @@ namespace Innertube
|
|||||||
return nodeData["items"]
|
return nodeData["items"]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function ParseRichGridRenderer(nodeData as object, _context as object) as object
|
function ParseRichGridRenderer(nodeData as object, context as object) as object
|
||||||
|
feedFilterChipBarRenderer = ObjectUtils.Dig(nodeData, ["header", "feedFilterChipBarRenderer"])
|
||||||
|
if feedFilterChipBarRenderer <> invalid
|
||||||
|
ParseFeedFilterChipBarRenderer(feedFilterChipBarRenderer, context)
|
||||||
|
end if
|
||||||
return nodeData["contents"]
|
return nodeData["contents"]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
@@ -1206,6 +1231,47 @@ namespace Innertube
|
|||||||
return nodeData["content"]
|
return nodeData["content"]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function ParseFeedFilterChipBarRenderer(nodeData as object, context as object) as object
|
||||||
|
contents = ObjectUtils.Dig(nodeData, ["contents"])
|
||||||
|
if not IsArray(contents)
|
||||||
|
return invalid
|
||||||
|
end if
|
||||||
|
|
||||||
|
sortOptions = []
|
||||||
|
for each item in contents
|
||||||
|
if not IsAssociativeArray(item) or not item.DoesExist("chipCloudChipRenderer")
|
||||||
|
continue for
|
||||||
|
end if
|
||||||
|
chipCloudChipRenderer = item["chipCloudChipRenderer"]
|
||||||
|
if not IsAssociativeArray(chipCloudChipRenderer)
|
||||||
|
continue for
|
||||||
|
end if
|
||||||
|
continuationCommand = ObjectUtils.Dig(chipCloudChipRenderer, ["navigationEndpoint", "continuationCommand"])
|
||||||
|
if not IsAssociativeArray(continuationCommand) or ValidString(continuationCommand["request"]) <> "CONTINUATION_REQUEST_TYPE_BROWSE"
|
||||||
|
continue for
|
||||||
|
end if
|
||||||
|
|
||||||
|
title = ParseText(chipCloudChipRenderer["text"])
|
||||||
|
token = ValidString(continuationCommand["token"])
|
||||||
|
isSelected = ValidBool(chipCloudChipRenderer["isSelected"])
|
||||||
|
if title = "" or token = ""
|
||||||
|
continue for
|
||||||
|
end if
|
||||||
|
|
||||||
|
sortOptions.Push({
|
||||||
|
"title": title
|
||||||
|
"continuation": token
|
||||||
|
"isSelected": isSelected
|
||||||
|
})
|
||||||
|
end for
|
||||||
|
|
||||||
|
if sortOptions.Count() > 0
|
||||||
|
context.currentFeed.sortOptions = sortOptions
|
||||||
|
end if
|
||||||
|
|
||||||
|
return invalid
|
||||||
|
end function
|
||||||
|
|
||||||
function ParseContinuationItemRenderer(nodeData as object, context as object) as object
|
function ParseContinuationItemRenderer(nodeData as object, context as object) as object
|
||||||
continuation = ObjectUtils.Dig(nodeData, ["continuationEndpoint", "continuationCommand", "token"])
|
continuation = ObjectUtils.Dig(nodeData, ["continuationEndpoint", "continuationCommand", "token"])
|
||||||
if IsString(continuation)
|
if IsString(continuation)
|
||||||
@@ -1222,6 +1288,10 @@ namespace Innertube
|
|||||||
return nodeData["continuationItems"]
|
return nodeData["continuationItems"]
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
function ParseReloadContinuationItemsCommand(nodeData as object, _context as object) as object
|
||||||
|
return nodeData["continuationItems"]
|
||||||
|
end function
|
||||||
|
|
||||||
function ParseGridContinuation(nodeData as object, context as object) as object
|
function ParseGridContinuation(nodeData as object, context as object) as object
|
||||||
continuation = ObjectUtils.Dig(nodeData, ["continuations", 0, "nextContinuationData", "continuation"])
|
continuation = ObjectUtils.Dig(nodeData, ["continuations", 0, "nextContinuationData", "continuation"])
|
||||||
if IsString(continuation)
|
if IsString(continuation)
|
||||||
|
|||||||
@@ -141,12 +141,16 @@ namespace Innertube
|
|||||||
|
|
||||||
items = []
|
items = []
|
||||||
continuation = invalid
|
continuation = invalid
|
||||||
|
sortOptions = invalid
|
||||||
feeds = ParseResponseDataForFeeds(responseData, { "currentAuthor": author, "currentAuthorId": authorId })
|
feeds = ParseResponseDataForFeeds(responseData, { "currentAuthor": author, "currentAuthorId": authorId })
|
||||||
if feeds.Count() > 0
|
if feeds.Count() > 0
|
||||||
items = ValidArray(feeds[0].items)
|
items = ValidArray(feeds[0].items)
|
||||||
if feeds[0].DoesExist("continuation")
|
if feeds[0].DoesExist("continuation")
|
||||||
continuation = feeds[0].continuation
|
continuation = feeds[0].continuation
|
||||||
end if
|
end if
|
||||||
|
if feeds[0].DoesExist("sortOptions")
|
||||||
|
sortOptions = feeds[0].sortOptions
|
||||||
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
channel = {
|
channel = {
|
||||||
@@ -161,9 +165,13 @@ namespace Innertube
|
|||||||
"items": items
|
"items": items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
' continuation and sort options are specific to certain tabs of the channel
|
||||||
if continuation <> invalid
|
if continuation <> invalid
|
||||||
channel["continuation"] = continuation
|
channel["continuation"] = continuation
|
||||||
end if
|
end if
|
||||||
|
if sortOptions <> invalid
|
||||||
|
channel["sortOptions"] = sortOptions
|
||||||
|
end if
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
end function
|
end function
|
||||||
|
|||||||
@@ -487,6 +487,7 @@ namespace Invidious
|
|||||||
return {
|
return {
|
||||||
items: json.videos
|
items: json.videos
|
||||||
continuation: json.continuation
|
continuation: json.continuation
|
||||||
|
sortOptions: json.sortOptions
|
||||||
}
|
}
|
||||||
end if
|
end if
|
||||||
return invalid
|
return invalid
|
||||||
@@ -510,6 +511,7 @@ namespace Invidious
|
|||||||
return {
|
return {
|
||||||
items: json.playlists
|
items: json.playlists
|
||||||
continuation: json.continuation
|
continuation: json.continuation
|
||||||
|
sortOptions: json.sortOptions
|
||||||
}
|
}
|
||||||
end if
|
end if
|
||||||
return invalid
|
return invalid
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ function VideoRowListRowContentTask(input as object) as object
|
|||||||
hasContinuation = not StringUtils.IsNullOrEmpty(response.result.continuation)
|
hasContinuation = not StringUtils.IsNullOrEmpty(response.result.continuation)
|
||||||
feedSource.state.continuation = ValidString(response.result.continuation)
|
feedSource.state.continuation = ValidString(response.result.continuation)
|
||||||
|
|
||||||
|
if response.result.sortOptions <> invalid
|
||||||
|
feedSource.state.sortOptions = response.result.sortOptions
|
||||||
|
end if
|
||||||
|
|
||||||
if addedItemCount > 0
|
if addedItemCount > 0
|
||||||
pageType = feedSource.state.paginationType
|
pageType = feedSource.state.paginationType
|
||||||
if response.result.isLastPage = true or (hadContinuation and not hasContinuation)
|
if response.result.isLastPage = true or (hadContinuation and not hasContinuation)
|
||||||
|
|||||||
+56
-14
@@ -735,6 +735,24 @@ namespace Http
|
|||||||
options.params = params
|
options.params = params
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
' sort by is a special sorting argument handled by Playlet backend.
|
||||||
|
' It's a JSON object that could have the "params" key or "continuation"
|
||||||
|
' key. In this case, we will override these options with the values
|
||||||
|
' from the "sort_by" query parameter. If we do get an Invidious "sort_by"
|
||||||
|
' (such as "newest", "oldest", etc.), we'll ignore it, as it is not supported.
|
||||||
|
sortBy = request.query.sort_by
|
||||||
|
if not StringUtils.IsNullOrEmpty(sortBy) and sortBy.StartsWith("{")
|
||||||
|
sortBy = ParseJson(sortBy)
|
||||||
|
if IsAssociativeArray(sortBy)
|
||||||
|
if sortBy.DoesExist("params")
|
||||||
|
options.params = sortBy.params
|
||||||
|
end if
|
||||||
|
if sortBy.DoesExist("continuation")
|
||||||
|
options.continuation = sortBy.continuation
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
channel = InnertubeService.GetChannel(channelId, options)
|
channel = InnertubeService.GetChannel(channelId, options)
|
||||||
if raw
|
if raw
|
||||||
response.Json(channel)
|
response.Json(channel)
|
||||||
@@ -747,29 +765,53 @@ namespace Http
|
|||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
result = {}
|
||||||
if _tab = "playlists" or _tab = "podcasts" or _tab = "releases" or _tab = "courses"
|
if _tab = "playlists" or _tab = "podcasts" or _tab = "releases" or _tab = "courses"
|
||||||
result = {
|
result ["playlists"] = channel.items
|
||||||
"playlists": channel.items
|
|
||||||
}
|
|
||||||
if channel.DoesExist("continuation")
|
|
||||||
result.continuation = channel.continuation
|
|
||||||
end if
|
|
||||||
response.Json(result)
|
|
||||||
if channel.DoesExist("cache-control")
|
|
||||||
response.headers["cache-control"] = channel["cache-control"]
|
|
||||||
end if
|
|
||||||
else
|
else
|
||||||
result = {
|
result ["videos"] = channel.items
|
||||||
"videos": channel.items
|
end if
|
||||||
}
|
|
||||||
if channel.DoesExist("continuation")
|
if channel.DoesExist("continuation")
|
||||||
result.continuation = channel.continuation
|
result.continuation = channel.continuation
|
||||||
end if
|
end if
|
||||||
|
if channel.DoesExist("sortOptions")
|
||||||
|
' Transform sort options from:
|
||||||
|
' [{
|
||||||
|
' "title": "string",
|
||||||
|
' "isSelected": "boolean"
|
||||||
|
' "params?": "string",
|
||||||
|
' "continuation?": "string"
|
||||||
|
' }]
|
||||||
|
' to:
|
||||||
|
' [{
|
||||||
|
' "title": "string",
|
||||||
|
' "isSelected": "boolean"
|
||||||
|
' "params?": "string",
|
||||||
|
' "continuation?": "string"
|
||||||
|
' "id": "{ \"params\": \"string\", \"continuation\": \"string\" }"
|
||||||
|
' }]
|
||||||
|
' This so sorting doesn't interfere with actual params or continuation.
|
||||||
|
' Sort options are later parsed by Playlet backend.
|
||||||
|
sortOptions = channel.sortOptions
|
||||||
|
if IsArray(sortOptions) and sortOptions.Count() > 0
|
||||||
|
for i = 0 to sortOptions.Count() - 1
|
||||||
|
sortOption = sortOptions[i]
|
||||||
|
sortOptionId = {}
|
||||||
|
if sortOption.DoesExist("params")
|
||||||
|
sortOptionId["params"] = sortOption.params
|
||||||
|
end if
|
||||||
|
if sortOption.DoesExist("continuation")
|
||||||
|
sortOptionId["continuation"] = sortOption.continuation
|
||||||
|
end if
|
||||||
|
sortOption.id = FormatJson(sortOptionId)
|
||||||
|
end for
|
||||||
|
end if
|
||||||
|
result["sortOptions"] = sortOptions
|
||||||
|
end if
|
||||||
response.Json(result)
|
response.Json(result)
|
||||||
if channel.DoesExist("cache-control")
|
if channel.DoesExist("cache-control")
|
||||||
response.headers["cache-control"] = channel["cache-control"]
|
response.headers["cache-control"] = channel["cache-control"]
|
||||||
end if
|
end if
|
||||||
end if
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|||||||
Reference in new issue
Block a user