mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-01-31 04:58:21 +00:00
63 lines
33 KiB
HTML
63 lines
33 KiB
HTML
|
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Command-line: youtube-dl</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
|
||
|
MathJax = {
|
||
|
tex: {
|
||
|
inlineMath: [ ['$','$'], ['\(','\)'] ],
|
||
|
displayMath: [ ['$$','$$'], ['[',']'] ]
|
||
|
},
|
||
|
options = {
|
||
|
processHtmlClass = "math"
|
||
|
}
|
||
|
}
|
||
|
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Command-line: youtube-dl</h1><section class="post-metadata"><span>Date: <!-- -->2021-07-08 17:36:26 +08:00</span><span>Date modified: <!-- -->2022-04-22 11:25:43 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/cli.youtube-dl#synopsis" class="toc-link toc-link-h1">Synopsis</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cli.youtube-dl#options" class="toc-link toc-link-h1">Options</a><ol class="toc-level toc-level-2"><li class="toc-item toc-item-h2"><a href="/wiki/cli.youtube-dl#output-formats" class="toc-link toc-link-h2">Output formats</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.youtube-dl#date-ranges" class="toc-link toc-link-h2">Date ranges</a></li></ol></li><li class="toc-item toc-item-h1"><a href="/wiki/cli.youtube-dl#examples" class="toc-link toc-link-h1">Examples</a><ol class="toc-level toc-level-2"><li class="toc-item toc-item-h2"><a href="/wiki/cli.youtube-dl#download-the-thumbnail-and-the-audio-of-the-video" class="toc-link toc-link-h2">Download the thumbnail and the audio of the video</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.youtube-dl#download-an-entire-album" class="toc-link toc-link-h2">Download an entire album</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.youtube-dl#specific-video-download-requirements" class="toc-link toc-link-h2">Specific video download requirements</a></li><li class="toc-item toc-item-h2"><a href="/wiki/cli.youtube-dl#check-the-first-50-videos-at-certain-date-range" class="toc-link toc-link-h2">Check the first 50 videos at certain date range</a></li></ol></li></ol></nav><p>One of the archivists' best friends.
|
||
|
At least you don't have to go to those shady YouTube conversion sites anymore when you have a <a href="https://ytdl-org.github.io/youtube-dl/supportedsites.html">complete list of other video sites</a> you can download from.
|
||
|
</p><p>Take note, I use <a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a>.
|
||
|
Any yt-dlp-specific options should be in the appropriate note.
|
||
|
</p><p>For complete information, you can always inspect <code class="inline-verbatim">youtube-dl.1</code> manual page.
|
||
|
</p><h1 id="synopsis">Synopsis</h1><pre class="src-block"><code class="language-shell">youtube-dl [OPTIONS...] [URLS...]
|
||
|
</code></pre><h1 id="options">Options</h1><ul><li><p><code class="inline-verbatim">--add-metadata</code> adds metadata to the resulting file after download
|
||
|
</p></li><li><p><code class="inline-verbatim">--audio-format EXTENSION</code> downloads the video with the select format of "opus", "mp3", "opus", and "vorbis";
|
||
|
but there is also the convenient "best" option
|
||
|
</p></li><li><p><code class="inline-verbatim">--audio-quality QUALITY</code> sets the quality of the audio from 0 to 9, best to worst respectively;
|
||
|
bitrates are also accepted (e.g., <code class="inline-verbatim">320K</code>, <code class="inline-verbatim">1M</code>)
|
||
|
</p></li><li><p><code class="inline-verbatim">--date RANGE</code> finds videos that are uploaded from a certain date range.
|
||
|
See the <a href="/wiki/Date%20ranges">Date ranges</a> section to see the format required.
|
||
|
</p></li><li><p><code class="inline-verbatim">--dateafter RANGE</code> and <code class="inline-verbatim">--datebefore RANGE</code> is a similar option to <code class="inline-verbatim">--date</code> but to find videos before or after the specified date range, respectively.
|
||
|
Accepts the same format as <code class="inline-verbatim">--date</code>.
|
||
|
</p></li><li><p><code class="inline-verbatim">--list-extractors</code> prints a list of supported sites and their specific features.
|
||
|
</p></li><li><p><code class="inline-verbatim">--format QUALITY</code> downloads the video with the format shown in <code class="inline-verbatim">--list-format</code>;
|
||
|
there are convenient options such as <code class="inline-verbatim">bestaudio</code> and <code class="inline-verbatim">bestvideo</code> referring to the best quality it could find
|
||
|
</p></li><li><p><code class="inline-verbatim">-o, --output STRING</code> formats the resulting filename of the tracks to be downloaded
|
||
|
</p></li><li><p><code class="inline-verbatim">--no-overwrite</code> throws an error if the file already exists which is handy for scripts
|
||
|
</p></li><li><p><code class="inline-verbatim">-x, --extract-audio</code> extracts only the audio track
|
||
|
</p></li></ul><h2 id="output-formats">Output formats</h2><p>For <code class="inline-verbatim">--output</code> option, there are a lot of things to consider naming your files.
|
||
|
You may want to automate them yourself but <code class="inline-verbatim">youtube-dl</code> has plenty of options from the get-go.
|
||
|
</p><p>The following code is the sensible default output string.
|
||
|
</p><pre class="src-block"><code>%(playlist_index)02d-%(title)s.%(ext)s
|
||
|
</code></pre><p>A few of the usual stuff I use:
|
||
|
</p><ul><li><p><code class="inline-verbatim">title</code> (string) is the title of the track
|
||
|
</p></li><li><p><code class="inline-verbatim">ext</code> (string) is the extension to be used; pretty much recommended to use it
|
||
|
</p></li><li><p><code class="inline-verbatim">creator</code> (string) and <code class="inline-verbatim">uploader</code> (string)
|
||
|
</p></li></ul><p>A lot of the things I have to do is to download multiple tracks from an album or playlist.
|
||
|
Unfortunately, these are often different from one site to another.
|
||
|
</p><ul><li><p><code class="inline-verbatim">playlist_index</code> (number) indicates the position of the track in a playlist.
|
||
|
These are usually used from YouTube and Soundcloud playlists.
|
||
|
</p></li><li><p><code class="inline-verbatim">track_number</code> (number) is the position of the track from an album.
|
||
|
Usually, these are used from Bandcamp and Vimeo playlists.
|
||
|
</p></li></ul><h2 id="date-ranges">Date ranges</h2><p>The options <code class="inline-verbatim">--date</code> and the like accept a certain format for date ranges in <code class="inline-verbatim">(now|today)[-|+][\\d+](day|week|month|year)s?</code> or <code class="inline-verbatim">YYYYMMDD</code> for absolute date.
|
||
|
</p><table><thead><tr><th>Example</th><th>Description</th></tr></thead><tbody><tr><td><code class="inline-verbatim">now-2weeks</code></td><td>From today to 2 weeks ago.</td></tr><tr><td><code class="inline-verbatim">today+3days</code></td><td>From today to 3 days from now.</td></tr><tr><td><code class="inline-verbatim">20000505</code></td><td>Equivalent to <code class="inline-verbatim">2000-05-05</code>.</td></tr></tbody></table><h1 id="examples">Examples</h1><p>Here is an entryway into your newfound archiving habit.
|
||
|
Enjoy! :)
|
||
|
</p><h2 id="download-the-thumbnail-and-the-audio-of-the-video">Download the thumbnail and the audio of the video</h2><p>Very simple.
|
||
|
Very useful as most of the thumbnails can go to high resolution and if you need them for some reason.
|
||
|
</p><pre class="src-block"><code class="language-shell">youtube-dl --write-thumbnail --extract-audio https://www.youtube.com/watch?v=wy9VvdaLuSs
|
||
|
</code></pre><h2 id="download-an-entire-album">Download an entire album</h2><p>Though, you should look at the supported sites if it supports downloading an album out of the URL.
|
||
|
In this example, we have Bandcamp.
|
||
|
</p><pre class="src-block"><code class="language-shell">youtube-dl --output '%(track_number)02d-%(title)s.%(ext)s' --format bestaudio https://gametal.bandcamp.com/album/side-quests-vol-3
|
||
|
</code></pre><h2 id="specific-video-download-requirements">Specific video download requirements</h2><p>In this example, I want to download a video with a width of 1080px and the best video and audio at 320Kbit/s.
|
||
|
Oh, and the video should be in MP4 and the audio in Opus.
|
||
|
</p><p>This is will only succeed if the format is available to download which you can do with <code class="inline-verbatim">--list-format</code>.
|
||
|
</p><pre class="src-block"><code class="language-shell">youtube-dl --format 'bestvideo[width=1080,ext=mp4]+bestaudio[abr=320K,ext=opus]' https://www.youtube.com/watch?v=wy9VvdaLuSs
|
||
|
</code></pre><h2 id="check-the-first-50-videos-at-certain-date-range">Check the first 50 videos at certain date range</h2><p>In this example, I want to download videos from <a href="roam:David Revoy">roam:David Revoy</a>'s YouTube channel that uploaded up to 2 months ago while checking only the first 50 videos.
|
||
|
This is a useful template especially if the channel has a large selection of videos.
|
||
|
Also useful if you're checking for videos daily to mitigate against potential bans from overusing it.
|
||
|
</p><pre class="src-block"><code class="language-shell">youtube-dl --playlist-end 50 --dateafter 'today-2weeks' "https://www.youtube.com/c/DavidRevoy"
|
||
|
</code></pre></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2021-07-08 17:36:26 +08:00\"","date_modified":"\"2022-04-22 11:25:43 +08:00\"","language":"en","source":""},"title":"Command-line: youtube-dl","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"synopsis"},"children":[{"type":"text","value":"Synopsis"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.youtube-dl#synopsis"},"children":[{"type":"text","value":"Synopsis"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"options"},"children":[{"type":"text","value":"Options"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.youtube-dl#options"},"children":[{"type":"text","value":"Options"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"output-formats"},"children":[{"type":"text","value":"Output formats"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.youtube-dl#output-formats"},"children":[{"type":"text","value":"Output formats"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"date-ranges"},"children":[{"type":"text","value":"Date ranges"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.youtube-dl#date-ranges"},"children":[{"type":"text","value":"Date ranges"}]}]}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.youtube-dl#examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"download-the-thumbnail-and-the-audio-of-the-video"},"children":[{"type":"text","value":"Download the thumbnail and the audio of the video"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.youtube-dl#download-the-thumbnail-and-the-audio-of-the-video"},"children":[{"type":"text","value":"Download the thumbnail and the audio of the video"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"download-an-entire-album"},"children":[{"type":"text","value":"Download an entire album"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.youtube-dl#download-an-entire-album"},"children":[{"type":"text","value":"Download an entire album"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"specific-video-download-requirements"},"children":[{"type":"text","value":"Specific video download requirements"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.youtube-dl
|