March 29, 2020

My youtube-dl Setup

FYI (updated: 2021-05-28)
Some things have changed with the move to Apple Silicon. Updates below.

FYI (updated: 2021-10-08)
If you are experiencing issues with youtube-dl like slowdowns (it looks like the project is not currently actively being maintained) you might try this fork of the project yt-dlp

I also simplified my setup to all live within a single .sh script instead of using config files. Makes it a one stop shop (file) when you need to make updates.

Overview

The YouTube apps on the various platforms (iOS, Apple TV, web, and so on) are ok. I was looking for a better way to watch videos that I saved to view later (especially with pip on the iPad). There is a utility called youtube-dl that you may or may not have seen mentioned online. Here is a rundown of how I am now using it to manage all my YouTube videos I want to watch.

youtube-dl Configuration

The youtube-dl utility can be downloaded here: https://github.com/ytdl-org/youtube-dl
Check out the documentation on youtube-dl to get it all setup for your platform. Then it’s time to setup the configuration.

The yt-dlp utility can be downloaded here: https://github.com/yt-dlp/yt-dlp
Check out the documentation on yt-dlp to get it all setup for your platform.

Since my intial setup, I have moved away from a separate configuration file. No technical reason, just made thing a little simpler with everything baked into the shell script instead. But, if you would like to have your config in a separate file, here is an example of one.

I still recommend using a separate archive.txt file though so you don’t end up re-downloading your entire playlist every time!

youtube-dl.conf (I am not using a standalone config anymore. Just the .sh below)
Located here: /private/etc/youtube-dl.conf
Plus ~/archive.txt to keep an archive and only download videos that have not already been downloaded.
There is an ffmpeg line for Intel and one for Apple Silicon. Remove the one you don’t need.

# Save all videos to download folder
-o /Volumes/LaCie/Media/YouTube/%(title)s.%(ext)s

# Mark video as watched
--mark-watched

# download playlist
--yes-playlist

# Dowload new videos only
--download-archive ~/archive.txt

# Download best quality
-f 299+140/137+140/best

# ffmpeg location (Intel)
--ffmpeg-location /usr/local/Cellar/ffmpeg/4.4.1/bin/ffmpeg

# ffmpeg location (Apple Silicon)
--ffmpeg-location /opt/homebrew/Cellar/ffmpeg/4.4.1/bin/ffmpeg

Simplified .sh (mentioned in my 2021-10-08 update above)

If you go this route, you don’t need a separate config file.
ytdlp_playlist_download.sh

/opt/homebrew/Cellar/yt-dlp/2021.10.22/bin/yt-dlp\
 -o "/Volumes/LaCie/Media/YouTube/%(title)s.%(ext)s"\
 --mark-watched\
 --yes-playlist\
 -f "299+140/137+140/best"\
 --ffmpeg-location "/opt/homebrew/Cellar/ffmpeg/4.4.1/bin/ffmpeg"\
 --ignore-config\
 "https://www.youtube.com/playlist?list=PL-XXXXXXXXX"\
 --download-archive ~/archive.txt\
 --embed-thumbnail  

Be sure to make this .sh executable: chmod +x ytdlp_playlist_download.sh

Automating The Setup

Launch Agent (download_videos.plist)
A simple .plist that is placed in /Library/LaunchAgents set to run the .sh every 60 seconds. There is also a .log file in this example that I use to check when things aren’t working. Very handy!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>EnableGlobbing</key>
    <true/>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>Label</key>
    <string>ytdl</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/jason/Scripts/ytdlp_playlist_download.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/Users/jason/ytdl_error.log</string>
    <key>StandardOutPath</key>
    <string>/Users/jason/ytdl_st_out.log</string>
    <key>StartInterval</key>
    <integer>60</integer>
    <key>disabled</key>
    <false/>
</dict>
</plist>

This is all running on a 2018 Mac mini that is always on.
This is all running on a 2021 M1 iMac that is always on.

Plex Viewing

Now that the videos are being saved to a YouTube folder on the LaCie 6Big, this is where Plex comes in. This folder is monitored by Plex and updated with new videos so I can watch them right in the Plex app on iPhone, iPad, Mac, AppleTV, really anywhere you can get Plex running.

Managing the videos that are on the 6Big Storage.
Once I am done watching a video, Plex has an option to delete the video, which will delete the actual file on the server, so this keeps the folder from getting too out of control.

That’s it! Simply add a video to the ytdl” playlist on YouTube and this handles the rest!

Side Note - Alfred Workflow

Because youtube-dl is so useful and supports many different video platforms, I also have an Alfred workflow that I use for one-off downloads. Since this workflow is different from what I want the above system to accomplish with a YouTube playlist, I have set this up slightly different.

I don’t want the videos downloaded via this workflow to go to the same YouTube folder on the LacIe, so I decided to go with a one off config just for this workflow, it looks like this:

(Intel) youtube-dl -o "~/Downloads/%(title)s.%(ext)s" -f "299+140/137+140/best" --ffmpeg-location "/usr/local/Cellar/ffmpeg/4.3_2/bin/ffmpeg" --ignore-config "{query}"

(Apple Silicon) youtube-dl -o "~/Downloads/%(title)s.%(ext)s" -f "299+140/137+140/best" --ffmpeg-location "/opt/homebrew/Cellar/ffmpeg/4.4_1/bin/ffmpeg" --ignore-config "{query}"

This ignores my standard config file and sets the download location to Downloads’.

  1. Copy the video URL to clipboard
  2. Trigger Alfred
  3. Use the keyword yt followed by pasting the video URL
  4. Hit enter and your video begins downloading!

YouTube-dl Alfred Workflow

iOS Shortcut

I realized I didn’t have a way to complete the workflow if I got a link on my iPhone / iPad, so here is a shortcut to fix that.

HELP!!!

  • If your automated downloads stop and you are getting an error in the console related to keyerror: u'content_html' the issue may be that your YouTube playlist has gotten too large. This happened to me and my list was over 400 items! 😱 Probably a good idea to clean that list up from time to time. 👍

YouTube Automation YouTube-dl Mac Plex Alfred Workflow iOS Shortcuts Intel Apple Silicon yt-dlp


Previous post
Animated Color Change Blog Logo I have been wanting to swap the logo on my blog to my own logo (instead of the Animoji face I have been using) but I wanted it to be something more
Next post
Making A Board Game - Part 5 Things are progressing, albeit slowly, but they are! We have done some more play testing with beta components, and I think the game is coming along
Jason Burk | 1999-2021
blot.im! | 🧛‍♂️
📦 Blog Archives 📦

#FreeAds
top