Bump number of videos in channel resources to 60

This commit is contained in:
Omar Roth 2018-09-06 08:43:22 -05:00
parent d81a803618
commit b17d3d1e51
2 changed files with 61 additions and 45 deletions

View file

@ -1407,21 +1407,26 @@ get "/feed/channel/:ucid" do |env|
auto_generated = true auto_generated = true
end end
url = produce_channel_videos_url(ucid, auto_generated: auto_generated) page = 1
response = client.get(url)
json = JSON.parse(response.body)
if json["content_html"]? && !json["content_html"].as_s.empty? videos = [] of SearchVideo
document = XML.parse_html(json["content_html"].as_s) 2.times do |i|
nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])) url = produce_channel_videos_url(ucid, page * 2 + (i - 1), auto_generated: auto_generated)
response = client.get(url)
json = JSON.parse(response.body)
if auto_generated if json["content_html"]? && !json["content_html"].as_s.empty?
videos = extract_videos(nodeset) document = XML.parse_html(json["content_html"].as_s)
nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")]))
if auto_generated
videos += extract_videos(nodeset)
else
videos += extract_videos(nodeset, ucid)
end
else else
videos = extract_videos(nodeset, ucid) break
end end
else
videos = [] of SearchVideo
end end
channel = get_channel(ucid, client, PG_DB, pull_all_videos: false) channel = get_channel(ucid, client, PG_DB, pull_all_videos: false)
@ -1659,21 +1664,24 @@ get "/channel/:ucid" do |env|
auto_generated = true auto_generated = true
end end
url = produce_channel_videos_url(ucid, page, auto_generated: auto_generated) videos = [] of SearchVideo
response = client.get(url) 2.times do |i|
json = JSON.parse(response.body) url = produce_channel_videos_url(ucid, page * 2 + (i - 1), auto_generated: auto_generated)
response = client.get(url)
json = JSON.parse(response.body)
if json["content_html"]? && !json["content_html"].as_s.empty? if json["content_html"]? && !json["content_html"].as_s.empty?
document = XML.parse_html(json["content_html"].as_s) document = XML.parse_html(json["content_html"].as_s)
nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])) nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")]))
if auto_generated if auto_generated
videos = extract_videos(nodeset) videos += extract_videos(nodeset)
else
videos += extract_videos(nodeset, ucid)
end
else else
videos = extract_videos(nodeset, ucid) break
end end
else
videos = [] of SearchVideo
end end
templated "channel" templated "channel"
@ -2309,21 +2317,26 @@ get "/api/v1/channels/:ucid" do |env|
auto_generated = true auto_generated = true
end end
url = produce_channel_videos_url(ucid, 1, auto_generated) page = 1
response = client.get(url)
json = JSON.parse(response.body) videos = [] of SearchVideo
if json["content_html"]? && !json["content_html"].as_s.empty? 2.times do |i|
document = XML.parse_html(json["content_html"].as_s) url = produce_channel_videos_url(ucid, page * 2 + (i - 1), auto_generated: auto_generated)
nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])) response = client.get(url)
json = JSON.parse(response.body)
if auto_generated if json["content_html"]? && !json["content_html"].as_s.empty?
videos = extract_videos(nodeset) document = XML.parse_html(json["content_html"].as_s)
nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")]))
if auto_generated
videos += extract_videos(nodeset)
else
videos += extract_videos(nodeset, ucid)
end
else else
videos = extract_videos(nodeset, ucid) break
end end
else
videos = [] of SearchVideo
end end
channel_html = client.get("/channel/#{ucid}/about?disable_polymer=1").body channel_html = client.get("/channel/#{ucid}/about?disable_polymer=1").body
@ -2486,21 +2499,24 @@ get "/api/v1/channels/:ucid/videos" do |env|
auto_generated = true auto_generated = true
end end
url = produce_channel_videos_url(ucid, auto_generated: auto_generated) videos = [] of SearchVideo
response = client.get(url) 2.times do |i|
json = JSON.parse(response.body) url = produce_channel_videos_url(ucid, page * 2 + (i - 1), auto_generated: auto_generated)
response = client.get(url)
json = JSON.parse(response.body)
if json["content_html"]? && !json["content_html"].as_s.empty? if json["content_html"]? && !json["content_html"].as_s.empty?
document = XML.parse_html(json["content_html"].as_s) document = XML.parse_html(json["content_html"].as_s)
nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])) nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")]))
if auto_generated if auto_generated
videos = extract_videos(nodeset) videos += extract_videos(nodeset)
else
videos += extract_videos(nodeset, ucid)
end
else else
videos = extract_videos(nodeset, ucid) break
end end
else
videos = [] of SearchVideo
end end
result = JSON.build do |json| result = JSON.build do |json|

View file

@ -51,7 +51,7 @@
</div> </div>
<div class="pure-u-1 pure-u-md-3-5"></div> <div class="pure-u-1 pure-u-md-3-5"></div>
<div style="text-align:right;" class="pure-u-1 pure-u-md-1-5"> <div style="text-align:right;" class="pure-u-1 pure-u-md-1-5">
<% if videos.size == 30 %> <% if videos.size == 60 %>
<a href="/channel/<%= ucid %>?page=<%= page + 1 %>">Next page</a> <a href="/channel/<%= ucid %>?page=<%= page + 1 %>">Next page</a>
<% end %> <% end %>
</div> </div>