index.html (10717B)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <link rel="stylesheet" href="/style.css" type="text/css"> 5 <meta charset="utf-8"> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 <link rel="stylesheet" type="text/css" href="/style.css"> 9 <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🏕️</text></svg>"> 10 <title></title> 11 </head> 12 <body> 13 <div id="page-wrapper"> 14 <div id="header" role="banner"> 15 <header class="banner"> 16 <div id="banner-text"> 17 <span class="banner-title"><a href="/">beauhilton</a></span> 18 </div> 19 </header> 20 <nav> 21 <a href="/about">about</a> 22 <a href="/now">now</a> 23 <a href="/thanks">thanks</a> 24 <a class="nav-active" href="/posts">posts</a> 25 <a href="https://notes.beauhilton.com">notes</a> 26 <a href="https://talks.beauhilton.com">talks</a> 27 <a href="https://git.beauhilton.com">git</a> 28 <a href="/contact">contact</a> 29 <a href="/atom.xml">rss</a> 30 </nav> 31 </div> 32 <main> 33 <h1> 34 yt-dlp Nix config 35 </h1> 36 <p> 37 <time id="post-date">2023-10-18</time> 38 </p> 39 <p id="post-excerpt"> 40 yt-dlp is an incredibly useful and customizable tool 41 for downloading online videos 42 from YouTube and elsewhere. 43 Here's my setup 44 (declared in Nix, but easily generalizable). 45 </p> 46 <p> 47 If you just want the config, scroll to the bottom (ignore the 48 ramblings under the asterisk). 49 </p> 50 <h2> 51 yt-dlp 52 </h2> 53 <p> 54 youtube-dl was, for years, the de facto standard for retrieving 55 videos from YouTube (and other websites - e.g. Vimeo) for local use, but 56 eventually it got old and crufty. 57 </p> 58 <p> 59 <a href="https://github.com/yt-dlp/yt-dlp">yt-dlp</a> is a fork of 60 youtube-dl that is more actively maintained, with many upgrades. 61 </p> 62 <p> 63 It has sane defaults, but I have a few things I change to make it 64 suit my uses. 65 </p> 66 <p> 67 I mostly use it to download instructional videos so they’re easier to 68 use: no getting interrupted by ads whenever I scrub back and forth to 69 find or rewatch a particular section, and I can proceed without an 70 internet connection. 71 </p> 72 <p> 73 It’s also a boon for archival of any video you use frequently for any 74 reason, e.g. in an educational setting - if you have a lesson plan that 75 depends on a clip from an online video, it is wise to have your own copy 76 of the video, both to reduce dependence on finicky wifi and to make it 77 more likely you’ll have the vid for every time you repeat this lesson in 78 the future. Videos go offline for strange, sundry, and unpredictable 79 reasons. 80 </p> 81 <p> 82 (I maintain that YouTube and related video sites, taken as a whole, 83 are the single greatest source of procedural knowledge ever created by 84 humankind* - the problems that threaten their utility are, first, 85 curation, and second, durability) 86 </p> 87 <h2> 88 configuring 89 </h2> 90 <p> 91 yt-dlp accepts a config file, usually placed at 92 <code>~/.config/yt-dlp/config</code>, so you don’t have to have a long 93 string of flags and options in your shell command to yt-dlp (you can 94 override your config file with shell options, so it’s reasonable to set 95 your defaults to your most common use and not worry about messing up 96 some divergent situation that may come up). 97 </p> 98 <p> 99 For example, to download the whole <a href="https://www.youtube.com/c/JohnWatsonRooney">JohnWatsonRooney 100 YouTube channel</a>, all I had do was: 101 </p> 102 <pre tabindex="0"><code class="language-sh"><span class="hl kwb">cd</span> youtube<span class="hl kwb">-downloads</span><span class="hl opt">/</span>JohnWatsonRooney 103 yt<span class="hl kwb">-dlp</span> <span class="hl sng">"https://www.youtube.com/c/JohnWatsonRooney"</span> 104 </code></pre> 105 <p> 106 And it did something like this: 107 </p> 108 <p> 109 <img src="/images/yt-dlp-downloading-example.png" alt="yt-dlp downloading example"> 110 </p> 111 <p> 112 Resulting in: 113 </p> 114 <p> 115 <img src="/images/yt-dlp-filename-example.jpg" alt="yt-dlp filename example"> 116 </p> 117 <p> 118 In the second screenshot you can see that some files are still in 119 process - when all the parts are downloaded, yt-dlp smushes them into an 120 mkv container, so the videos/thumbnails/subtitle files are clean and 121 accessible to most video players. 122 </p> 123 <h2> 124 config 125 </h2> 126 <p> 127 Here’s my config file, with some annotation. 128 </p> 129 <p> 130 I’m using Nix with Home Manager, but you can translate this into the 131 usual yt-dlp config file syntax with ease. 132 </p> 133 <p> 134 One of the great things about Nix is that it lets me group 135 installation and configuration for programs that make sense together - 136 here, I want to use aria2 as the downloader, so I declare the aria2 137 options to pass to yt-dlp, and also make sure aria2 is installed (it’s 138 ok if you installed aria2 in another part of your setup - if a program 139 is declared for installation in multiple places, Nix is smart enough to 140 install it only once, so it’s often wise to err on the side of 141 bundling). 142 </p> 143 <p> 144 If I take this config to any other machine with Nix installed, I’ll 145 get the whole setup including dependencies. This example is very simple, 146 just adding another program, but the principle scales to arbitrarily 147 complex setups. 148 </p> 149 <pre tabindex="0"><code class="language-nix"><span class="hl opt">{</span> 150 programs<span class="hl opt">.</span>yt<span class="hl opt">-</span>dlp <span class="hl opt">= {</span> 151 enable <span class="hl opt">=</span> <span class="hl kwb">true</span><span class="hl opt">;</span> 152 settings <span class="hl opt">= {</span> 153 embed<span class="hl opt">-</span>chapters <span class="hl opt">=</span> <span class="hl kwb">true</span><span class="hl opt">;</span> <span class="hl slc"># embed all the things</span> 154 embed<span class="hl opt">-</span>metadata <span class="hl opt">=</span> <span class="hl kwb">true</span><span class="hl opt">;</span> 155 embed<span class="hl opt">-</span>thumbnail <span class="hl opt">=</span> <span class="hl kwb">true</span><span class="hl opt">;</span> 156 convert<span class="hl opt">-</span>thumbnail <span class="hl opt">=</span> <span class="hl sng">"jpg"</span><span class="hl opt">;</span> 157 <span class="hl slc"># so every file manager can show the thumbnail - webp support is not quite universal</span> 158 embed<span class="hl opt">-</span>subs <span class="hl opt">=</span> <span class="hl kwb">true</span><span class="hl opt">;</span> 159 sub<span class="hl opt">-</span>langs <span class="hl opt">=</span> <span class="hl sng">"all"</span><span class="hl opt">;</span> 160 <span class="hl slc"># subtitle files are very small, </span> 161 <span class="hl slc"># and sometimes language names are declared badly, </span> 162 <span class="hl slc"># so worth it to grab them all</span> 163 downloader <span class="hl opt">=</span> <span class="hl sng">"aria2c"</span><span class="hl opt">;</span> 164 downloader<span class="hl opt">-</span>args <span class="hl opt">=</span> <span class="hl sng">"aria2c:'-c -x16 -s16 -k2M'"</span><span class="hl opt">;</span> 165 <span class="hl slc"># -c is resume if interrupted ("continue"), </span> 166 <span class="hl slc"># -x is max connections to a server, </span> 167 <span class="hl slc"># -s is number of connections used for download of a specific file, </span> 168 <span class="hl slc"># -k is size of chunks</span> 169 download<span class="hl opt">-</span>archive <span class="hl opt">=</span> <span class="hl sng">"yt-dlp-archive.txt"</span><span class="hl opt">;</span> 170 <span class="hl slc"># writes a file to the current directory specifying which files have already been downloaded - </span> 171 <span class="hl slc"># nice for updating your collection of a channel's videos </span> 172 <span class="hl slc"># (just run the download command again and it will grab only what you're missing)</span> 173 restrict<span class="hl opt">-</span>filenames <span class="hl opt">=</span> <span class="hl kwb">true</span><span class="hl opt">;</span> <span class="hl slc"># disallow spaces, weird characters, etc.</span> 174 output <span class="hl opt">=</span> <span class="hl sng">"%(upload_date>%Y-%m-%d)s--%(uploader)s--%(title)s--%(id)s.%(ext)s"</span><span class="hl opt">;</span> 175 <span class="hl slc"># I like to be able to sort by date </span> 176 <span class="hl slc"># and have enough info in the filename </span> 177 <span class="hl slc"># so I don't need to open it to find out what it is, </span> 178 <span class="hl slc"># so I include the:</span> 179 <span class="hl slc"># - ISO 8601-style date</span> 180 <span class="hl slc"># - uploader's name</span> 181 <span class="hl slc"># - title of the video</span> 182 <span class="hl slc"># - video ID (for easy copy pasta if I ever want to find it online, </span> 183 <span class="hl slc"># e.g. to see the comment section or show notes.)</span> 184 <span class="hl opt">};</span> 185 <span class="hl opt">};</span> 186 programs<span class="hl opt">.</span>aria2 <span class="hl opt">= {</span> 187 enable <span class="hl opt">=</span> <span class="hl kwb">true</span><span class="hl opt">;</span> 188 <span class="hl opt">};</span> 189 <span class="hl opt">}</span> 190 </code></pre> 191 <h2> 192 side note 193 </h2> 194 <p> 195 * Contrary to popular belief, things that go online do <em>not</em> 196 stay online forever: <a href="https://en.wikipedia.org/wiki/Digital_obsolescence">digital 197 obsolescence</a> is real, and is <a href="https://blog.archive.org/2023/03/25/the-fight-continues/">probably 198 going to get worse</a> before it gets better (“?better”). This section 199 is under an asterisk and at the end because it is a side thought, just 200 an idea that tools like yt-dlp may have import that goes beyond helping 201 me write web scrapers, build saunas, etc. - maybe they have the 202 primitives to help build a videographic Whole Earth Catalog for the 203 ages. I don’t think everything is going to explode any time soon, but 204 wouldn’t it be interesting to have a digital archive with videos, rather 205 than just text, of how to do the basic things (and some not-so-basic 206 things) that make life possible and enjoyable? Some kind of all-in-one 207 system with redundant storage and a power-supply (hand crank? solar?), 208 durable screen and speakers, to help you bootstrap the physical needs of 209 a society? I’m sure the raw content is out there. 210 </p> 211 </main> 212 <div id="footnotes"></div> 213 <footer></footer> 214 </div> 215 </body> 216 </html>