From c92f6e44e708c6085eb9143e68a8a451ef641846 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 2 Nov 2018 08:09:28 -0500 Subject: [PATCH] Update keywords and view_count --- src/invidious.cr | 6 +----- src/invidious/videos.cr | 13 ++++++++++--- src/invidious/views/channel.ecr | 2 +- src/invidious/views/watch.ecr | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 0ad09e2f..2924c894 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -2087,11 +2087,7 @@ get "/api/v1/videos/:id" do |env| json.field "descriptionHtml", video.description json.field "published", video.published.epoch json.field "publishedText", "#{recode_date(video.published)} ago" - json.field "keywords" do - json.array do - video.info["keywords"].split(",").each { |keyword| json.string keyword } - end - end + json.field "keywords", video.keywords json.field "viewCount", video.views json.field "likeCount", video.likes diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 26aa487e..d21806d5 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -262,6 +262,10 @@ class Video end end + def keywords + return self.player_response["videoDetails"]["keywords"].as_a + end + def fmt_stream(decrypt_function) streams = [] of HTTP::Params self.info["url_encoded_fmt_stream_map"].split(",") do |string| @@ -638,16 +642,19 @@ def fetch_video(id, proxies) end title = info["title"] - views = info["view_count"].to_i64 author = info["author"] ucid = info["ucid"] + views = html.xpath_node(%q(//meta[@itemprop="interactionCount"])) + views = views.try &.["content"].to_i64? + views ||= 0_i64 + likes = html.xpath_node(%q(//button[@title="I like this"]/span)) - likes = likes.try &.content.delete(",").try &.to_i + likes = likes.try &.content.delete(",").try &.to_i? likes ||= 0 dislikes = html.xpath_node(%q(//button[@title="I dislike this"]/span)) - dislikes = dislikes.try &.content.delete(",").try &.to_i + dislikes = dislikes.try &.content.delete(",").try &.to_i? dislikes ||= 0 description = html.xpath_node(%q(//p[@id="eow-description"])) diff --git a/src/invidious/views/channel.ecr b/src/invidious/views/channel.ecr index d8cc4a8d..b9b75ef5 100644 --- a/src/invidious/views/channel.ecr +++ b/src/invidious/views/channel.ecr @@ -106,4 +106,4 @@ function unsubscribe() { } } } - \ No newline at end of file + diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 3cb6328b..fe785fb7 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -1,7 +1,7 @@ <% content_for "header" do %> -"> +"> @@ -451,4 +451,4 @@ function get_youtube_replies(target, load_more) { get_youtube_comments(); <% end %> - \ No newline at end of file +