-
Notifications
You must be signed in to change notification settings - Fork 86
Update youtube.php #220
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?
Update youtube.php #220
Conversation
Try to solve e-alfred#219
Optimization
controller/lib/youtube.php
Outdated
@@ -59,7 +59,10 @@ public function getVideoData($ExtractAudio = false) | |||
$fVideo = escapeshellarg($this->YTDLVideoFormat); | |||
$Output = shell_exec( | |||
$this->YTDLBinary.' -i \''.$this->URL.'\' --get-url --get-filename' | |||
.($ExtractAudio?" -f $fAudio -x":" -f $fVideo").($this->ForceIPv4 ? ' -4' : '') | |||
.(!is_null($fAudio) " -f $fAudio": '') |
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 line has a wrong syntax. The "ternary operator" works like this
(!is_null($fAudio) ? " -f $fAudio" : '')
(you missed the ?`).
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 now changes the beheviour from before. If $ExtractAudio
was true it added -f $fAudio
and -x
. This now changed. If $fAudio
isset it adds -f
as well. According to the youtube-dl doc -f
is for video only. If $fAudio
and $fVideo
isset it adds two -f
what doen't look correct to me.
Could you please have another look here?
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, I did update to your 1st comment.
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 now changes the beheviour from before. If $ExtractAudio was true it added -f $fAudio and -x.
Yes, my Idea was if user set Audio Format, than he expect to have this audio settings when extracting audio only AND downloading video. What was before is Audio setting is only active when user extracts Audio only. Those two behaviors are different and personally I prefer to have 1st one.
But if you thing the 2nd is correct one, than it can be send not with -f
, but rather with following options:
--audio-format FORMAT Specify audio format: "best", "aac",
"flac", "mp3", "m4a", "opus", "vorbis",
or "wav"; "best" by default; No effect
without -x
--audio-quality QUALITY Specify ffmpeg/avconv audio quality,
insert a value between 0 (better) and 9
(worse) for VBR or a specific bitrate
like 128K (default 5)
According to the youtube-dl doc -f is for video only.
You right, documentation does not highlight it directly, but in a section https://github.com/ytdl-org/youtube-dl/blob/master/README.md#format-selection-examples you can see that Video and Audio options could be combined after -f
key. E.g.
youtube-dl -f 'bestvideo[height<=480]+bestaudio/best[height<=480]'
I did few tries and this works perfect also for:
youtube-dl -f 'bestvideo[height<=480]' -f 'bestaudio/best[height<=480]'
youtube-dl -f 'bestvideo[height<=480]' -f 'bestaudio/best[height<=480]' -x
And what I try also:
youtube-dl --get-url --get-filename -f "best[width<=1920]" -f "bestaudio[abr<=75]" -x -4 -s
youtube-dl --get-url --get-filename -f "best[width<=1920]" -f "bestaudio[abr<=75]" -4 -s
youtube-dl --get-url --get-filename -x -4 -s
Does NOT work for
youtube-dl --get-url --get-filename -f -4
In #219 it is highlighted that -f
must not be send when nothing is set in fAudio
/fVideo
, so I divide it to 2 checks and -f
should be suppressed for empty keys.
After investigations I find out that setting fAudio
and fVideo
together with -x
will simply ignores video values and extract audio only as expected, so there is no harm to add fVideo
even when user extracts audio only. Of course we can add here 2nd check for audio only, but to be honest IDK how.
Hi @GAS85 thanks for your contribution. See my comments in the code. |
Correction according comment https://github.com/e-alfred/ocdownloader/pull/220/files#r725669645
Try to solve #219 and partly solve #187... If it works 👯
Never used PHP before, please check it!!!
Update:
I play around with command line and it is possible to pass Audio and/or Video Quality with key
-x
without problems as Quality parameters are only Optional values. Even if they are not set - no harm at all, best from the tool point of view will be downloaded.Only error is when Audio and/or Video are not set, but we send key
-f
with empty value.