[Tutorial] Download Youtube (Scripted youtube-dl)

This tutorial will (mostly) walk you through how script youtube-dl to archive youtube channels, playlists, or even individual videos, and then scan them into Plex. The default naming system assumes saving playlists as the preferred content and will organize playlists each as a “show” for Plex. This guide assumes you understand how to install the prerequisite software, install an agent for plex, and how to create and edit files for your preferred OS.

PLEASE NOTE: It is important to create the files within the OS you intend to use to avoid ‘last line’ errors.


0. Prerequisites:


1. Create Files

Create these files in the same directory, each with the following contents listed in the next steps.

youtube-dl-archive.txt
youtube-dl-channels.txt
youtube-dl.conf

  • :penguin: Linux Only
    download_archive.sh

  • :bsod: Windows Only
    download_archive.bat


2. File Contents

Edit each file with the necessary info.

youtube-dl-archive.txt - This is a blank file initially for keeping track of past downloads. It will populate with completed downloads and skip them in the future.

youtube-dl-channels.txt - This is where you can configure what channels, playlists, or individual videos to download. This is an example template, feel free to add, comment out (#) or remove lines as necessary.

# JDM_WAAAT: Nas Killer 2.0
https://www.youtube.com/playlist?list=PLahxXMkkX6cBZbmQiPI0kIwMYJNTlHioN
# SPACE INVADER ONE: UNRAID BASICS
https://www.youtube.com/watch?v=HybwCOVDg9k&list=PL6MCtOroZNDCXhQQWrVjbPWO-45qV7SOF
# DBZ Abridged
https://www.youtube.com/playlist?list=PL6EC7B047181AD013

youtube-dl.conf - This is where the configuration is set for youtube-dl. PLEASE NOTE: Some optional settings are commented out. You may choose to uncomment as needed

# Ignore Errors
-i

# Save Location and Naming
# The default naming saves the videos in the script location. Change as needed.
-o "%(uploader)s/%(playlist)s (%(uploader)s)/%(playlist)s - S01E%(playlist_index)s - %(title)s [%(id)s].%(ext)s"

# Archive Settings
--download-archive youtube-dl-archive.txt
-a youtube-dl-channels.txt

# (Optional) Max Downloads Per Run - This Limits Amount of Downloads Per Run
# --max-downloads 30

# (Optional) Reversed Playlist - For "backwards" playlists. This affects ALL links in the channel list. 
# Instead of toggling this, a 2nd set of scripts for reversed playlists is recommended.
# --playlist-reverse

# Uniform Format
--prefer-ffmpeg
--merge-output-format mkv

# Get All Subs to SRT
--write-sub
--all-subs
--convert-subs srt

# Get metadata
--add-metadata
--write-description
--write-thumbnail

# Debug
-v

# (Optional) Force IPV4 - Use this to get around IPV6 API limits (HTTP Error 429: Too Many Requests)
#-4

3. Script and Usage


3a - :penguin: Linux Only

  • Create the file with the following contents.
    download_archive.sh
#!/bin/bash

# Config Location
youtube-dl --config-location youtube-dl.conf

# (Optional) Move Downloads. Using rsync instead of mv to avoid "Directory not empty" error
# sudo rsync -a /path/to/downloads/ /destination/path/ --remove-source-files
exit 0
  • Run this command in the directory to make it executable.
    chmod +x download_archive.sh

  • Run using ./download_archive.sh


3b - :bsod: Windows Only

  • Create the file with the following contents.
    download_archive.bat
youtube-dl --config-location youtube-dl.conf
  • Run using:
    Run download_archive.bat

And that’s it! Simply assign the YouTube Metdata agent to the Plex Library that contains these downloaded videos. Be sure to set it as a TV type library for best results.



This guide was cobbled together from the works of others, to whom we owe a special thanks:

Reddit user: Stephen304 https://www.reddit.com/user/Stephen304 original post (deleted):

Github User: dmn001

Discord Users Stupifier, Chazlarson, and others from The Cloudbox Community

6 Likes

Solid script compilation.

Working in HomeBrew on a Mac Mini without issue.

May want to default this to commented out / disabled.

Quick n Dirty Mac instructions.

Assumes Brew is installed

1  brew install youtube-dl         #install youtube_dl package
2  brew install ffmpeg             #install ffmpeg package
3  mkdir $install_dir              #create install directory
4  cd $install_dir                 #enter install directory
5  touch youtube-dl-archive.txt    #create blank history file
6  nano youtube-dl-channels.txt    #paste in watchlist of channels
7  nano youtube-dl.conf            #paste in youtube-dl config
8  nano download_archive.sh        #master script
9  chmod +x download_archive.sh    #make master script executable
10 ./download_archive.sh           #launch master script

TODO

  • echo to $PATH
  • make cron job for automatic updates
2 Likes

I felt this was better to leave default as you can see what does or does not process. It does not save the output, so it’s only visible during manual runs or while tailing the output.