diff options
Diffstat (limited to '_posts/2018-12-21-using-youtube-dl-to-manage-youtube-subscriptions.md')
-rw-r--r-- | _posts/2018-12-21-using-youtube-dl-to-manage-youtube-subscriptions.md | 100 |
1 files changed, 46 insertions, 54 deletions
diff --git a/_posts/2018-12-21-using-youtube-dl-to-manage-youtube-subscriptions.md b/_posts/2018-12-21-using-youtube-dl-to-manage-youtube-subscriptions.md index b58aee9..0501ff4 100644 --- a/_posts/2018-12-21-using-youtube-dl-to-manage-youtube-subscriptions.md +++ b/_posts/2018-12-21-using-youtube-dl-to-manage-youtube-subscriptions.md @@ -5,18 +5,17 @@ layout: post lang: en ref: using-youtube-dl-to-manage-youtube-subscriptions --- -I\'ve recently read the +I've recently read the [announcement](https://www.reddit.com/r/DataHoarder/comments/9sg8q5/i_built_a_selfhosted_youtube_subscription_manager/) of a very nice [self-hosted YouTube subscription -manager](https://github.com/chibicitiberiu/ytsm). I haven\'t used -YouTube\'s built-in subscriptions for a while now, and haven\'t missed +manager](https://github.com/chibicitiberiu/ytsm). I haven't used +YouTube's built-in subscriptions for a while now, and haven't missed it at all. When I saw the announcement, I considered writing about the -solution I\'ve built on top of [youtube-dl](https://youtube-dl.org/). +solution I've built on top of [youtube-dl](https://youtube-dl.org/). -Background: the problem with YouTube ------------------------------------- +## Background: the problem with YouTube -In many ways, I agree with [André Staltz\'s view on data ownership and +In many ways, I agree with [André Staltz's view on data ownership and privacy](https://staltz.com/what-happens-when-you-block-internet-giants.html): > I started with the basic premise that "I want to be in control of my @@ -34,22 +33,20 @@ privacy](https://staltz.com/what-happens-when-you-block-internet-giants.html): > Tor bandwidth for these purposes. I'm still scratching my head with > this issue. -Even though I don\'t use most alternative services he mentions, I do +Even though I don't use most alternative services he mentions, I do watch videos from YouTube. But I also feel uncomfortable logging in to YouTube with a Google account, watching videos, creating playlists and similar things. -Using the mobile app is worse: you can\'t even block ads in there. -You\'re in less control on what you share with YouTube and Google. +Using the mobile app is worse: you can't even block ads in there. +You're in less control on what you share with YouTube and Google. -youtube-dl ----------- +## youtube-dl youtube-dl is a command-line tool for downloading videos, from YouTube -and [many other -sites](https://rg3.github.io/youtube-dl/supportedsites.html): +and [many other sites](https://rg3.github.io/youtube-dl/supportedsites.html): -``` {.shell} +```shell $ youtube-dl https://www.youtube.com/watch?v=rnMYZnY3uLA [youtube] rnMYZnY3uLA: Downloading webpage [youtube] rnMYZnY3uLA: Downloading video info webpage @@ -66,14 +63,14 @@ also has some interesting flags that we can use: which videos were already downloaded; - `--prefer-free-formats`: prefer free video formats, like `webm`, `ogv` and Matroska `mkv`; -- `--playlist-end`: how many videos to download from a \"playlist\" (a +- `--playlist-end`: how many videos to download from a "playlist" (a channel, a user or an actual playlist); - `--write-description`: write the video description to a `.description` file, useful for accessing links and extra content. Putting it all together: -``` {.shell} +```shell $ youtube-dl "https://www.youtube.com/channel/UClu474HMt895mVxZdlIHXEA" \ --download-archive ~/Nextcloud/cache/youtube-dl-seen.conf \ --prefer-free-formats \ @@ -84,7 +81,7 @@ $ youtube-dl "https://www.youtube.com/channel/UClu474HMt895mVxZdlIHXEA" \ This will download the latest 20 videos from the selected channel, and write down the video IDs in the `youtube-dl-seen.conf` file. Running it -immediately after one more time won\'t have any effect. +immediately after one more time won't have any effect. If the channel posts one more video, running the same command again will download only the last video, since the other 19 were already @@ -93,7 +90,7 @@ downloaded. With this basic setup you have a minimal subscription system at work, and you can create some functions to help you manage that: -``` {.shell} +```shell #!/bin/sh export DEFAULT_PLAYLIST_END=15 @@ -130,7 +127,7 @@ export -f download_playlist With these functions, you now can have a subscription fetching script to download the latest videos from your favorite channels: -``` {.shell} +```shell #!/bin/sh download_user ClojureTV 15 @@ -139,31 +136,30 @@ download_playlist "PLqG7fA3EaMRPzL5jzd83tWcjCUH9ZUsbX" 15 ``` Now, whenever you want to watch the latest videos, just run the above -script and you\'ll get all of them in your local machine. +script and you'll get all of them in your local machine. -Tradeoffs ---------- +## Tradeoffs -### I\'ve made it for myself, with my use case in mind +### I've made it for myself, with my use case in mind 1. Offline My internet speed it somewhat reasonable[^1], but it is really - unstable. Either at work or at home, it\'s not uncommon to loose - internet access for 2 minutes 3\~5 times every day, and stay + unstable. Either at work or at home, it's not uncommon to loose + internet access for 2 minutes 3~5 times every day, and stay completely offline for a couple of hours once every week. Working through the hassle of keeping a playlist on disk has payed off many, many times. Sometimes I even not notice when the - connection drops for some minutes, because I\'m watching a video and + connection drops for some minutes, because I'm watching a video and working on some document, all on my local computer. - There\'s also no quality adjustment for YouTube\'s web player, I - always pick the higher quality and it doesn\'t change during the + There's also no quality adjustment for YouTube's web player, I + always pick the higher quality and it doesn't change during the video. For some types of content, like a podcast with some tiny - visual resources, this doesn\'t change much. For other types of + visual resources, this doesn't change much. For other types of content, like a keynote presentation with text written on the - slides, watching on 144p isn\'t really an option. + slides, watching on 144p isn't really an option. If the internet connection drops during the video download, youtube-dl will resume from where it stopped. @@ -171,14 +167,14 @@ Tradeoffs This is an offline first benefit that I really like, and works well for me. -2. Sync the \"seen\" file +2. Sync the "seen" file I already have a running instance of Nextcloud, so just dumping the `youtube-dl-seen.conf` file inside Nextcloud was a no-brainer. You could try putting it in a dedicated git repository, and wrap the script with an autocommit after every run. If you ever had a merge - conflict, you\'d simply accept all changes and then run: + conflict, you'd simply accept all changes and then run: ``` {.shell} $ uniq youtube-dl-seen.conf > youtube-dl-seen.conf @@ -186,22 +182,22 @@ Tradeoffs to tidy up the file. -3. Doesn\'t work on mobile +3. Doesn't work on mobile My primary device that I use everyday is my laptop, not my phone. It works well for me this way. - Also, it\'s harder to add ad-blockers to mobile phones, and most - mobile software still depends on Google\'s and Apple\'s blessing. + Also, it's harder to add ad-blockers to mobile phones, and most + mobile software still depends on Google's and Apple's blessing. If you wish, you can sync the videos to the SD card periodically, - but that\'s a bit of extra manual work. + but that's a bit of extra manual work. ### The Good 1. Better privacy - We don\'t even have to configure the ad-blocker to keep ads and + We don't even have to configure the ad-blocker to keep ads and trackers away! YouTube still has your IP address, so using a VPN is always a good @@ -210,10 +206,10 @@ Tradeoffs 2. No need to self-host - There\'s no host that needs maintenance. Everything runs locally. + There's no host that needs maintenance. Everything runs locally. As long as you keep youtube-dl itself up to date and sync your - \"seen\" file, there\'s little extra work to do. + "seen" file, there's little extra work to do. 3. Track your subscriptions with git @@ -226,26 +222,25 @@ Tradeoffs 1. Maximum playlist size is your disk size This is a good thing for getting a realistic view on your actual - \"watch later\" list. However I\'ve run out of disk space many + "watch later" list. However I've run out of disk space many times, and now I need to be more aware of how much is left. ### The Ugly We can only avoid all the bad parts of YouTube with youtube-dl as long as YouTube keeps the videos public and programmatically accessible. If -YouTube ever blocks that we\'d loose the ability to consume content this +YouTube ever blocks that we'd loose the ability to consume content this way, but also loose confidence on considering YouTube a healthy repository of videos on the internet. -Going beyond ------------- +## Going beyond -Since you\'re running everything locally, here are some possibilities to +Since you're running everything locally, here are some possibilities to be explored: ### A playlist that is too long for being downloaded all at once -You can wrap the `download_playlist` function (let\'s call the wrapper +You can wrap the `download_playlist` function (let's call the wrapper `inc_download`) and instead of passing it a fixed number to the `--playlist-end` parameter, you can store the `$n` in a folder (something like `$HOME/.yt-db/$PLAYLIST_ID`) and increment it by `$step` @@ -258,24 +253,21 @@ without filling your disk with gigabytes of content all at once. The `download_playlist` function could be aware of the specific machine that it is running on and apply specific policies depending on the -machine: always download everything; only download videos that aren\'t +machine: always download everything; only download videos that aren't present anywhere else; etc. -Conclusion ----------- +## Conclusion youtube-dl is a great tool to keep at hand. It covers a really large range of video websites and works robustly. -Feel free to copy and modify this code, and [send -me](mailto:eu@euandre.org) suggestions of improvements or related +Feel free to copy and modify this code, and [send me](mailto:eu@euandre.org) suggestions of improvements or related content. -*Edit* ------- +## *Edit* 2019/05/22: Fix spelling. [^1]: Considering how expensive it is and the many ways it could be better, but also how much it has improved over the last years, I say - it\'s reasonable. + it's reasonable. |