|
1 | | -Automating Downloads |
2 | | -==================== |
| 1 | +Automating |
| 2 | +========== |
3 | 3 |
|
4 | | -:ref:`Guide for Docker and Unraid Containers <guides/getting_started/automating_downloads:docker and unraid>` |
| 4 | +Automate downloading your subscriptions by running the :ref:`'sub' sub-command |
| 5 | +<usage:subscriptions options>` periodically. There are various tools that can run |
| 6 | +commands on a schedule you may use any of them that work with your installation |
| 7 | +method. Most users use `cron`_ in `Docker containers <docker and unraid_>`_. |
5 | 8 |
|
6 | | -:ref:`Guide for Linux <guides/getting_started/automating_downloads:linux>` |
7 | | - |
8 | | -:ref:`Guide for Windows <guides/getting_started/automating_downloads:windows>` |
9 | | - |
10 | | -.. _cron scheduling syntax: https://crontab.guru/#0_*/6_*_*_* |
11 | | - |
12 | | - |
13 | | -.. _docker-unraid-setup: |
14 | 9 |
|
15 | 10 | Docker and Unraid |
16 | 11 | ----------------- |
17 | 12 |
|
18 | | -Cron is preconfigured in every ytdl-sub docker container. Enable by adding the following |
19 | | -ENV variables to your docker setup. |
| 13 | +:doc:`The 'ytdl-sub' Docker container images <../install/docker>` provide optional cron |
| 14 | +support. Enable cron support by setting `a cron schedule`_ in the ``CRON_SCHEDULE`` |
| 15 | +environment variable: |
20 | 16 |
|
21 | 17 | .. code-block:: yaml |
| 18 | + :caption: ./compose.yaml |
| 19 | + :emphasize-lines: 4 |
22 | 20 |
|
23 | 21 | services: |
24 | 22 | ytdl-sub: |
25 | 23 | environment: |
26 | | - - CRON_SCHEDULE="0 */6 * * *" |
27 | | - - CRON_RUN_ON_START=false |
| 24 | + CRON_SCHEDULE: "0 */6 * * *" |
| 25 | + # WARNING: See "Getting Started" -> "Automating" docs regarding throttles/bans: |
| 26 | + # CRON_RUN_ON_START: false |
| 27 | +
|
| 28 | +Then recreate the container to apply the change and start it to generate the default |
| 29 | +``/config/ytdl-sub-configs/cron`` script. Read the comments in that script and edit as |
| 30 | +appropriate. |
| 31 | + |
| 32 | +The container cron wrapper script will write output from the cron job to |
| 33 | +``/config/ytdl-sub-configs/.cron.log``. The default image ``ENTRYPOINT`` will ``$ tail |
| 34 | +...`` that file so you can monitor the cron job in the container's output and thus also |
| 35 | +in the Docker logs. |
28 | 36 |
|
| 37 | +You may also set the ``CRON_RUN_ON_START`` environment variable to ``true`` to have the |
| 38 | +image run your cron script whenever the container starts in addition to the cron |
| 39 | +schedule. |
29 | 40 |
|
30 | | -- ``CRON_SCHEDULE`` follows the standard `cron scheduling syntax`_. The above value will |
31 | | - run the script once every 6 hours. |
32 | | -- ``CRON_RUN_ON_START`` toggles whether to run your cron script on container start in |
33 | | - addition to the cron schedule. |
| 41 | +.. warning:: |
34 | 42 |
|
35 | | -The cron script will reside in the main directory with the file name ``cron``. Cron |
36 | | -logs should show when viewing the Docker logs. |
| 43 | + Using ``CRON_RUN_ON_START`` may cause your cron script to run too often and may |
| 44 | + trigger throttles and bans. When enabled, your cron script will run *whenever* the |
| 45 | + container starts including when the host reboots, when ``# dockerd`` restarts such as |
| 46 | + when upgrading Docker itself, when a new image is pulled, when something applies |
| 47 | + Compose changes, etc.. This may result in running ``ytdl-sub`` right before or after |
| 48 | + the next cron scheduled run. |
37 | 49 |
|
38 | 50 |
|
39 | 51 | .. _linux-setup: |
40 | 52 |
|
41 | | -Linux |
42 | | ------ |
43 | | -Must configure crontab manually, like so: |
| 53 | +Linux, Mac OS X, BSD, or other UNIX's |
| 54 | +------------------------------------- |
| 55 | + |
| 56 | +For installations on systems already running ``# crond``, you can also use cron to run |
| 57 | +``ytdl-sub`` periodically. Write a script to run ``ytdl-sub`` in the cron job. Be sure |
| 58 | +the script changes to the same directory as your configuration and uses the full path to |
| 59 | +``ytdl-sub``: |
44 | 60 |
|
45 | 61 | .. code-block:: shell |
| 62 | + :caption: ~/.local/bin/ytdl-sub-cron |
| 63 | + :emphasize-lines: 2,3 |
| 64 | +
|
| 65 | + #!/bin/bash |
| 66 | + cd "~/.config/ytdl-sub/" |
| 67 | + ~/.local/bin/ytdl-sub --dry-run sub -o '--ytdl_options.max_downloads 3' |& |
| 68 | + tee -a "~/.local/state/ytdl-sub/.cron.log" |
| 69 | +
|
| 70 | +Then tell ``# crond`` when to run the script: |
46 | 71 |
|
47 | | - crontab -e |
48 | | - 0 */6 * * * /config/run_cron |
| 72 | +.. code-block:: console |
| 73 | +
|
| 74 | + echo "0 */6 * * * ${HOME}/.local/bin/ytdl-sub-cron" | crontab "-" |
| 75 | +
|
| 76 | +Remove the ``--dry-run`` and ``-o ...`` CLI options from your cron script when you've |
| 77 | +tested your configuration and you're ready to download entries unattended. |
49 | 78 |
|
50 | 79 |
|
51 | 80 | .. _windows-setup: |
52 | 81 |
|
53 | 82 | Windows |
54 | 83 | ------- |
55 | 84 |
|
56 | | -To be tested (please contact code owner or join the discord server if you can test this |
57 | | -out for us) |
| 85 | +For most Windows users, the best way to run commands periodically is `the Task |
| 86 | +Scheduler`_: |
| 87 | + |
| 88 | +.. attention:: |
58 | 89 |
|
59 | | -.. code-block:: powershell |
| 90 | + These instructions are untested. Use at your own risk. If you use them, whether they |
| 91 | + work or not, please let us know how it went in `a support post in Discord`_ or `a new |
| 92 | + GitHub issue`_. |
60 | 93 |
|
61 | | - ytdl-sub.exe --config \path\to\config\config.yaml sub \path\to\config\subscriptions.yaml |
| 94 | +#. Open the Task Scheduler app. |
| 95 | + |
| 96 | +#. Click ``Create Basic Task`` at the top of the right sidebar. |
| 97 | + |
| 98 | +#. Set all the fields as appropriate until you get to the ``Action``... |
| 99 | + |
| 100 | +#. For the ``Action``, select ``Start a program``... |
| 101 | + |
| 102 | +#. Click ``Browse...`` to the installed ``ytdl-sub.exe`` executable... |
| 103 | + |
| 104 | +#. Add CLI arguments to ``Add arguments (optional):``, for example ``--dry-run sub -o |
| 105 | + '--ytdl_options.max_downloads 3'``... |
| 106 | + |
| 107 | +#. Set ``Start in (optional):`` to the directory containing your configuration. |
| 108 | + |
| 109 | +#. Finish the rest of the ``Create Basic Task`` wizard. |
62 | 110 |
|
63 | 111 |
|
64 | 112 | Next Steps |
65 | 113 | ---------- |
66 | 114 |
|
67 | | -Once you have a significant quantity of subscriptions or have use cases not served using |
68 | | -:doc:`YAML keys and the special characters <./subscriptions>`, it's time to start |
69 | | -:doc:`defining your own custom presets <./first_config>`. |
| 115 | +At this point, ``ytdl-sub`` should run periodically and keep your subscriptions current |
| 116 | +in your media library without your intervention. As your :doc:`subscriptions file |
| 117 | +<./subscriptions>` grows or you discover new use cases, it becomes worth while to |
| 118 | +simplify things by :doc:`defining your own custom presets <./first_config>`. |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +.. _`cron`: |
| 123 | + https://en.wikipedia.org/wiki/Cron |
| 124 | +.. _`a cron schedule`: |
| 125 | + https://crontab.cronhub.io/ |
| 126 | + |
| 127 | +.. _`the Task Scheduler`: |
| 128 | + https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page |
| 129 | +.. _`a support post in Discord`: |
| 130 | + https://discord.com/channels/994270357957648404/1084886228266127460 |
| 131 | +.. _`a new GitHub issue`: |
| 132 | + https://github.com/jmbannon/ytdl-sub/issues/new |
0 commit comments