Add 'view as playlist' option to trending page

pull/366/head
Omar Roth 6 years ago
parent 9c8f85741c
commit f5dd135ed8

@ -278,6 +278,7 @@
"About": "حول", "About": "حول",
"Rating: ": "التقييم", "Rating: ": "التقييم",
"Language: ": "اللغة", "Language: ": "اللغة",
"View as playlist": "",
"Default": "الكل", "Default": "الكل",
"Music": "الاغانى", "Music": "الاغانى",
"Gaming": "الألعاب", "Gaming": "الألعاب",

@ -278,6 +278,7 @@
"About": "Über", "About": "Über",
"Rating: ": "Bewertung: ", "Rating: ": "Bewertung: ",
"Language: ": "Sprache: ", "Language: ": "Sprache: ",
"View as playlist": "",
"Default": "", "Default": "",
"Music": "", "Music": "",
"Gaming": "", "Gaming": "",

@ -112,7 +112,7 @@
"Whitelisted regions: ": "Whitelisted regions: ", "Whitelisted regions: ": "Whitelisted regions: ",
"Blacklisted regions: ": "Blacklisted regions: ", "Blacklisted regions: ": "Blacklisted regions: ",
"Shared `x`": "Shared `x`", "Shared `x`": "Shared `x`",
"`x` views": "", "`x` views": "`x` views",
"Premieres in `x`": "Premieres in `x`", "Premieres in `x`": "Premieres in `x`",
"Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.", "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.": "Hi! Looks like you have JavaScript disabled. Click here to view comments, keep in mind it may take a bit longer to load.",
"View YouTube comments": "View YouTube comments", "View YouTube comments": "View YouTube comments",
@ -276,6 +276,7 @@
"About": "About", "About": "About",
"Rating: ": "Rating: ", "Rating: ": "Rating: ",
"Language: ": "Language: ", "Language: ": "Language: ",
"View as playlist": "View as playlist",
"Default": "Default", "Default": "Default",
"Music": "Music", "Music": "Music",
"Gaming": "Gaming", "Gaming": "Gaming",

@ -276,6 +276,7 @@
"About": "Acerca de", "About": "Acerca de",
"Rating: ": "Valoración: ", "Rating: ": "Valoración: ",
"Language: ": "Idioma: ", "Language: ": "Idioma: ",
"View as playlist": "",
"Default": "Por defecto", "Default": "Por defecto",
"Music": "Música", "Music": "Música",
"Gaming": "Videojuegos", "Gaming": "Videojuegos",

@ -276,6 +276,7 @@
"About": "", "About": "",
"Rating: ": "", "Rating: ": "",
"Language: ": "", "Language: ": "",
"View as playlist": "",
"Default": "", "Default": "",
"Music": "", "Music": "",
"Gaming": "", "Gaming": "",

@ -276,6 +276,7 @@
"About": "A Propos", "About": "A Propos",
"Rating: ": "Évaluation : ", "Rating: ": "Évaluation : ",
"Language: ": "Langue : ", "Language: ": "Langue : ",
"View as playlist": "",
"Default": "Défaut", "Default": "Défaut",
"Music": "Musique", "Music": "Musique",
"Gaming": "Jeux Vidéo", "Gaming": "Jeux Vidéo",

@ -276,6 +276,7 @@
"About": "A proposito", "About": "A proposito",
"Rating: ": "Punteggio: ", "Rating: ": "Punteggio: ",
"Language: ": "Lingua: ", "Language: ": "Lingua: ",
"View as playlist": "",
"Default": "Predefinito", "Default": "Predefinito",
"Music": "Musica", "Music": "Musica",
"Gaming": "Videogiochi", "Gaming": "Videogiochi",

@ -276,6 +276,7 @@
"About": "Om", "About": "Om",
"Rating: ": "Vurdering: ", "Rating: ": "Vurdering: ",
"Language: ": "Språk: ", "Language: ": "Språk: ",
"View as playlist": "",
"Default": "Forvalg", "Default": "Forvalg",
"Music": "Musikk", "Music": "Musikk",
"Gaming": "Spill", "Gaming": "Spill",

@ -276,6 +276,7 @@
"About": "", "About": "",
"Rating: ": "", "Rating: ": "",
"Language: ": "", "Language: ": "",
"View as playlist": "",
"Default": "", "Default": "",
"Music": "", "Music": "",
"Gaming": "", "Gaming": "",

@ -276,6 +276,7 @@
"About": "Informacje", "About": "Informacje",
"Rating: ": "Ocena: ", "Rating: ": "Ocena: ",
"Language: ": "Język: ", "Language: ": "Język: ",
"View as playlist": "",
"Default": "Domyślnie", "Default": "Domyślnie",
"Music": "Muzyka", "Music": "Muzyka",
"Gaming": "Gry", "Gaming": "Gry",

@ -278,6 +278,7 @@
"About": "О сайте", "About": "О сайте",
"Rating: ": "Рейтинг: ", "Rating: ": "Рейтинг: ",
"Language: ": "Язык: ", "Language: ": "Язык: ",
"View as playlist": "",
"Default": "По-умолчанию", "Default": "По-умолчанию",
"Music": "Музыка", "Music": "Музыка",
"Gaming": "Игры", "Gaming": "Игры",

@ -1955,7 +1955,7 @@ get "/feed/trending" do |env|
region ||= "US" region ||= "US"
begin begin
trending = fetch_trending(trending_type, proxies, region, locale) trending, plid = fetch_trending(trending_type, proxies, region, locale)
rescue ex rescue ex
error_message = "#{ex.message}" error_message = "#{ex.message}"
next templated "error" next templated "error"
@ -3205,7 +3205,7 @@ get "/api/v1/trending" do |env|
trending_type = env.params.query["type"]? trending_type = env.params.query["type"]?
begin begin
trending = fetch_trending(trending_type, proxies, region, locale) trending, plid = fetch_trending(trending_type, proxies, region, locale)
rescue ex rescue ex
error_message = {"error" => ex.message}.to_json error_message = {"error" => ex.message}.to_json
env.response.status_code = 500 env.response.status_code = 500

@ -7,6 +7,8 @@ def fetch_trending(trending_type, proxies, region, locale)
region = region.upcase region = region.upcase
trending = "" trending = ""
plid = nil
if trending_type && trending_type != "Default" if trending_type && trending_type != "Default"
trending_type = trending_type.downcase.capitalize trending_type = trending_type.downcase.capitalize
@ -23,9 +25,11 @@ def fetch_trending(trending_type, proxies, region, locale)
url = tabs.select { |tab| tab["channelListSubMenuAvatarRenderer"]["title"]["simpleText"] == trending_type }[0]? url = tabs.select { |tab| tab["channelListSubMenuAvatarRenderer"]["title"]["simpleText"] == trending_type }[0]?
if url if url
url["channelListSubMenuAvatarRenderer"]["navigationEndpoint"]["commandMetadata"]["webCommandMetadata"]["url"]
url = url["channelListSubMenuAvatarRenderer"]["navigationEndpoint"]["commandMetadata"]["webCommandMetadata"]["url"].as_s url = url["channelListSubMenuAvatarRenderer"]["navigationEndpoint"]["commandMetadata"]["webCommandMetadata"]["url"].as_s
url += "&disable_polymer=1&gl=#{region}&hl=en" url += "&disable_polymer=1&gl=#{region}&hl=en"
trending = client.get(url).body trending = client.get(url).body
plid = extract_plid(url)
else else
trending = client.get("/feed/trending?gl=#{region}&hl=en&disable_polymer=1").body trending = client.get("/feed/trending?gl=#{region}&hl=en&disable_polymer=1").body
end end
@ -37,5 +41,37 @@ def fetch_trending(trending_type, proxies, region, locale)
nodeset = trending.xpath_nodes(%q(//ul/li[@class="expanded-shelf-content-item-wrapper"])) nodeset = trending.xpath_nodes(%q(//ul/li[@class="expanded-shelf-content-item-wrapper"]))
trending = extract_videos(nodeset) trending = extract_videos(nodeset)
return trending return {trending, plid}
end
def extract_plid(url)
wrapper = HTTP::Params.parse(URI.parse(url).query.not_nil!)["bp"]
wrapper = URI.unescape(wrapper)
wrapper = Base64.decode(wrapper)
# 0xe2 0x02 0x2e
wrapper += 3
# 0x0a
wrapper += 1
# Looks like "/m/[a-z0-9]{5}", not sure what it does here
item_size = wrapper[0]
wrapper += 1
item = wrapper[0, item_size]
wrapper += item.size
# 0x12
wrapper += 1
plid_size = wrapper[0]
wrapper += 1
plid = wrapper[0, plid_size]
wrapper += plid.size
plid = String.new(plid)
return plid
end end

@ -6,9 +6,10 @@
<%= rendered "components/feed_menu" %> <%= rendered "components/feed_menu" %>
<div class="pure-g h-box"> <div class="pure-g h-box">
<div class="pure-u-2-3"> <div style="align-self:flex-end" class="pure-u-2-3">
<form class="pure-form pure-form-aligned" action="/feed/trending" method="get"> <% if plid %>
</form> <a href="/playlist?list=<%= plid %>"><%= translate(locale, "View as playlist") %></a>
<% end %>
</div> </div>
<div class="pure-u-1-3"> <div class="pure-u-1-3">
<div class="pure-g" style="text-align:right;"> <div class="pure-g" style="text-align:right;">

Loading…
Cancel
Save