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

Merged
merged 28 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 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,7 @@ 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"]?
end
end
end
Expand Down
18 changes: 13 additions & 5 deletions src/invidious/videos/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "json"
#
# TODO: "compactRadioRenderer" (Mix) and
# TODO: Use a proper struct/class instead of a hacky JSON object
def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
def parse_related_video(related : JSON::Any, published) : Hash(String, JSON::Any)?
RadoslavL marked this conversation as resolved.
Show resolved Hide resolved
return nil if !related["videoId"]?

# The compact renderer has video length in seconds, where the end
Expand Down Expand Up @@ -47,6 +47,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" => published,
}
end

Expand Down Expand Up @@ -92,7 +93,7 @@ def extract_video_info(video_id : String, proxy_region : String? = nil)
player_response = player_response.merge(next_response)
end

params = parse_video_info(video_id, player_response)
params = parse_video_info(video_id, player_response, proxy_region)
params["reason"] = JSON::Any.new(reason) if reason

new_player_response = nil
Expand Down Expand Up @@ -157,7 +158,7 @@ def try_fetch_streaming_data(id : String, client_config : YoutubeAPI::ClientConf
end
end

def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any)) : Hash(String, JSON::Any)
def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any), proxy_region : String? = nil) : Hash(String, JSON::Any)
RadoslavL marked this conversation as resolved.
Show resolved Hide resolved
# Top level elements

main_results = player_response.dig?("contents", "twoColumnWatchNextResults")
Expand Down Expand Up @@ -235,7 +236,14 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
.dig?("secondaryResults", "secondaryResults", "results")
secondary_results.try &.as_a.each do |element|
if item = element["compactVideoRenderer"]?
related_video = parse_related_video(item)
time_text = item["publishedTimeText"]?
if !time_text.nil?
time = decode_date(item["publishedTimeText"].to_s)
published1 = JSON::Any.new(time.to_unix.to_s)
else
published1 = JSON::Any.new("")
end
related_video = parse_related_video(item, published1)
RadoslavL marked this conversation as resolved.
Show resolved Hide resolved
related << JSON::Any.new(related_video) if related_video
end
end
Expand All @@ -250,7 +258,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any

player_overlays.try &.as_a.each do |element|
if item = element["endScreenVideoRenderer"]?
related_video = parse_related_video(item)
related_video = parse_related_video(item, JSON::Any.new(""))
RadoslavL marked this conversation as resolved.
Show resolved Hide resolved
related << JSON::Any.new(related_video) if related_video
end
end
Expand Down