2019-06-29 02:17:56 +00:00
|
|
|
def fetch_trending(trending_type, region, locale)
|
2018-11-20 17:18:12 +00:00
|
|
|
region ||= "US"
|
|
|
|
region = region.upcase
|
|
|
|
|
2019-04-15 00:04:10 +00:00
|
|
|
plid = nil
|
|
|
|
|
2021-06-23 22:08:40 +00:00
|
|
|
if trending_type == "Music"
|
|
|
|
params = "4gINGgt5dG1hX2NoYXJ0cw%3D%3D"
|
|
|
|
elsif trending_type == "Gaming"
|
|
|
|
params = "4gIcGhpnYW1pbmdfY29ycHVzX21vc3RfcG9wdWxhcg%3D%3D"
|
|
|
|
elsif trending_type == "Movies"
|
|
|
|
params = "4gIKGgh0cmFpbGVycw%3D%3D"
|
|
|
|
else # Default
|
|
|
|
params = ""
|
2018-11-20 17:18:12 +00:00
|
|
|
end
|
|
|
|
|
2021-06-23 22:08:40 +00:00
|
|
|
initial_data = request_youtube_api_browse("FEtrending", params: params, region: region)
|
2020-06-15 22:33:23 +00:00
|
|
|
trending = extract_videos(initial_data)
|
2018-11-20 17:18:12 +00:00
|
|
|
|
2019-04-15 00:04:10 +00:00
|
|
|
return {trending, plid}
|
|
|
|
end
|
|
|
|
|
|
|
|
def extract_plid(url)
|
2020-06-15 22:33:23 +00:00
|
|
|
return url.try { |i| URI.parse(i).query }
|
|
|
|
.try { |i| HTTP::Params.parse(i)["bp"] }
|
2020-03-30 19:27:07 +00:00
|
|
|
.try { |i| URI.decode_www_form(i) }
|
|
|
|
.try { |i| Base64.decode(i) }
|
|
|
|
.try { |i| IO::Memory.new(i) }
|
|
|
|
.try { |i| Protodec::Any.parse(i) }
|
2020-06-15 22:33:23 +00:00
|
|
|
.try &.["44:0:embedded"]?.try &.["2:1:string"]?.try &.as_s
|
2018-11-20 17:18:12 +00:00
|
|
|
end
|