youtube-dl format options API
Asked Answered
M

2

5

Does youtube API provide the original audio you are listening from youtube as a download option? Is it perhaps the --extract-audio option?

Mensch answered 20/2, 2020 at 20:32 Comment(4)
your question is not very clear. do you mean to ask where the audio is from?Waller
When you listen to a song on youtube, it is of a certain quality etc, if we call that the original quality, does the youtube API provide it as a download option when you do: youtube-dl -F <URL> or do they provide formats of lesser quality to you.Mensch
Alright! just posted an answer. hope it helps.Waller
If you follow my answer to this question, you'll get the best video and audio in whatever format is available, and each best video + audio gets auto-merged into one file and the temporary audio + video gets deleted. Very flexible.Ramsden
R
1

More Flexibility (using shell aliases)

As mentioned, the defaults are set to download the highest quality from the provided video URL. This isn't the same as saying that it always will be so, and it certainly hasn't always been so.

I'm a fan of stability, and have better experience with specifying the options directly, as defaults have a tendency to change with versions / updates, but using the specific options would still be valid, or you'd get a warning or error.
Using the direct options I know what I end up with.
It's also more flexible.

You can choose what preferred formats to prioritize, and get the best compatible video + audio merged automatically if the requested format/quality is unavailable and you can specify a format string for naming the downloaded file, and decide where it will end up (by default it's the current working directory).

You can use a separate settings file, on the Mac its by default: ~/.config/youtube-dl/config Or, you can use an alias defined in your shell (I've named the alias :ytdl) so I just do:

:ytdl link_to_single_video

And have it set to automatically download the preferred video/audio format and merge them together at a location specified in the alias command in my shell startup file, using the naming convention I've decided it to use.

I also have a :ytdlpl playlist_id alias that downloads complete playlists to a specified folder:

/playlists/[name_from_playlist_title]/[episode_num_and_name_from_playlist].[ext]

I've done this by setting up the two aliases:

# Download best mp4 format available or other format if no mp4 is available
alias :ytdl='/usr/local/bin/youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" -o "/Volumes/SSD/Video/YTDL/%(title)s.%(ext).s"'

# Download YouTube playlist videos in separate directory indexed by video order in a playlist
alias :ytdlpl='/usr/local/bin/youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" -o "/Volumes/SSD/Video/YTDL/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s"'


How you choose to do this is personal preference, but this works perfectly for my needs at least! 👍

Ramsden answered 3/3, 2020 at 23:50 Comment(2)
You are simply writing a shorthand of a command type. youtube-dl in practicality always downloads the best video available for you. Aliases are only useful for specificity. Supposing you want to download specific versions but the question is not how to download several versions but if the quality is top notch or not. Also consider that with your commands, should the specified versions not be available youtubedl may switch to the next best version available. or if a version is higher than what you define, you get a lower available quality.Waller
@Waller : I know that I'm "simply writing a shorthand of a command", that's kinda what an alias is for... Besides, with the given options I get exactly the behavior you ask me to "consider": I get the best Video + Audio available, preferred format being .mp4, if that doesn't exist I'll get whatever other format available in highest quality, if not any is available in highest quality, it will go down the ladder, starting with second best .mp4 available.Ramsden
W
6

By default youtube-dl tries to download the best available quality, i.e. if you want the best quality you don't need to pass any special options, youtube-dl will guess it for you by default.

Since the end of April 2015 and version 2015.04.26, youtube-dl uses -f bestvideo+bestaudio/best as the default format selection (see #5447(https://github.com/ytdl-org/youtube-dl/issues/5447), #5456(https://github.com/ytdl-org/youtube-dl/issues/5456)).

If you want to preserve the old format selection behavior (prior to youtube-dl 2015.04.26), i.e. you want to download the best available quality media served as a single file, you should explicitly specify your choice with -f best. You may want to add it to the configuration file in order not to type it every time you run youtube-dl.

Reference: https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme

Let me know if this helps. if not, we could figure it out in specifics.

UPDATE

Here are a few commands that could come handy;

# Download best mp4 format available or any other best if no mp4 available
$ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'

# Download best format available but no better than 480p
$ youtube-dl -f 'bestvideo[height<=480]+bestaudio/best[height<=480]'

# Download best video only format but no bigger than 50 MB
$ youtube-dl -f 'best[filesize<50M]'

# Download best format available via direct link over HTTP/HTTPS protocol
$ youtube-dl -f '(bestvideo+bestaudio/best)[protocol^=http]'

# Download the best video format and the best audio format without merging them
$ youtube-dl -f 'bestvideo,bestaudio' -o '%(title)s.f%(format_id)s.%(ext)s'
Waller answered 2/3, 2020 at 8:16 Comment(4)
Aha, so now (in your "Update") you're basically providing the same option as you were criticized me for using in my alias... First example in your "handy" commands are exactly what I use in my answer, and probably the only one most people will care about using. Also, I provide more alternatives for formatting the file name and location etc. Your copy / paste "update" is straight from: github.com/ytdl-org/youtube-dl/blob/master/… Well, hope you're fine and all...Ramsden
My comment with your first answer which you later updated did not answer the question. The question was does youtbe-dl provide same high quality videos (paraphrasing) and your answer gave a list of aliases. After my comment, you fixed your answer with details which added clarity and answered the question. In my answer, I added a reference to github (reliable source) and in my update, as is a norm on Stack Overflow to include information from reference links, I included the commands for clarity. I fail to see how that is wrong.Waller
Ok. The logic is flawed, but I don't believe the comments are meant for personal arguing, so I'll let you have the last saying in this.Ramsden
If any of my comments came offensive. I apologize! Your current solution is awesome and I have personally learnt from it. Thank youWaller
R
1

More Flexibility (using shell aliases)

As mentioned, the defaults are set to download the highest quality from the provided video URL. This isn't the same as saying that it always will be so, and it certainly hasn't always been so.

I'm a fan of stability, and have better experience with specifying the options directly, as defaults have a tendency to change with versions / updates, but using the specific options would still be valid, or you'd get a warning or error.
Using the direct options I know what I end up with.
It's also more flexible.

You can choose what preferred formats to prioritize, and get the best compatible video + audio merged automatically if the requested format/quality is unavailable and you can specify a format string for naming the downloaded file, and decide where it will end up (by default it's the current working directory).

You can use a separate settings file, on the Mac its by default: ~/.config/youtube-dl/config Or, you can use an alias defined in your shell (I've named the alias :ytdl) so I just do:

:ytdl link_to_single_video

And have it set to automatically download the preferred video/audio format and merge them together at a location specified in the alias command in my shell startup file, using the naming convention I've decided it to use.

I also have a :ytdlpl playlist_id alias that downloads complete playlists to a specified folder:

/playlists/[name_from_playlist_title]/[episode_num_and_name_from_playlist].[ext]

I've done this by setting up the two aliases:

# Download best mp4 format available or other format if no mp4 is available
alias :ytdl='/usr/local/bin/youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" -o "/Volumes/SSD/Video/YTDL/%(title)s.%(ext).s"'

# Download YouTube playlist videos in separate directory indexed by video order in a playlist
alias :ytdlpl='/usr/local/bin/youtube-dl -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" -o "/Volumes/SSD/Video/YTDL/%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s"'


How you choose to do this is personal preference, but this works perfectly for my needs at least! 👍

Ramsden answered 3/3, 2020 at 23:50 Comment(2)
You are simply writing a shorthand of a command type. youtube-dl in practicality always downloads the best video available for you. Aliases are only useful for specificity. Supposing you want to download specific versions but the question is not how to download several versions but if the quality is top notch or not. Also consider that with your commands, should the specified versions not be available youtubedl may switch to the next best version available. or if a version is higher than what you define, you get a lower available quality.Waller
@Waller : I know that I'm "simply writing a shorthand of a command", that's kinda what an alias is for... Besides, with the given options I get exactly the behavior you ask me to "consider": I get the best Video + Audio available, preferred format being .mp4, if that doesn't exist I'll get whatever other format available in highest quality, if not any is available in highest quality, it will go down the ladder, starting with second best .mp4 available.Ramsden

© 2022 - 2024 — McMap. All rights reserved.