From db91d3af66b52e8f7127b2b3b826111126027c6d Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Wed, 14 Sep 2022 20:08:36 +0200 Subject: [PATCH] videos: Fix some bugs --- src/invidious/jsonify/api_v1/video_json.cr | 11 ++++++++++- src/invidious/videos/parser.cr | 8 ++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr index 0a5173ce..642789aa 100644 --- a/src/invidious/jsonify/api_v1/video_json.cr +++ b/src/invidious/jsonify/api_v1/video_json.cr @@ -93,7 +93,16 @@ module Invidious::JSONify::APIv1 json.field "itag", fmt["itag"].as_i.to_s json.field "type", fmt["mimeType"] json.field "clen", fmt["contentLength"]? || "-1" - json.field "lmt", fmt["lastModified"] + + # Last modified is a unix timestamp with µS, with the dot omitted. + # E.g: 1638056732(.)141582 + # + # On livestreams, it's not present, so always fall back to the + # current unix timestamp (up to mS precision) for compatibility. + last_modified = fmt["lastModified"]? + last_modified ||= "#{Time.utc.to_unix_ms.to_s}000" + json.field "lmt", last_modified + json.field "projectionType", fmt["projectionType"] if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"]) diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr index 701c4e77..53372942 100644 --- a/src/invidious/videos/parser.cr +++ b/src/invidious/videos/parser.cr @@ -159,10 +159,10 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any # We have to try to extract viewCount from videoPrimaryInfoRenderer first, # then from videoDetails, as the latter is "0" for livestreams (we want # to get the amount of viewers watching). - views = video_primary_renderer + views_txt = video_primary_renderer .try &.dig?("viewCount", "videoViewCountRenderer", "viewCount", "runs", 0, "text") - .try &.as_s.to_i64 - views ||= video_details["viewCount"]?.try &.as_s.to_i64 + views_txt ||= video_details["viewCount"]? + views = views_txt.try &.as_s.gsub(/\D/, "").to_i64? length_txt = (microformat["lengthSeconds"]? || video_details["lengthSeconds"]) .try &.as_s.to_i64 @@ -270,7 +270,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any license = nil metadata.try &.each do |row| - metadata_title = row.dig?("metadataRowRenderer", "title", "simpleText").try &.as_s + metadata_title = extract_text(row.dig?("metadataRowRenderer", "title")) contents = row.dig?("metadataRowRenderer", "contents", 0) if metadata_title == "Category"