|
|
@ -934,9 +934,7 @@ get "/api/v1/trending" do |env|
|
|
|
|
videos = JSON.build do |json|
|
|
|
|
videos = JSON.build do |json|
|
|
|
|
json.array do
|
|
|
|
json.array do
|
|
|
|
trending.xpath_nodes(%q(//ul/li[@class="expanded-shelf-content-item-wrapper"])).each do |node|
|
|
|
|
trending.xpath_nodes(%q(//ul/li[@class="expanded-shelf-content-item-wrapper"])).each do |node|
|
|
|
|
length_seconds = node.xpath_node(%q(.//span[@class="video-time"])).not_nil!.content
|
|
|
|
length_seconds = decode_length_seconds(node.xpath_node(%q(.//span[@class="video-time"])).not_nil!.content)
|
|
|
|
minutes, seconds = length_seconds.split(":")
|
|
|
|
|
|
|
|
length_seconds = minutes.to_i * 60 + seconds.to_i
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
video = node.xpath_node(%q(.//h3/a)).not_nil!
|
|
|
|
video = node.xpath_node(%q(.//h3/a)).not_nil!
|
|
|
|
title = video.content
|
|
|
|
title = video.content
|
|
|
@ -966,7 +964,7 @@ get "/api/v1/trending" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
published = published.content.split(" ")[-3..-1].join(" ")
|
|
|
|
published = published.content.split(" ")[-3..-1].join(" ")
|
|
|
|
published = decode_date(published)
|
|
|
|
published = decode_date(published).epoch
|
|
|
|
|
|
|
|
|
|
|
|
json.object do
|
|
|
|
json.object do
|
|
|
|
json.field "title", title
|
|
|
|
json.field "title", title
|
|
|
@ -993,7 +991,7 @@ get "/api/v1/trending" do |env|
|
|
|
|
json.field "viewCount", view_count
|
|
|
|
json.field "viewCount", view_count
|
|
|
|
json.field "author", author
|
|
|
|
json.field "author", author
|
|
|
|
json.field "authorUrl", author_url
|
|
|
|
json.field "authorUrl", author_url
|
|
|
|
json.field "published", published.epoch
|
|
|
|
json.field "published", published
|
|
|
|
json.field "description", description
|
|
|
|
json.field "description", description
|
|
|
|
json.field "descriptionHtml", descriptionHtml
|
|
|
|
json.field "descriptionHtml", descriptionHtml
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -1216,12 +1214,12 @@ get "/api/v1/channels/:ucid/videos" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
videos = JSON.build do |json|
|
|
|
|
videos = JSON.build do |json|
|
|
|
|
json.array do
|
|
|
|
json.array do
|
|
|
|
document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])).each do |item|
|
|
|
|
document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])).each do |node|
|
|
|
|
anchor = item.xpath_node(%q(.//h3[contains(@class,"yt-lockup-title")]/a)).not_nil!
|
|
|
|
anchor = node.xpath_node(%q(.//h3[contains(@class,"yt-lockup-title")]/a)).not_nil!
|
|
|
|
title = anchor.content.strip
|
|
|
|
title = anchor.content.strip
|
|
|
|
video_id = anchor["href"].lchop("/watch?v=")
|
|
|
|
video_id = anchor["href"].lchop("/watch?v=")
|
|
|
|
|
|
|
|
|
|
|
|
published = item.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[1]))
|
|
|
|
published = node.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[1]))
|
|
|
|
if !published
|
|
|
|
if !published
|
|
|
|
next
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -1229,9 +1227,9 @@ get "/api/v1/channels/:ucid/videos" do |env|
|
|
|
|
if published.ends_with? "watching"
|
|
|
|
if published.ends_with? "watching"
|
|
|
|
next
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
published = decode_date(published)
|
|
|
|
published = decode_date(published).epoch
|
|
|
|
|
|
|
|
|
|
|
|
view_count = item.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[2])).not_nil!
|
|
|
|
view_count = node.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[2])).not_nil!
|
|
|
|
view_count = view_count.content.rchop(" views")
|
|
|
|
view_count = view_count.content.rchop(" views")
|
|
|
|
if view_count = "No"
|
|
|
|
if view_count = "No"
|
|
|
|
view_count = 0
|
|
|
|
view_count = 0
|
|
|
@ -1239,7 +1237,7 @@ get "/api/v1/channels/:ucid/videos" do |env|
|
|
|
|
view_count = view_count.delete(",").to_i
|
|
|
|
view_count = view_count.delete(",").to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
|
|
|
descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
|
|
|
if !descriptionHtml
|
|
|
|
if !descriptionHtml
|
|
|
|
description = ""
|
|
|
|
description = ""
|
|
|
|
descriptionHtml = ""
|
|
|
|
descriptionHtml = ""
|
|
|
@ -1250,10 +1248,7 @@ get "/api/v1/channels/:ucid/videos" do |env|
|
|
|
|
description = XML.parse_html(description).content.strip("\n ")
|
|
|
|
description = XML.parse_html(description).content.strip("\n ")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
length_seconds = item.xpath_node(%q(.//span[@class="video-time"]/span)).not_nil!.content
|
|
|
|
length_seconds = decode_length_seconds(node.xpath_node(%q(.//span[@class="video-time"])).not_nil!.content)
|
|
|
|
length_seconds = length_seconds.split(":").map { |a| a.to_i }
|
|
|
|
|
|
|
|
length_seconds = [0] * (3 - length_seconds.size) + length_seconds
|
|
|
|
|
|
|
|
length_seconds = Time::Span.new(length_seconds[0], length_seconds[1], length_seconds[2])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json.object do
|
|
|
|
json.object do
|
|
|
|
json.field "title", title
|
|
|
|
json.field "title", title
|
|
|
@ -1281,8 +1276,8 @@ get "/api/v1/channels/:ucid/videos" do |env|
|
|
|
|
json.field "descriptionHtml", descriptionHtml
|
|
|
|
json.field "descriptionHtml", descriptionHtml
|
|
|
|
|
|
|
|
|
|
|
|
json.field "viewCount", view_count
|
|
|
|
json.field "viewCount", view_count
|
|
|
|
json.field "published", published.epoch
|
|
|
|
json.field "published", published
|
|
|
|
json.field "lengthSeconds", length_seconds.total_seconds.to_i
|
|
|
|
json.field "lengthSeconds", length_seconds
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -1308,8 +1303,8 @@ get "/api/v1/search" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
results = JSON.build do |json|
|
|
|
|
results = JSON.build do |json|
|
|
|
|
json.array do
|
|
|
|
json.array do
|
|
|
|
html.xpath_nodes(%q(//ol[@class="item-section"]/li)).each do |item|
|
|
|
|
html.xpath_nodes(%q(//ol[@class="item-section"]/li)).each do |node|
|
|
|
|
anchor = item.xpath_node(%q(.//h3[contains(@class,"yt-lockup-title")]/a)).not_nil!
|
|
|
|
anchor = node.xpath_node(%q(.//h3[contains(@class,"yt-lockup-title")]/a)).not_nil!
|
|
|
|
if anchor["href"].starts_with? "https://www.googleadservices.com"
|
|
|
|
if anchor["href"].starts_with? "https://www.googleadservices.com"
|
|
|
|
next
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -1317,11 +1312,11 @@ get "/api/v1/search" do |env|
|
|
|
|
title = anchor.content.strip
|
|
|
|
title = anchor.content.strip
|
|
|
|
video_id = anchor["href"].lchop("/watch?v=")
|
|
|
|
video_id = anchor["href"].lchop("/watch?v=")
|
|
|
|
|
|
|
|
|
|
|
|
anchor = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-byline")]/a)).not_nil!
|
|
|
|
anchor = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-byline")]/a)).not_nil!
|
|
|
|
author = anchor.content
|
|
|
|
author = anchor.content
|
|
|
|
author_url = anchor["href"]
|
|
|
|
author_url = anchor["href"]
|
|
|
|
|
|
|
|
|
|
|
|
published = item.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[1]))
|
|
|
|
published = node.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[1]))
|
|
|
|
if !published
|
|
|
|
if !published
|
|
|
|
next
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -1329,9 +1324,9 @@ get "/api/v1/search" do |env|
|
|
|
|
if published.ends_with? "watching"
|
|
|
|
if published.ends_with? "watching"
|
|
|
|
next
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
published = decode_date(published)
|
|
|
|
published = decode_date(published).epoch
|
|
|
|
|
|
|
|
|
|
|
|
view_count = item.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[2])).not_nil!
|
|
|
|
view_count = node.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[2])).not_nil!
|
|
|
|
view_count = view_count.content.rchop(" views")
|
|
|
|
view_count = view_count.content.rchop(" views")
|
|
|
|
if view_count = "No"
|
|
|
|
if view_count = "No"
|
|
|
|
view_count = 0
|
|
|
|
view_count = 0
|
|
|
@ -1339,7 +1334,7 @@ get "/api/v1/search" do |env|
|
|
|
|
view_count = view_count.delete(",").to_i
|
|
|
|
view_count = view_count.delete(",").to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
|
|
|
descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
|
|
|
if !descriptionHtml
|
|
|
|
if !descriptionHtml
|
|
|
|
description = ""
|
|
|
|
description = ""
|
|
|
|
descriptionHtml = ""
|
|
|
|
descriptionHtml = ""
|
|
|
@ -1350,10 +1345,7 @@ get "/api/v1/search" do |env|
|
|
|
|
description = XML.parse_html(description).content.strip("\n ")
|
|
|
|
description = XML.parse_html(description).content.strip("\n ")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
length_seconds = item.xpath_node(%q(.//span[@class="video-time"])).not_nil!.content
|
|
|
|
length_seconds = decode_length_seconds(node.xpath_node(%q(.//span[@class="video-time"])).not_nil!.content)
|
|
|
|
length_seconds = length_seconds.split(":").map { |a| a.to_i }
|
|
|
|
|
|
|
|
length_seconds = [0] * (3 - length_seconds.size) + length_seconds
|
|
|
|
|
|
|
|
length_seconds = Time::Span.new(length_seconds[0], length_seconds[1], length_seconds[2])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json.object do
|
|
|
|
json.object do
|
|
|
|
json.field "title", title
|
|
|
|
json.field "title", title
|
|
|
@ -1384,8 +1376,8 @@ get "/api/v1/search" do |env|
|
|
|
|
json.field "descriptionHtml", descriptionHtml
|
|
|
|
json.field "descriptionHtml", descriptionHtml
|
|
|
|
|
|
|
|
|
|
|
|
json.field "viewCount", view_count
|
|
|
|
json.field "viewCount", view_count
|
|
|
|
json.field "published", published.epoch
|
|
|
|
json.field "published", published
|
|
|
|
json.field "lengthSeconds", length_seconds.total_seconds.to_i
|
|
|
|
json.field "lengthSeconds", length_seconds
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -2134,12 +2126,12 @@ get "/feed/channel/:ucid" do |env|
|
|
|
|
xml.element("uri") { xml.text "#{scheme}#{host}/channel/#{ucid}" }
|
|
|
|
xml.element("uri") { xml.text "#{scheme}#{host}/channel/#{ucid}" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])).each do |item|
|
|
|
|
document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])).each do |node|
|
|
|
|
anchor = item.xpath_node(%q(.//h3[contains(@class,"yt-lockup-title")]/a)).not_nil!
|
|
|
|
anchor = node.xpath_node(%q(.//h3[contains(@class,"yt-lockup-title")]/a)).not_nil!
|
|
|
|
title = anchor.content.strip
|
|
|
|
title = anchor.content.strip
|
|
|
|
video_id = anchor["href"].lchop("/watch?v=")
|
|
|
|
video_id = anchor["href"].lchop("/watch?v=")
|
|
|
|
|
|
|
|
|
|
|
|
view_count = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[2])).not_nil!
|
|
|
|
view_count = node.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[2])).not_nil!
|
|
|
|
view_count = view_count.content.rchop(" views")
|
|
|
|
view_count = view_count.content.rchop(" views")
|
|
|
|
if view_count = "No"
|
|
|
|
if view_count = "No"
|
|
|
|
view_count = 0
|
|
|
|
view_count = 0
|
|
|
@ -2147,7 +2139,7 @@ get "/feed/channel/:ucid" do |env|
|
|
|
|
view_count = view_count.delete(",").to_i
|
|
|
|
view_count = view_count.delete(",").to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
|
|
|
descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
|
|
|
if !descriptionHtml
|
|
|
|
if !descriptionHtml
|
|
|
|
description = ""
|
|
|
|
description = ""
|
|
|
|
descriptionHtml = ""
|
|
|
|
descriptionHtml = ""
|
|
|
@ -2158,7 +2150,7 @@ get "/feed/channel/:ucid" do |env|
|
|
|
|
description = XML.parse_html(description).content.strip("\n ")
|
|
|
|
description = XML.parse_html(description).content.strip("\n ")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
published = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[1]))
|
|
|
|
published = node.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[1]))
|
|
|
|
if !published
|
|
|
|
if !published
|
|
|
|
next
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -2202,12 +2194,12 @@ get "/feed/private" do |env|
|
|
|
|
token = env.params.query["token"]?
|
|
|
|
token = env.params.query["token"]?
|
|
|
|
|
|
|
|
|
|
|
|
if !token
|
|
|
|
if !token
|
|
|
|
halt env, status_code: 401
|
|
|
|
halt env, status_code: 403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
user = PG_DB.query_one?("SELECT * FROM users WHERE token = $1", token, as: User)
|
|
|
|
user = PG_DB.query_one?("SELECT * FROM users WHERE token = $1", token.strip, as: User)
|
|
|
|
if !user
|
|
|
|
if !user
|
|
|
|
halt env, status_code: 401
|
|
|
|
halt env, status_code: 403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
max_results = env.params.query["max_results"]?.try &.to_i?
|
|
|
|
max_results = env.params.query["max_results"]?.try &.to_i?
|
|
|
@ -2715,10 +2707,10 @@ get "/channel/:ucid" do |env|
|
|
|
|
author = document.xpath_node(%q(//div[@class="pl-video-owner"]/a)).not_nil!.content
|
|
|
|
author = document.xpath_node(%q(//div[@class="pl-video-owner"]/a)).not_nil!.content
|
|
|
|
|
|
|
|
|
|
|
|
videos = [] of ChannelVideo
|
|
|
|
videos = [] of ChannelVideo
|
|
|
|
document.xpath_nodes(%q(//a[contains(@class,"pl-video-title-link")])).each do |item|
|
|
|
|
document.xpath_nodes(%q(//a[contains(@class,"pl-video-title-link")])).each do |node|
|
|
|
|
href = URI.parse(item["href"])
|
|
|
|
href = URI.parse(node["href"])
|
|
|
|
id = HTTP::Params.parse(href.query.not_nil!)["v"]
|
|
|
|
id = HTTP::Params.parse(href.query.not_nil!)["v"]
|
|
|
|
title = item.content
|
|
|
|
title = node.content
|
|
|
|
|
|
|
|
|
|
|
|
videos << ChannelVideo.new(id, title, Time.now, Time.now, ucid, author)
|
|
|
|
videos << ChannelVideo.new(id, title, Time.now, Time.now, ucid, author)
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -2726,14 +2718,6 @@ get "/channel/:ucid" do |env|
|
|
|
|
templated "channel"
|
|
|
|
templated "channel"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
get "/redirect" do |env|
|
|
|
|
|
|
|
|
if env.params.query["q"]?
|
|
|
|
|
|
|
|
env.redirect env.params.query["q"]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
env.redirect "/"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/manifest/dash/id/:id" do |env|
|
|
|
|
get "/api/manifest/dash/id/:id" do |env|
|
|
|
|
env.response.headers.add("Access-Control-Allow-Origin", "*")
|
|
|
|
env.response.headers.add("Access-Control-Allow-Origin", "*")
|
|
|
|
env.response.content_type = "application/dash+xml"
|
|
|
|
env.response.content_type = "application/dash+xml"
|
|
|
|