2019-06-29 07:47:56 +05:30
|
|
|
def fetch_trending(trending_type, region, locale)
|
2018-11-20 22:48:12 +05:30
|
|
|
region ||= "US"
|
|
|
|
region = region.upcase
|
|
|
|
|
2019-04-15 05:34:10 +05:30
|
|
|
plid = nil
|
|
|
|
|
2023-02-11 19:11:26 +05:30
|
|
|
case trending_type.try &.downcase
|
|
|
|
when "music"
|
2021-06-24 03:38:40 +05:30
|
|
|
params = "4gINGgt5dG1hX2NoYXJ0cw%3D%3D"
|
2023-02-11 19:11:26 +05:30
|
|
|
when "gaming"
|
2021-06-24 03:38:40 +05:30
|
|
|
params = "4gIcGhpnYW1pbmdfY29ycHVzX21vc3RfcG9wdWxhcg%3D%3D"
|
2023-02-11 19:11:26 +05:30
|
|
|
when "movies"
|
2021-06-24 03:38:40 +05:30
|
|
|
params = "4gIKGgh0cmFpbGVycw%3D%3D"
|
|
|
|
else # Default
|
|
|
|
params = ""
|
2018-11-20 22:48:12 +05:30
|
|
|
end
|
|
|
|
|
2021-08-03 06:28:27 +05:30
|
|
|
client_config = YoutubeAPI::ClientConfig.new(region: region)
|
|
|
|
initial_data = YoutubeAPI.browse("FEtrending", params: params, client_config: client_config)
|
2018-11-20 22:48:12 +05:30
|
|
|
|
2023-04-28 20:53:40 +05:30
|
|
|
items, _ = extract_items(initial_data)
|
|
|
|
|
2023-05-03 02:48:40 +05:30
|
|
|
extracted = [] of SearchItem
|
|
|
|
|
|
|
|
items.each do |itm|
|
|
|
|
if itm.is_a?(Category)
|
|
|
|
# Ignore the smaller categories, as they generally contain a sponsored
|
|
|
|
# channel, which brings a lot of noise on the trending page.
|
|
|
|
# See: https://github.com/iv-org/invidious/issues/2989
|
|
|
|
next if itm.contents.size < 24
|
|
|
|
|
|
|
|
extracted.concat extract_category(itm)
|
|
|
|
else
|
|
|
|
extracted << itm
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 03:32:38 +05:30
|
|
|
# Deduplicate items before returning results
|
|
|
|
return extracted.select(SearchVideo).uniq!(&.id), plid
|
2019-04-15 05:34:10 +05:30
|
|
|
end
|