diff options
| author | syeopite <syeopite@syeopite.dev> | 2025-01-22 11:38:12 -0800 |
|---|---|---|
| committer | syeopite <syeopite@syeopite.dev> | 2025-01-22 11:38:12 -0800 |
| commit | 164d764d553921e6ee98facda241f13c2103ec90 (patch) | |
| tree | 40b6309d3cdf0b893a328bcbd0c06299e091d70f /src | |
| parent | 4a31da40009b0cf628b8c871d1cb1d18e7b8600d (diff) | |
| parent | eed14d08a8c33424c2f8d7223351de04b20f47d2 (diff) | |
| download | invidious-164d764d553921e6ee98facda241f13c2103ec90.tar.gz invidious-164d764d553921e6ee98facda241f13c2103ec90.tar.bz2 invidious-164d764d553921e6ee98facda241f13c2103ec90.zip | |
API: Add a 'published' video parameter for related videos (#4149)
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/jsonify/api_v1/video_json.cr | 6 | ||||
| -rw-r--r-- | src/invidious/videos/parser.cr | 8 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr index 08cd533f..3439ae60 100644 --- a/src/invidious/jsonify/api_v1/video_json.cr +++ b/src/invidious/jsonify/api_v1/video_json.cr @@ -267,6 +267,12 @@ module Invidious::JSONify::APIv1 json.field "lengthSeconds", rv["length_seconds"]?.try &.to_i json.field "viewCountText", rv["short_view_count"]? json.field "viewCount", rv["view_count"]?.try &.empty? ? nil : rv["view_count"].to_i64 + json.field "published", rv["published"]? + if !rv["published"]?.nil? + json.field "publishedText", translate(locale, "`x` ago", recode_date(Time.parse_rfc3339(rv["published"].to_s), locale)) + else + json.field "publishedText", "" + end end end end diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr index 915c9baf..5ca4bdb2 100644 --- a/src/invidious/videos/parser.cr +++ b/src/invidious/videos/parser.cr @@ -36,6 +36,13 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)? LOGGER.trace("parse_related_video: Found \"watchNextEndScreenRenderer\" container") + if published_time_text = related["publishedTimeText"]? + decoded_time = decode_date(published_time_text["simpleText"].to_s) + published = decoded_time.to_rfc3339.to_s + else + published = nil + end + # TODO: when refactoring video types, make a struct for related videos # or reuse an existing type, if that fits. return { @@ -47,6 +54,7 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)? "view_count" => JSON::Any.new(view_count || "0"), "short_view_count" => JSON::Any.new(short_view_count || "0"), "author_verified" => JSON::Any.new(author_verified), + "published" => JSON::Any.new(published || ""), } end |
