Skip to content

7. Automate Downloading New Content Using Your Configs

Jesse Bannon edited this page Aug 4, 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.

Enabling crontab

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

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

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. Since this path is not part of the already mounted volume, we need to mount another path. While we are at it, let's mount another directory to store the TV shows we download. In docker-compose, this looks like:

services:
  ytdl-sub:
    image: ghcr.io/jmbannon/ytdl-sub:latest
    container_name: ytdl-sub
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/Los_Angeles
    volumes:
      - </path/to/ytdl-sub/config>:/config
      - </path/to/ytdl-sub/crontab_files>:/etc/crontabs
      - </path/to/ytdl-sub/tv_shows>:/tv_shows
    restart: unless-stopped

Now that /path/to/ytdl-sub/crontab_files is mounted, we can create the abc crontab file there:

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

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

Ensure this file is executable and has permissions for abc:

# run as root
chmod +x /config/run_cron
chown abc:abc /config/run_cron

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

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.