March 29, 2020

My youtube-dl Setup

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 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.

Here is what I am using for my current configuration file.

youtube-dl.conf
Located here: /private/etc/youtube-dl.conf
Plus ~/archive.txt to keep an archive and only download videos that have not already been downloaded.

# Save All Videos To YouTube Folder On Lacie 6Big
-o /Volumes/LaCie/Media/YouTube/%(title)s.%(ext)s

# Mark Video As Watched On YouTube
--mark-watched

# Download Playlist
--yes-playlist

# Dowload New Videos Only
--download-archive ~/archive.txt

# Download Best Quality mp4
-f mp4

Automating The Setup

Shell Script (ytdl_playlist_download.sh)
pointing to the YouTube playlist that I am using ytdl

#!/bin/bash
/usr/local/bin/youtube-dl "https://www.youtube.com/playlist?list=PL-XXXXXX"

Launch Agent (download_videos.plist)
A simple .plist that is placed in /Library/LaunchAgents set to run the .sh every 90 seconds. There is also a .log file in this example that I was using while testing everything.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>ytdl</string>
        <key>StartInterval</key>
        <integer>90</integer>
        <key>StandardErrorPath</key>
        <string>/Users/jason/Desktop/ytdl_error_logfile2.log</string>
        <key>EnableGlobbing</key>
        <true/>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <dict>
            <key>SuccessfulExit</key>
            <false/>
        </dict>
        <key>Program</key>
        <string>/Users/jason/Scripts/ytdl_playlist_download.sh</string>
    </dict>
</plist>

This is all running on a 2018 Mac mini 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:

youtube-dl -o "~/Downloads/%(title)s.%(ext)s" -f "mp4" --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.


YouTube Automation YouTube-dl Mac Plex Alfred Workflow iOS Shortcuts


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-2020
blot.im! | 🧛‍♂️
📦 Blog Archives 📦