Skip to content

Commit 164d764

Browse files
committed
API: Add a 'published' video parameter for related videos (#4149)
2 parents 4a31da4 + eed14d0 commit 164d764

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/invidious/jsonify/api_v1/video_json.cr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ module Invidious::JSONify::APIv1
267267
json.field "lengthSeconds", rv["length_seconds"]?.try &.to_i
268268
json.field "viewCountText", rv["short_view_count"]?
269269
json.field "viewCount", rv["view_count"]?.try &.empty? ? nil : rv["view_count"].to_i64
270+
json.field "published", rv["published"]?
271+
if !rv["published"]?.nil?
272+
json.field "publishedText", translate(locale, "`x` ago", recode_date(Time.parse_rfc3339(rv["published"].to_s), locale))
273+
else
274+
json.field "publishedText", ""
275+
end
270276
end
271277
end
272278
end

src/invidious/videos/parser.cr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
3636

3737
LOGGER.trace("parse_related_video: Found \"watchNextEndScreenRenderer\" container")
3838

39+
if published_time_text = related["publishedTimeText"]?
40+
decoded_time = decode_date(published_time_text["simpleText"].to_s)
41+
published = decoded_time.to_rfc3339.to_s
42+
else
43+
published = nil
44+
end
45+
3946
# TODO: when refactoring video types, make a struct for related videos
4047
# or reuse an existing type, if that fits.
4148
return {
@@ -47,6 +54,7 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
4754
"view_count" => JSON::Any.new(view_count || "0"),
4855
"short_view_count" => JSON::Any.new(short_view_count || "0"),
4956
"author_verified" => JSON::Any.new(author_verified),
57+
"published" => JSON::Any.new(published || ""),
5058
}
5159
end
5260

0 commit comments

Comments
 (0)