About

Even though not a PVR, the command line utilities yt-dlp and ytdl-sub can be used to automate the process of downloading videos from YouTube, renaming them sequentially and then placing them somewhere to be picked up by jellyfin or Plex Media Server.

Requirements

  • yt-dlp,
  • ytdl-sub

Configuration

ytdl-sub uses YAML configuration files to define rules for downloading YouTube content. In its simplest form, two files are used config.yaml and subscriptions.yaml where config.yaml defines some general settings and subscriptions.yaml can be used to download YouTube channel subscriptions.

The setup described on this page uses one script per YouTube show such that it is recommended to keep these files contained within the same directory structure. For example, the filesystem structure that we use is the following:

+ /opt/ytdl-sub/TVSHOW
|          +
|          |
|          +---+ config.yaml
|          |
|          +---+ subscriptions.yaml
|          |
|          +---+ downloads
|
|
+ /etc/cron.daily
        +
        |
        +---+ ytdl-TVSHOW

where:

  • TVSHOW is the name of the TV show to be downloaded

config.yaml

configuration:
  working_directory: '/opt/ytdl-sub/TVSHOW/downloads'
  persist_logs:
    logs_directory: '/opt/ytdl-sub/TVSHOW/logs/'

presets:
  tv_show:
    ytdl_options:
      break_on_existing: True
      extractor_args:
        youtube:
          lang:
            - "en"

    preset:
      - "kodi_tv_show_by_date"
      - "jellyfin_tv_show_by_date"
      - "plex_tv_show_by_date"
      - "season_by_year__episode_by_month_day"

subscriptions.yaml

TVSHOW:
  preset:
    - "tv_show"

  overrides:
    tv_show_name: "TVSHOW"
    tv_show_directory: "/mnt/data/YouTube/"
    url: "https://www.youtube.com/channel/UXVQPTd6lNuq3POclliYXXze"

where:

  • TVSHOW is the name of the TV show,
  • https://www.youtube.com/channel/UXVQPTd6lNuq3POclliYXXze is the link to the YouTube channel

The result of this file will be that the channel videos will be downloaded to the directory /mnt/data/YouTube.

Setting up Jellyfin/Plex Media Server

Now either Jellyfin or Plex Media Server can be configured and a new collection added for the directory /mnt/data/YouTube. Both packages already use inotify to monitor files such that it is not really necessary to complicate the script to additionally notify Jellyfin or Plex.

Updating

In order to update, create the file at /etc/cron.daily/ytdl-TVSHOW with the following contents:

#!/bin/sh
YTDL_SHOW_DIRECTORY="$TVSHOW"
 
LOCK_FILE='/var/lock/ytdl-starea-natiei'
if mkdir $LOCK_FILE 2>&1 >/dev/null; then
    trap '{ rm -rf $LOCK_FILE; }' KILL QUIT TERM EXIT INT HUP
else
    exit 0
fi
 
cd "/opt/ytdl-sub/$YTDL_SHOW_DIRECTORY/"
/usr/local/bin/ytdl-sub -l verbose \
    --config "/opt/ytdl-sub/$YTDL_SHOW_DIRECTORY/config.yaml" sub "/opt/ytdl-sub/$YTDL_SHOW_DIRECTORY/subscriptions.yaml" | /usr/bin/logger

and replace:

  • $TVSHOW with the name of the TV show

Using cron, the script will now run daily and pull any additional videos that might have appeared in the meanwhile.

In order to run the script right now, tmux can be used to create a detached terminal session that will run the script manually /etc/cron.daily/ytdl-TVSHOW (where TVSHOW is the name of the TV show).

Scaling

Scaling is now fairly easy with one single example in place. One would have to just duplicate the folder /opt/ytdl-sub/TVSHOW for a different show, as well as create an additional script in /etc/cron.daily that references the files in /opt/ytdl-sub/TVSHOW.

Notes

At the time of writing all GUI solutions are problematic, especially the ones meant to run under docker and the main reason is due to the yt-dlp utility that finds itself in a constant race to keep up with the YouTube API such that many of the GUI solutions have an outdated yt-dlp that cannot be updated. yt-dlp and ytdl-sub means a little more work but ultimately, they are the best options, and especially due to being able to update both utilities at will. An alternative is to not use ytdl-sub but rather yt-dlp directly in order to download YouTube content.


linux/downloading_youtube_channels.txt ยท Last modified: 2024/06/09 03:28 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.