invidious/src/invidious/search.cr

76 wiersze
1.9 KiB
Crystal
Czysty Zwykły widok Historia

class ChannelSearchException < InfoException
getter channel : String
def initialize(@channel)
end
end
2021-03-24 05:15:06 +00:00
def produce_channel_search_continuation(ucid, query, page)
if page <= 1
idx = 0_i64
else
idx = 30_i64 * (page - 1)
end
2019-10-27 17:50:42 +00:00
object = {
"80226972:embedded" => {
"2:string" => ucid,
"3:base64" => {
"2:string" => "search",
2021-03-24 05:15:06 +00:00
"6:varint" => 1_i64,
2019-10-27 17:50:42 +00:00
"7:varint" => 1_i64,
2021-03-24 05:15:06 +00:00
"12:varint" => 1_i64,
"15:base64" => {
"3:varint" => idx,
},
2020-06-15 22:33:23 +00:00
"23:varint" => 0_i64,
2019-10-27 17:50:42 +00:00
},
"11:string" => query,
2021-03-24 05:15:06 +00:00
"35:string" => "browse-feed#{ucid}search",
2019-10-27 17:50:42 +00:00
},
}
2021-09-25 02:05:25 +00:00
continuation = object.try { |i| Protodec::Any.cast_json(i) }
2019-10-27 17:50:42 +00:00
.try { |i| Protodec::Any.from_json(i) }
.try { |i| Base64.urlsafe_encode(i) }
.try { |i| URI.encode_www_form(i) }
2021-03-24 05:15:06 +00:00
return continuation
2018-09-13 22:47:31 +00:00
end
2019-08-05 23:49:13 +00:00
def process_search_query(query, page, user, region)
# Parse legacy query
filters, channel, search_query, subscriptions = Invidious::Search::Filters.from_legacy_filters(query)
2019-08-05 23:49:13 +00:00
if !channel.nil? && !channel.empty?
2022-03-06 23:52:54 +00:00
items = Invidious::Search::Processors.channel(search_query, page, channel)
2019-08-05 23:49:13 +00:00
elsif subscriptions
2022-03-06 23:52:54 +00:00
if user
user = user.as(Invidious::User)
items = Invidious::Search::Processors.subscriptions(query, page, user)
2019-08-05 23:49:13 +00:00
else
items = [] of ChannelVideo
end
else
search_params = filters.to_yt_params(page: page)
items = search(search_query, search_params, region)
2019-08-05 23:49:13 +00:00
end
# Light processing to flatten search results out of Categories.
# They should ideally be supported in the future.
items_without_category = [] of SearchItem | ChannelVideo
items.each do |i|
if i.is_a? Category
i.contents.each do |nest_i|
if !nest_i.is_a? Video
items_without_category << nest_i
end
end
else
items_without_category << i
end
end
{search_query, items_without_category, filters}
2019-08-05 23:49:13 +00:00
end