2023-12-08 01:57:30 +00:00
|
|
|
# Plex Preroll Scheduler
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
A script to automate management of Plex pre-rolls.
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
Define when you want different pre-rolls to play throughout the year. For example:
|
2021-01-01 18:51:22 +00:00
|
|
|
|
|
|
|
- Holiday pre-roll rotations
|
|
|
|
- Special occasions
|
2023-12-08 01:57:30 +00:00
|
|
|
- Seasonal rotations
|
2021-01-01 18:51:22 +00:00
|
|
|
- Breaking up the monotony
|
2021-01-01 20:09:54 +00:00
|
|
|
- Keeping your family on their toes!
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2021-01-01 20:09:54 +00:00
|
|
|
---
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
## Installation and Usage
|
2021-01-01 20:09:54 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
### Run Script Directly
|
2021-01-01 20:09:54 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
#### Requirements
|
2021-01-01 20:09:54 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
- Python 3.8+
|
2021-01-01 20:09:54 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
Clone the repo:
|
2021-01-01 18:51:22 +00:00
|
|
|
|
|
|
|
```sh
|
2023-12-08 01:57:30 +00:00
|
|
|
git clone https://github.com/nwithan8/plex-schedule-prerolls.git
|
2021-01-01 18:51:22 +00:00
|
|
|
```
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
Install Python requirements:
|
2021-01-01 18:51:22 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
pip install -r requirements.txt
|
|
|
|
```
|
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
Copy `config.yaml.example` to `config.yaml`, provide your `plex` details and [edit your schedule](#schedule-rules).
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
Run the script:
|
2021-01-01 18:51:22 +00:00
|
|
|
|
|
|
|
```sh
|
2023-12-09 00:50:12 +00:00
|
|
|
python run.py
|
2021-01-01 18:51:22 +00:00
|
|
|
```
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
#### Advanced Usage
|
2021-01-01 18:51:22 +00:00
|
|
|
|
|
|
|
```sh
|
2023-12-09 00:50:12 +00:00
|
|
|
$ python run.py -h
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
usage: run.py [-h] [-c CONFIG] [-l LOG] [-d]
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
Plex Prerolls - A tool to manage prerolls for Plex
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
options:
|
2021-01-01 18:51:22 +00:00
|
|
|
-h, --help show this help message and exit
|
2023-12-09 00:50:12 +00:00
|
|
|
-c CONFIG, --config CONFIG
|
|
|
|
Path to config file. Defaults to 'config.yaml'
|
|
|
|
-l LOG, --log LOG Log file directory. Defaults to 'logs/'
|
|
|
|
-d, --dry-run Dry run, no real changes made
|
2021-01-01 18:51:22 +00:00
|
|
|
```
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
##### Example
|
2021-01-01 18:51:22 +00:00
|
|
|
|
|
|
|
```sh
|
2023-12-09 00:50:12 +00:00
|
|
|
python run.py -c path/to/custom/config.yaml -l path/to/custom/log/directory/ # Trailing slash required
|
2021-01-01 18:51:22 +00:00
|
|
|
```
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
### Run as Docker Container
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
#### Requirements
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
- Docker
|
|
|
|
|
|
|
|
#### Docker Compose
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
Complete the provided `docker-compose.yml` file and run:
|
2021-01-01 18:51:22 +00:00
|
|
|
|
|
|
|
```sh
|
2023-12-08 01:57:30 +00:00
|
|
|
docker-compose up -d
|
2021-01-01 18:51:22 +00:00
|
|
|
```
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
#### Docker CLI
|
2021-01-01 18:51:22 +00:00
|
|
|
|
|
|
|
```sh
|
2023-12-08 01:57:30 +00:00
|
|
|
docker run -d \
|
|
|
|
--name=plex_prerolls \
|
|
|
|
-e PUID=1000 \
|
|
|
|
-e PGID=1000 \
|
|
|
|
-e TZ=Etc/UTC \
|
|
|
|
-e CRON_SCHEDULE="0 0 * * *" \
|
2023-12-09 00:50:12 +00:00
|
|
|
-v /path/to/config:/ \
|
2023-12-08 01:57:30 +00:00
|
|
|
-v /path/to/logs:/logs \
|
|
|
|
--restart unless-stopped \
|
|
|
|
nwithan8/plex_prerolls:latest
|
2021-01-01 18:51:22 +00:00
|
|
|
```
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
#### Paths and Environment Variables
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-09 08:05:13 +00:00
|
|
|
| Path | Description |
|
|
|
|
|-----------|-----------------------------------------------------------------------|
|
|
|
|
| `/config` | Path to config directory (`config.yaml` should be in this directory) |
|
|
|
|
| `/logs` | Path to log directory (`Plex Prerolls.log` will be in this directory) |
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
| Environment Variable | Description |
|
|
|
|
|----------------------|-------------------------------------------------------------------|
|
|
|
|
| `PUID` | UID of user to run as |
|
|
|
|
| `PGID` | GID of user to run as |
|
|
|
|
| `TZ` | Timezone to use for cron schedule |
|
|
|
|
| `CRON_SCHEDULE` | Cron schedule to run script (see <https://crontab.guru> for help) |
|
2021-01-21 02:53:50 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
## Schedule Rules
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
Any entry whose schedule falls within the current date/time at the time of execution will be added to the preroll.
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
You can define as many schedules as you want, in the following categories (order does not matter):
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
1. **always**: Items listed here will always be included (appended) to the preroll list
|
|
|
|
- If you have a large set of prerolls, you can provide all paths and use `random_count` to randomly select a smaller
|
|
|
|
subset of the list to use on each run.
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
2. **date_range**: Schedule based on a specific date/time range (including [wildcards](#date-range-section-scheduling))
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
3. **weekly**: Schedule based on a specific week of the year
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
4. **monthly**: Schedule based on a specific month of the year
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
### Advanced Scheduling
|
|
|
|
|
|
|
|
#### Date Range Section Scheduling
|
|
|
|
|
|
|
|
`date_range` entries can accept both dates (`yyyy-mm-dd`) and datetimes (`yyyy-mm-dd hh:mm:ss`, 24-hour time).
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
`date_range` entries can also accept wildcards for any of the date/time fields. This can be useful for scheduling
|
|
|
|
recurring events, such as annual events, "first-of-the-month" events, or even hourly events.
|
2023-12-08 01:57:30 +00:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
date_range:
|
|
|
|
enabled: true
|
|
|
|
ranges:
|
|
|
|
# Each entry requires start_date, end_date, path values
|
|
|
|
- start_date: 2020-01-01 # Jan 1st, 2020
|
|
|
|
end_date: 2020-01-02 # Jan 2nd, 2020
|
2023-12-09 08:05:13 +00:00
|
|
|
paths:
|
|
|
|
- /path/to/video.mp4
|
|
|
|
- /path/to/another/video.mp4
|
2023-12-08 07:57:02 +00:00
|
|
|
weight: 2 # Add these paths to the list twice (make up greater percentage of prerolls - more likely to be selected)
|
2023-12-08 01:57:30 +00:00
|
|
|
- start_date: xxxx-07-04 # Every year on July 4th
|
|
|
|
end_date: xxxx-07-04 # Every year on July 4th
|
2023-12-09 00:50:12 +00:00
|
|
|
paths:
|
2023-12-09 08:05:13 +00:00
|
|
|
- /path/to/video.mp4
|
|
|
|
- /path/to/another/video.mp4
|
2023-12-08 07:57:02 +00:00
|
|
|
weight: 1
|
2023-12-09 00:50:12 +00:00
|
|
|
- name: "My Schedule" # Optional name for logging purposes
|
|
|
|
start_date: xxxx-xx-02 # Every year on the 2nd of every month
|
2023-12-08 01:57:30 +00:00
|
|
|
end_date: xxxx-xx-03 # Every year on the 3rd of every month
|
2023-12-09 00:50:12 +00:00
|
|
|
paths:
|
2023-12-09 08:05:13 +00:00
|
|
|
- /path/to/video.mp4
|
|
|
|
- /path/to/another/video.mp4
|
2023-12-08 07:57:02 +00:00
|
|
|
weight: 1
|
2023-12-08 01:57:30 +00:00
|
|
|
- start_date: xxxx-xx-xx 08:00:00 # Every day at 8am
|
|
|
|
end_date: xxxx-xx-xx 09:30:00 # Every day at 9:30am
|
2023-12-09 00:50:12 +00:00
|
|
|
paths:
|
2023-12-09 08:05:13 +00:00
|
|
|
- /path/to/video.mp4
|
|
|
|
- /path/to/another/video.mp4
|
2023-12-08 07:57:02 +00:00
|
|
|
weight: 1
|
2021-01-21 02:53:50 +00:00
|
|
|
```
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
You should [adjust your cron schedule](#scheduling-script) to run the script more frequently if you use this feature.
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
`date_range` entries also accept an optional `weight` value that can be used to adjust the emphasis of this entry over
|
|
|
|
others by adding the listed paths multiple times. Since Plex selects a random preroll from the list of paths, having the
|
|
|
|
same path listed multiple times increases its chances of being selected over paths that only appear once. This allows
|
|
|
|
you to combine, e.g. a `date_range` entry with a `misc` entry, but place more weight/emphasis on the `date_range` entry.
|
|
|
|
|
|
|
|
`date_range` entries also accept an optional `name` value that can be used to identify the schedule in the logs.
|
2023-12-08 07:57:02 +00:00
|
|
|
|
2021-01-21 02:53:50 +00:00
|
|
|
---
|
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
## Scheduling Script
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
**NOTE:** Scheduling is handled automatically in the Docker version of this script via the `CRON_SCHEDULE` environment
|
|
|
|
variable.
|
2021-01-21 02:53:50 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
### Linux
|
|
|
|
|
|
|
|
Add to system scheduler:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
crontab -e
|
|
|
|
```
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
Place desired schedule (example below for every day at midnight)
|
|
|
|
|
|
|
|
```sh
|
2023-12-09 00:50:12 +00:00
|
|
|
0 0 * * * python /path/to/run.py >/dev/null 2>&1
|
2023-12-08 01:57:30 +00:00
|
|
|
```
|
|
|
|
|
2023-12-09 00:50:12 +00:00
|
|
|
You can also wrap the execution in a shell script (useful if running other scripts/commands, using venv encapsulation,
|
|
|
|
customizing arguments, etc.)
|
2023-12-08 01:57:30 +00:00
|
|
|
|
|
|
|
```sh
|
2023-12-09 00:50:12 +00:00
|
|
|
0 0 * * * /path/to/run_prerolls.sh >/dev/null 2>&1
|
2023-12-08 01:57:30 +00:00
|
|
|
```
|
2021-01-01 18:51:22 +00:00
|
|
|
|
2023-12-08 01:57:30 +00:00
|
|
|
Schedule as frequently as needed for your schedule (ex: hourly, daily, weekly, etc.)
|
2021-01-01 18:51:22 +00:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
## Shout out to places to get Pre-Roll
|
|
|
|
|
2021-01-21 02:53:50 +00:00
|
|
|
- <a href="https://prerolls.video" target="_blank"><https://prerolls.video></a>
|