summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-08-22 11:06:31 -0500
committerOmar Roth <omarroth@hotmail.com>2018-08-22 11:06:31 -0500
commit01a80995d3ebfc0edd18d3d27de22adf3595e8be (patch)
treea3a1012cccabf920eb58472002b166a33d50ddab
parent76d3abb5f90dc513e30c996f0d11ba0f8c963bb8 (diff)
downloadinvidious-01a80995d3ebfc0edd18d3d27de22adf3595e8be.tar.gz
invidious-01a80995d3ebfc0edd18d3d27de22adf3595e8be.tar.bz2
invidious-01a80995d3ebfc0edd18d3d27de22adf3595e8be.zip
Add fix for channel endpoint where channel has no subscribers
-rw-r--r--src/invidious.cr14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index cc8edf0a..e36f28f1 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -2170,10 +2170,16 @@ get "/api/v1/channels/:ucid" do |env|
is_family_friendly = channel_html.xpath_node(%q(//meta[@itemprop="isFamilyFriendly"])).not_nil!["content"] == "True"
allowed_regions = channel_html.xpath_node(%q(//meta[@itemprop="regionsAllowed"])).not_nil!["content"].split(",")
- sub_count, total_views, joined = channel_html.xpath_nodes(%q(//span[@class="about-stat"]))
- sub_count = sub_count.content.rchop(" subscribers").delete(",").to_i64
- total_views = total_views.content.rchop(" views").lchop(" • ").delete(",").to_i64
- joined = Time.parse(joined.content.lchop("Joined "), "%b %-d, %Y", Time::Location.local)
+ anchor = channel_html.xpath_nodes(%q(//span[@class="about-stat"]))
+ if anchor[0].content.includes? "views"
+ sub_count = 0
+ total_views = anchor[0].content.delete("views •,").to_i64
+ joined = Time.parse(anchor[1].content.lchop("Joined "), "%b %-d, %Y", Time::Location.local)
+ else
+ sub_count = anchor[0].content.delete("subscribers").delete(",").to_i64
+ total_views = anchor[1].content.delete("views •,").to_i64
+ joined = Time.parse(anchor[2].content.lchop("Joined "), "%b %-d, %Y", Time::Location.local)
+ end
latest_videos = PG_DB.query_all("SELECT * FROM channel_videos WHERE ucid = $1 ORDER BY published DESC LIMIT 15",
channel.id, as: ChannelVideo)