Try fetching multiple pages in the search, in case results are filtered out (e.g. shorts)
This commit is contained in:
1 parent
ae09f711df
commit
36910ab5cf
3 files changed
+60
-25
No files matched your search
+3
-1
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
- Nothing worth mentioning yet.
|
### Fixed
|
||||||
|
|
||||||
|
- Try fetching multiple pages in the search, in case results are filtered out (e.g. shorts)
|
||||||
|
|
||||||
## [0.41.13] - 2025-09-18
|
## [0.41.13] - 2025-09-18
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,14 @@ namespace Innertube
|
|||||||
|
|
||||||
Innertube.ParseNode(containers, context)
|
Innertube.ParseNode(containers, context)
|
||||||
|
|
||||||
if context.currentFeed <> invalid and (context.currentFeed.items.Count() > 0 or context.currentFeed.title <> "")
|
if context.currentFeed <> invalid
|
||||||
context.feeds.Push(context.currentFeed)
|
hasTitle = context.currentFeed.title <> ""
|
||||||
context.currentFeed = invalid
|
hasItems = context.currentFeed.items.Count() > 0
|
||||||
|
hasContinuation = context.currentFeed.DoesExist("continuation")
|
||||||
|
if hasTitle or hasItems or hasContinuation
|
||||||
|
context.feeds.Push(context.currentFeed)
|
||||||
|
context.currentFeed = invalid
|
||||||
|
end if
|
||||||
end if
|
end if
|
||||||
return context.feeds
|
return context.feeds
|
||||||
end function
|
end function
|
||||||
|
|||||||
+49
-21
@@ -420,31 +420,59 @@ namespace Http
|
|||||||
options.continuation = continuation
|
options.continuation = continuation
|
||||||
end if
|
end if
|
||||||
|
|
||||||
result = InnertubeService.Search(query, options)
|
fetchedPages = 0
|
||||||
|
while true
|
||||||
|
' Content can be filtered (for example, shorts removed)
|
||||||
|
' so we could be fetching multiple pages.
|
||||||
|
if fetchedPages > 3
|
||||||
|
response.Json({
|
||||||
|
"error": "Failed to search: no results found"
|
||||||
|
})
|
||||||
|
response.http_code = 500
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
result = InnertubeService.Search(query, options)
|
||||||
|
fetchedPages += 1
|
||||||
|
|
||||||
if raw
|
if raw
|
||||||
response.Json(result)
|
response.Json(result)
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if result.error <> invalid
|
if result.error <> invalid
|
||||||
response.Json(result)
|
response.Json(result)
|
||||||
response.http_code = 500
|
response.http_code = 500
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if not IsArray(result.feeds) or result.feeds.Count() = 0
|
if not IsArray(result.feeds) or result.feeds.Count() = 0
|
||||||
response.Json({
|
response.Json({
|
||||||
"error": "Failed to search: no results found"
|
"error": "Failed to search: no results found"
|
||||||
})
|
})
|
||||||
response.http_code = 500
|
response.http_code = 500
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
|
|
||||||
response.Json(result.feeds[0])
|
feed = result.feeds[0]
|
||||||
if result.DoesExist("cache-control")
|
if feed.items.Count() > 0
|
||||||
response.headers["cache-control"] = result["cache-control"]
|
response.Json(feed)
|
||||||
end if
|
if fetchedPages = 1 and result.DoesExist("cache-control")
|
||||||
|
response.headers["cache-control"] = result["cache-control"]
|
||||||
|
end if
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
if StringUtils.IsNullOrEmpty(feed.continuation)
|
||||||
|
response.Json({
|
||||||
|
"error": "Failed to search: no results found"
|
||||||
|
})
|
||||||
|
response.http_code = 500
|
||||||
|
return true
|
||||||
|
end if
|
||||||
|
|
||||||
|
LogDebug("Search returned no results, fetching next page with continuation")
|
||||||
|
options.continuation = feed.continuation
|
||||||
|
end while
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end function
|
end function
|
||||||
|
|||||||
Reference in new issue
Block a user