summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-09-14 20:08:36 +0200
committerSamantaz Fox <coding@samantaz.fr>2022-10-31 20:30:35 +0100
commitdb91d3af66b52e8f7127b2b3b826111126027c6d (patch)
treeb87957d6ff5bc7fac6e9cb526782f0ecd1a32399
parent83795c245aace771fb73936b22d3de7ced0df9df (diff)
downloadinvidious-db91d3af66b52e8f7127b2b3b826111126027c6d.tar.gz
invidious-db91d3af66b52e8f7127b2b3b826111126027c6d.tar.bz2
invidious-db91d3af66b52e8f7127b2b3b826111126027c6d.zip
videos: Fix some bugs
-rw-r--r--src/invidious/jsonify/api_v1/video_json.cr11
-rw-r--r--src/invidious/videos/parser.cr8
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"