Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: Add a 'published' video parameter for related videos #4149

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6b929da
Added a 'published' video parameter
RadoslavL Oct 7, 2023
b7a252b
Removed need for more API calls by parsing the publishedTimeText string
RadoslavL Oct 9, 2023
f9460e3
Fixed an issue
RadoslavL Oct 9, 2023
48af0af
Added minutes as well
RadoslavL Oct 9, 2023
b0b4f09
Seperated the code in a function
RadoslavL Oct 9, 2023
20ca1eb
Used the decode_date function instead
RadoslavL Oct 11, 2023
fa59f41
Fixed an issue
RadoslavL Oct 11, 2023
6236cea
Changed some variable names
RadoslavL Nov 8, 2023
76369eb
Removed unused attribute
RadoslavL Nov 8, 2023
a0d2419
Made published be an optional parameter
RadoslavL Nov 8, 2023
be216ff
Added the text version of the published parameter
RadoslavL Nov 12, 2023
7388e4c
Add translation to the `publishedText` parameter
RadoslavL Nov 12, 2023
50da6cf
Organize the code better
RadoslavL Nov 12, 2023
2a6a32e
Fixed an issue
RadoslavL Nov 14, 2023
0d22af6
Moved methods around
RadoslavL Nov 14, 2023
3bced4e
Fixed another issue
RadoslavL Nov 14, 2023
4c48663
Another attempt at fixing the issue
RadoslavL Nov 14, 2023
d098e5a
I hope it works at this point
RadoslavL Nov 14, 2023
03f9962
This should work
RadoslavL Nov 14, 2023
6861148
Moved code around and fixed a problem
RadoslavL Nov 24, 2023
7b7197c
retrigger checks
RadoslavL Apr 22, 2024
cab02d4
Corrected usage of publishedText variable throughout the code
RadoslavL Aug 16, 2024
2d6b46c
Fixed a really easy mistake
RadoslavL Aug 16, 2024
26dc9dc
Solution
RadoslavL Aug 16, 2024
69ff6de
Removed useless variable
RadoslavL Aug 16, 2024
e8cd631
Formatting
RadoslavL Aug 16, 2024
b526f48
Changed Unix time to Rfc3339 time and removed NaN message
RadoslavL Aug 16, 2024
eed14d0
Update src/invidious/jsonify/api_v1/video_json.cr
RadoslavL Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/invidious/jsonify/api_v1/video_json.cr
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,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
Expand Down
8 changes: 8 additions & 0 deletions src/invidious/videos/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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

Expand Down
Loading