Skip to content

7. Automate Downloading New Content Using Your Configs

Jesse Bannon edited this page Sep 8, 2022 · 24 revisions

Docker is the recommended way to use ytdl-sub because it is easy to set up a cron job to automatically download new files via cron job. Setting this up is quite easy since we use the LinuxServer base image.

Mounting directories with docker-compose

The first step is to mount a few additional directories.

services:
  ytdl-sub:
    image: ghcr.io/jmbannon/ytdl-sub:latest
    container_name: ytdl-sub
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/Los_Angeles
    volumes:
      # ensure directories have user permissions
      - </path/to/ytdl-sub/config>:/config
      - </path/to/ytdl-sub/tv_shows>:/tv_shows
      # ensure directories have root permissions
      - </path/to/ytdl-sub/crontab_files>:/etc/crontabs
      - </path/to/ytdl-sub/custom-services.d>:/custom-services.d
      - </path/to/ytdl-sub/custom-cont-init>:/custom-cont-init.d
    restart: unless-stopped

Ensure the respective directories have user or root permissions.

Enabling crontab

Let's log into the docker container console as root to configure this using

docker exec -it ytdl-sub /bin/bash

Crontab is a utility for running cron jobs. To enable it in the docker image, add the following file /custom-services.d/cron:

#!/usr/bin/with-contenv bash
/usr/sbin/crond -f -S -l 0 -c /etc/crontabs

And set the following permissions:

chown root:root /custom-services.d/cron
chmod 644 /custom-services.d/cron

Creating the Crontab File

LinuxServer creates the user abc in the docker container and assigns it the respective PUID and PGID permissions to it. We want the cron job to run as this user to ensure downloaded files get these permissions instead of root permissions.

To do this, we need to create the file /etc/crontabs/abc.

# min hour    day     month   weekday command
0     */2      *       *       *      /config/run_cron

and set the following permissions:

chown root:root /etc/crontabs/abc
chmod 600 /etc/crontabs/abc

Creating the Run Script

This will run the run_cron script every 2 hours at the 0th minute. The last step is to create this bash script in /config/run_cron.

#!/bin/bash
echo "Cron started, running ytdl-sub..."
ytdl-sub --config=/config/first_config/config.yaml sub /config/first_config/subscriptions.yaml

and set the following permissions:

chown abc:abc /config/run_cron
chmod 755 /config/run_cron

This will use our config and subscriptions we created in this walk-through.

Updating the Config to the Mounted TV Show Directory

The final step is to point our config's output_options.output_directory to our new mounted TV shows folder /tv_shows:

presets:
  yt_video:
    output_options:
      output_directory: "/tv_shows/{tv_show_name_sanitized}"

You're done! You are now downloading your subscriptions every two hours. New YouTube channel uploads, videos added to a playlist, or SoundCloud artist uploads can now be downloaded automatically.


<<-- Part VI: Modifying Your Config For Your Media Player -- Previous --