Update channel feed

pull/91/head
Omar Roth 6 years ago
parent e47b95ff42
commit d51b23bc16

@ -1257,9 +1257,6 @@ get "/feed/channel/:ucid" do |env|
end end
content_html = json["content_html"].as_s content_html = json["content_html"].as_s
if content_html.empty?
halt env, status_code: 403
end
document = XML.parse_html(content_html) document = XML.parse_html(content_html)
host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, env.request.headers["Host"]) host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, env.request.headers["Host"])
@ -1280,35 +1277,52 @@ get "/feed/channel/:ucid" do |env|
end end
document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])).each do |node| document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])).each do |node|
anchor = node.xpath_node(%q(.//h3[contains(@class,"yt-lockup-title")]/a)).not_nil! anchor = node.xpath_node(%q(.//h3[contains(@class,"yt-lockup-title")]/a))
if !anchor
next
end
if anchor["href"].starts_with? "https://www.googleadservices.com"
next
end
title = anchor.content.strip title = anchor.content.strip
video_id = anchor["href"].lchop("/watch?v=") video_id = anchor["href"].lchop("/watch?v=")
view_count = node.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[2])).not_nil! metadata = node.xpath_nodes(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li))
view_count = view_count.content.rchop(" views") if metadata.size == 0
next
elsif metadata.size == 1
view_count = metadata[0].content.split(" ")[0].delete(",").to_i64
published = Time.now
else
published = decode_date(metadata[0].content)
view_count = metadata[1].content.split(" ")[0]
if view_count == "No" if view_count == "No"
view_count = 0 view_count = 0_i64
else else
view_count = view_count.delete(",").to_i64 view_count = view_count.delete(",").to_i64
end end
end
descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])) description_html = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
if !descriptionHtml if !description_html
description = "" description = ""
descriptionHtml = "" description_html = ""
else else
descriptionHtml = descriptionHtml.to_s description_html = description_html.to_s
description = descriptionHtml.gsub("<br>", "\n") description = description_html.gsub("<br>", "\n")
description = description.gsub("<br/>", "\n") description = description.gsub("<br/>", "\n")
description = XML.parse_html(description).content.strip("\n ") description = XML.parse_html(description).content.strip("\n ")
end end
published = node.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[1])) length_seconds = node.xpath_node(%q(.//span[@class="video-time"]))
if !published if length_seconds
next length_seconds = decode_length_seconds(length_seconds.content)
else
length_seconds = -1
end end
published = published.content
published = decode_date(published)
xml.element("entry") do xml.element("entry") do
xml.element("id") { xml.text "yt:video:#{video_id}" } xml.element("id") { xml.text "yt:video:#{video_id}" }

@ -33,7 +33,7 @@ def search(query, page = 1, search_params = build_search_params(content_type: "v
end end
title = anchor.content.strip title = anchor.content.strip
id = anchor["href"].lchop("/watch?v=") video_id = anchor["href"].lchop("/watch?v=")
anchor = node.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
@ -77,7 +77,7 @@ def search(query, page = 1, search_params = build_search_params(content_type: "v
video = SearchVideo.new( video = SearchVideo.new(
title, title,
id, video_id,
author, author,
ucid, ucid,
published, published,

Loading…
Cancel
Save