Skip to content

7. Automate Downloading New Content Using Your Configs

Jesse Bannon edited this page Jul 29, 2023 · 24 revisions

This part of the walkthrough is for Docker + Unraid users. For folks running ytdl-sub differently, you're on your own for automation :-) (for any Windows experts, would love to include how to automate Windows downloads via a .bat script or something in this tutorial - please reach out if you know how).

Mounting directories with docker-compose

The first step is to ensure you have LinuxServer's Universal Cron mod enabled via the environment variable.

services:
  ytdl-sub:
    image: ghcr.io/jmbannon/ytdl-sub:latest
    container_name: ytdl-sub
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=America/Los_Angeles
      - DOCKER_MODS=linuxserver/mods:universal-cron  # <-- Make sure you have this!
    volumes:
      # ensure directories have user permissions
      - </path/to/ytdl-sub/config>:/config
      - </path/to/ytdl-sub/tv_shows>:/tv_shows
    restart: unless-stopped

This will tell your container to install and enable cron on start.

Some Context

LinuxServer containers create 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.

Creating the Crontab File

Log into the container as root using:

docker exec -it ytdl-sub /bin/bash

and run the following command:

echo "  0     */6     *       *       *       /config/run_cron" >> /config/crontabs/abc

This will write to the crontab file located at /config/crontabs/abc. It is telling cron "Run /config/run_cron every 6 hours". Feel free to change the cron schedule to your liking.

Creating the Run Script

Log back into the container as abc using:

docker exec -u abc -it ytdl-sub /bin/bash

Create the script located at /config/run_cron by running these commands:

echo '#!/bin/bash' > /config/run_cron
echo "echo 'Cron started, running ytdl-sub...'" >> /config/run_cron
echo "ytdl-sub --config=/config/config.yaml sub /config/subscriptions.yaml" >> /config/run_cron
chmod +x /config/run_cron

This will perform a download using config.yaml and subscriptions.yaml located in the /config directory. You can test that the script works by running:

/config/run_cron

Ensure your output directory points to your Docker mount

Assuming you mounted the /tv_shows directory, make sure ytdl-sub is writing to that output directory.

You're done! You are now downloading your subscriptions every six hours. Cron does not need to be updated if you update your container with a new image - it's setup-once-and-forget!


<<-- Part VI: Modifying Your Config For Your Media Player -- Previous -- | -- Next -- Part VIII: Using Prebuilt Presets and our Example Presets -->>