Invidious is an alternative front-end to YouTube
videos: Fix some bugs
Samantaz Foxdb91d3af66b5
diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.crindex 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::APIv1json.field "itag", fmt["itag"].as_i.to_sjson.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.crindex 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::Anylicense = nilmetadata.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"