-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Towards using only next endpoint for the major data. (Partial solution to #5003) #5237
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
base: master
Are you sure you want to change the base?
Conversation
Looks like some of the commits in this branch are outdated as it is missing changes that are already in the master branch such as #4934. |
That may well be. I don't understand enough crystal to be able to identify redundant code; I could only transplant changes that @unixfox made. If you tell me which (parts of) commits I shall omit, I can of course do that. |
There's also this commit that looks important: mk-pmb@108ee36
Shouldn't really belong to this PR though. Update: I learned enough crystal to do the early return transformation, but now I see that the common tail below has grown with companion stuff, so probably now the better choice is to factor out the "then" branch into its own function. |
3b761f4
to
a9dfc70
Compare
Ok yeah, some things seem to have been broken by git's rebase. I now discovered the UTC fallback, and it seems obvious even to me that the rebased commit does the opposite of what it claims. I removed that commit. |
return false if badges.nil? | ||
|
||
badges.as_a.each do |badge| | ||
icon_type = badge.dig("metadataBadgeRenderer", "icon", "iconType").as_s | ||
|
||
return true if icon_type == "PRIVACY_UNLISTED" | ||
end | ||
|
||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false if badges.nil? | |
badges.as_a.each do |badge| | |
icon_type = badge.dig("metadataBadgeRenderer", "icon", "iconType").as_s | |
return true if icon_type == "PRIVACY_UNLISTED" | |
end | |
return false | |
return false if badges.nil? | |
badges.as_a.each do |badge| | |
icon_type = badge.dig("metadataBadgeRenderer", "icon", "iconType").as_s | |
return true if icon_type == "PRIVACY_UNLISTED" | |
end | |
return false |
published_txt = video_primary_renderer | ||
.try &.dig?("dateText", "simpleText") | ||
|
||
if published_txt.try &.as_s.includes?("ago") && !published_txt.nil? | ||
published = decode_date(published_txt.as_s.lchop("Started streaming ")) | ||
elsif published_txt && published_txt.try &.as_s.matches?(/(\w{3} \d{1,2}, \d{4})$/) | ||
published = Time.parse(published_txt.as_s.match!(/(\w{3} \d{1,2}, \d{4})$/)[0], "%b %-d, %Y", Time::Location::UTC) | ||
else | ||
published = Time.utc | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this should be more efficient
video_primary_renderer.try(&.dig?("dateText", "simpleText")).try do | published_txt |
published_txt = published_txt.as_s
published = if published_txt.includes?("ago")
decode_date(published_txt.lchop("Started streaming "))
elsif matched_time = published_txt.match(/(\w{3} \d{1,2}, \d{4})$/)
Time.parse(matched_time[0], "%b %-d, %Y", Time::Location::UTC)
end
end
published ||= Time.utc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also try using the scheduledStartTime
prior to the other attempts
https://github.com/iv-org/invidious/pull/5003/files#r1807376801
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your feedback! Unfortunately I know almost nothing about crystal so I'd rather not try and implement actual changes. In this PR I just rebased @unixfox's code in hopes to get it merged asap to avoid even more branch divergence and thus even more effort for rebasing. I hope it's not too late already.
If it's important to you that I update the PR, I can try and apply all the changes you requested. However, since those are your changes, wouldn't it be more clear to merge and then apply them, rather than having me apply them in unixfox's or your name? (Evem deciding that for each patch seems needlessly error-prone.)
Except of course if any of the patches introduce a critical bug, then obviously I should fix the offending code before it's merged. If so, please tell me, because I'm unable to classify the kind of changes you made.
For any code that's not actually "bad" but just "could be better" (e.g. "should be more efficient"), let's make improvements a separate PR. After all, this PR is titled "Towards … (Partial solution …)" because I know it's not perfect, it's just a useful step, or at least I hope it is. And since most contributors here have a tendency to only occasionally have time for this project, I think merging acceptable parts as early as possible is a good approach.
if live_now.nil? | ||
live_now = video_primary_renderer | ||
.try &.dig?("viewCount", "videoViewCountRenderer", "isLive").try &.as_bool | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if live_now.nil? | |
live_now = video_primary_renderer | |
.try &.dig?("viewCount", "videoViewCountRenderer", "isLive").try &.as_bool | |
end | |
live_now ||= video_primary_renderer.try &.dig?("viewCount", "videoViewCountRenderer", "isLive").try &.as_bool |
"shortDescription" => JSON::Any.new(short_description.try &.as_s || nil), | ||
"shortDescription" => JSON::Any.new(short_description.try &.as_s || ""), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is shortDescription
not allowed to be nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea. @unixfox , do you still remember?
return false if badges.nil? | ||
|
||
badges.as_a.each do |badge| | ||
icon_type = badge.dig("metadataBadgeRenderer", "icon", "iconType").as_s | ||
|
||
return true if icon_type == "PRIVACY_UNLISTED" | ||
end | ||
|
||
return false | ||
rescue ex | ||
LOGGER.debug("Unable to parse owner badges. Got exception: #{ex.message}") | ||
LOGGER.trace("Owner badges data: #{badges.to_json}") | ||
|
||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire function could pretty much be reduced down to a single line. I don't know if the error handling + logging is intentional here but it shouldn't even be needed if you just use a dig?
instead.
return false if badges.nil? | |
badges.as_a.each do |badge| | |
icon_type = badge.dig("metadataBadgeRenderer", "icon", "iconType").as_s | |
return true if icon_type == "PRIVACY_UNLISTED" | |
end | |
return false | |
rescue ex | |
LOGGER.debug("Unable to parse owner badges. Got exception: #{ex.message}") | |
LOGGER.trace("Owner badges data: #{badges.to_json}") | |
return false | |
return badges.try(&.as_a.any?(&.dig?("metadataBadgeRenderer", "icon", "iconType").==("PRIVACY_UNLISTED"))) || false |
error_message = <<-END_HTML | ||
<div class="error_message"> | ||
<h2>#{translate(locale, "error_processing_data_youtube")}</h2> | ||
<p>#{translate(locale, message)}</p> | ||
#{error_redirect_helper(env)} | ||
</div> | ||
END_HTML |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy and pasted from my review from the original PR:
Your changes here will show the
Error while processing the data sent by YouTube
message on anyInfoException
while also removing the next steps message on allInfoException
sExample:
And
InfoException
s are raised in places unrelated to YouTube as well such as when a user inserts the wrong password.Related: #4651
"carousel_go_to": "Go to slide `x`", | ||
"error_from_youtube_unplayable": "Video unplayable due to an error from YouTube:", | ||
"error_processing_data_youtube": "Error while processing the data sent by YouTube", | ||
"refresh_page": "Refresh the page" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"refresh_page": "Refresh the page" |
<div id="player-container" class="h-box"> | ||
<%= rendered "components/player" %> | ||
</div> | ||
<% else %> | ||
<div id="player-error-container" class="h-box"> | ||
<h3> | ||
<%= video.reason %> | ||
</h3> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<div id="player-container" class="h-box"> | |
<%= rendered "components/player" %> | |
</div> | |
<% else %> | |
<div id="player-error-container" class="h-box"> | |
<h3> | |
<%= video.reason %> | |
</h3> | |
</div> | |
<div id="player-container" class="h-box"> | |
<%= rendered "components/player" %> | |
</div> | |
<% else %> | |
<div id="player-error-container" class="h-box"> | |
<h3> | |
<%= video.reason %> | |
</h3> | |
</div> |
video_details = player_response.dig?("videoDetails") | ||
video_details ||= {} of String => JSON::Any | ||
if !(microformat = player_response.dig?("microformat", "playerMicroformatRenderer")) | ||
microformat = {} of String => JSON::Any | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my discussion with @unixfox , these are the changes that I was able to salvage from #5003 that either were not critizised in code review or where I was able to apply the suggestions.