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

Update youtube.php #220

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Update youtube.php #220

wants to merge 3 commits into from

Conversation

GAS85
Copy link
Contributor

@GAS85 GAS85 commented Sep 14, 2021

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.

@@ -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": '')
Copy link
Contributor

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 ?`).

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@weeman1337
Copy link
Contributor

Hi @GAS85 thanks for your contribution. See my comments in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants