-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Add format selection criteria longside, shortside #30742
base: master
Are you sure you want to change the base?
Conversation
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.
@mk-pmb, I've created the PR for you. Do check these review items for which GH won't let me Request Changes from myself. Or you might rather create your own PR.
With my suggested changes the existing test/test_YoutubeDL.py
test succeeds. You should either add a new test case for long/short/side, or add something to the test_youtube_format_selection()
test case.
youtube_dl/YoutubeDL.py
Outdated
@@ -1484,6 +1491,17 @@ def sanitize_numeric_fields(info): | |||
sanitize_string_field(info_dict, 'id') | |||
sanitize_numeric_fields(info_dict) | |||
|
|||
def add_calculated_video_proprties(fmt): | |||
dimensions = [fmt.get(side) for side in ('width', 'height',)] |
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.
Or in 1 line:
dimensions = filter(None, [fmt.get(side) for side in ('width', 'height',)])
youtube_dl/YoutubeDL.py
Outdated
def add_calculated_video_proprties(fmt): | ||
dimensions = [fmt.get(side) for side in ('width', 'height',)] | ||
dimensions = [n for n in dimensions if n is not None] | ||
if len(dimensions): |
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.
You need both width and height to be set, otherwise long and short are indeterminate, as shown by the test error on l.1499 when trying to evaluate min(1000)
('int' object is not iterable). So:
if len(dimensions) == 2:
The doc for min()
:
min(iterable[, key])
min(arg1, arg2, *args[, key])
...
Because of the optional key
, parameter, the reasonable result min(x) -> x
isn't possible. If you don't know the length of the list whose min (resp. max) is being found, you have to say min(iter(dimensions))
rather than *dimensions
.
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.
Sorry for being late. It seems I missed a notification.
Thanks for teaching me! I hope I'll remember this trap.
The iter()
approach seemed best, but min()
and max()
throw on an empty, list, and I'd prefer to be tolerant for bad input, as in just giving 0 as the length for non-dimensional video. Thus, in my next version I'll propose min(0, 0, *dimensions)
unconditionally.
Edit: Yeah I see how this fails for min(). :D
youtube_dl/YoutubeDL.py
Outdated
'shortside': min(*dimensions), | ||
'longside': max(*dimensions), | ||
}) | ||
for fmt in info_dict['formats']: |
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.
Not all info_dict
s have a formats
key (see extractor/common.py
). In case the dimensions have been set in the top level, you could process the info_dict
as a format:
for fmt in info_dict.get('formats') or [info_dict]:
youtube_dl/YoutubeDL.py
Outdated
@@ -334,6 +334,11 @@ class YoutubeDL(object): | |||
'playlist_index', | |||
)) | |||
|
|||
_NUMERIC_FIELDS |= set(('longside', 'shortside',)) |
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 we're doing this, I'd just have these on a separate line in the original list:
'width', 'height', 'tbr', 'abr', 'asr', 'vbr', 'fps', 'filesize', 'filesize_approx',
'longside', 'shortside',
'timestamp', 'upload_year', 'upload_month', 'upload_day',
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.
As suggested in my refactor idea, IMO this list should not exist in the first place; rather, its values should be collected from the sections in code that implement them. I will not oppose anyone who decides to enact your solution, but I won't do anything that may look like approval.
Thank you for the kind gesture. I purposefully did not file a PR because my patch is not worthy of being merged into the main codebase, and never was intended to. My patch was an attempt to provide a stopgap at a time when the idea of my feature request was met with strong resistance. Someone who seemed to be a team member argued that this feature should not exist in yt-dl, so my patch was aimed at helping users merge it locally into their systems. Now if maintainers decide that the feature is worth adding, we should try and find someone who knows how to implement it cleanly and elegantly. I recommend to add the feature, but to not use my patch for it. |
The status of a commenter should be shown on the right-hand side of the message header. Your patch is in line with the existing code structure. The fields in the If this feature is to be implemented, the approach used in your patch seems fine. However it does need test(s) as I mentioned, and also updating A proposal for refactoring the format selection code ought to be a separate PR, also possibly acquiring some other recent and proposed changes from yt-dlp. |
31af229
to
5a2aca1
Compare
Nowadays I accept that argument and have updated my code to your suggestions.
Might take a while, so anyone else reading this, feel free to help out! Edit: I just discovered that I already had some tests in #30744, but accidentially closed that thread. I rebased that branch. Should I just merge them here, or make a new PR for them so we can first check if the tests would work? |
Please update this PR if you can, or start a replacement if not. Thanks. |
e685543
to
69872de
Compare
Done. I'm optimistic. Someone should look at the |
fe34885
to
bfc5707
Compare
I reviewed this again. The first ydl.process_ie_result(info_dict.copy())
# ^-- :TODO: Do we need this .copy()? The other |
bfc5707
to
8acf85a
Compare
8acf85a
to
d4f8a34
Compare
d4f8a34
to
0c1db86
Compare
I don't understand the CI errors.
but |
Please follow the guide below
x
into all the boxes [ ] relevant to your pull request (like that [x])Before submitting a pull request make sure you have:
In order to be accepted and merged into youtube-dl each piece of code must be in public domain or released under Unlicense. Check one of the following options:
What is the purpose of your pull request?
Description of your pull request and other information
Explanation of your pull request in arbitrary form goes here. Please make sure the description explains the purpose and effect of your pull request and is worded well enough to be understood. Provide as much context and examples as possible.