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
Changes from 2 commits
Commits
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
5 changes: 4 additions & 1 deletion controller/lib/youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

.(!is_null($fVideo) " -f $fVideo": '')
.($ExtractAudio? " -x": '')
.($this->ForceIPv4 ? ' -4' : '')
.(is_null($Proxy) ? '' : $Proxy)
);

Expand Down