-
Notifications
You must be signed in to change notification settings - Fork 80
7. Automate Downloading New Content Using Your Configs
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).
The first step is to ensure you have LinuxServer's Universal Cron mod enabled via the environment variable. For the GUI image, this is already included (no need to add it).
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.
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.
Follow the guide for your installed version of ytdl-sub, either GUI or Headless.
Create the script located at /config/ytdl-sub-configs/run_cron
by running these commands in the GUI terminal:
echo '#!/bin/bash' > /config/ytdl-sub-configs/run_cron
echo "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /config/ytdl-sub-configs/run_cron
echo "echo 'Cron started, running ytdl-sub...'" >> /config/ytdl-sub-configs/run_cron
echo "cd /config/ytdl-sub-configs" >> /config/ytdl-sub-configs/run_cron
echo "ytdl-sub --config=config.yaml sub subscriptions.yaml" >> /config/ytdl-sub-configs/run_cron
chmod +x /config/ytdl-sub-configs/run_cron
chown abc:abc /config/ytdl-sub-configs/run_cron
To create the cron definition, run the following command:
echo "# min hour day month weekday command" > /config/crontabs/abc
echo " 0 */6 * * * /config/ytdl-sub-configs/run_cron" >> /config/crontabs/abc
Log into the container as abc
using the command:
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 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /config/run_cron
echo "echo 'Cron started, running ytdl-sub...'" >> /config/run_cron
echo "cd /config" >> /config/run_cron
echo "ytdl-sub --config=config.yaml sub subscriptions.yaml" >> /config/run_cron
chmod +x /config/run_cron
chown abc:abc /config/run_cron
To create the cron definition, run the following command:
echo "# min hour day month weekday command" > /config/crontabs/abc
echo " 0 */6 * * * /config/run_cron" >> /config/crontabs/abc
The cron job is setup to "Run the run_cron
script every 6 hours". Feel free to change the cron schedule to your liking.
This will perform a download using config.yaml
and subscriptions.yaml
.
You can test that the script works by running:
/config/ytdl-sub-configs/run_cron
/config/run_cron
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 -->>