Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 committed Feb 4, 2024
2 parents 1ca5eab + 5bf153e commit 0e71b87
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 63 deletions.
93 changes: 86 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ docker run -d \

#### Paths and Environment Variables

| 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) |
| 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) |
| `/path/to/preroll/files` | Path to the root directory of all preroll files (for [Path Globbing](#path-globbing) feature) |

| Environment Variable | Description |
|----------------------|-------------------------------------------------------------------|
Expand Down Expand Up @@ -131,7 +132,8 @@ You can define as many schedules as you want, in the following categories (order
All schedule entries 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 an `always` entry, but place more weight/emphasis on the `date_range` entry.
you to combine, e.g. a `date_range` entry with an `always` entry, but place more weight/emphasis on the `date_range`
entry.

```yaml
date_range:
Expand All @@ -148,8 +150,10 @@ date_range:
#### Disable Always
Any schedule entry (except for the `always` section) can disable the inclusion of the `always` section by setting the
`disable_always` value to `true`. This can be useful if you want to make one specific, i.e. `date_range` entry for a holiday,
and you don't want to include the `always` section for this specific holiday, but you still want to include the `always` section
`disable_always` value to `true`. This can be useful if you want to make one specific, i.e. `date_range` entry for a
holiday,
and you don't want to include the `always` section for this specific holiday, but you still want to include the `always`
section
for other holidays.

```yaml
Expand Down Expand Up @@ -205,6 +209,81 @@ You should [adjust your cron schedule](#scheduling-script) to run the script mor

---

## Advanced Configuration

### Path Globbing

**NOTE**: This feature will only work if you are running the script/Docker container on the same machine as your Plex
server.

Instead of listing out each individual preroll file, you can use glob (wildcard) patterns to match multiple files in a
specific directory.
The application will search for all files on your local filesystem that match the pattern(s) and automatically translate
them to Plex-compatible remote paths.

#### Setup

Enable the feature under the advanced section of the config file, and specify the path to the root directory of your
preroll files, as well as the path to the same directory as seen by Plex.

```yaml
advanced:
path_globbing:
enabled: true
root_path: /path/to/preroll/directory/in/relation/to/application
plex_path: /path/to/same/directory/as/seen/by/plex
```

For example, if your prerolls on your file system are located at `/mnt/user/media/prerolls` and Plex sees them
at `/media/prerolls`, you would set the `root_path` to `/mnt/user/media/prerolls` and the `plex_path`
to `/media/prerolls`.

If you are using the Docker container, you can mount the preroll directory to the container at any location you would
prefer (recommended: `/files`) and set the `root_path` accordingly.

If you are using the Unraid version of this container, the "Files Path" path is mapped to `/files` by default; you
should set `root_path` to `/files` and `plex_path` to the same directory as seen by Plex.

#### Usage

In any schedule section, you can use the `path_globs` key to specify a list of glob patterns to match files.

```yaml
always:
enabled: true
paths:
- /remote/path/1.mp4
- /remote/path/2.mp4
- /remote/path/3.mp4
path_globs:
- "*.mp4"
```

The above example will match all `.mp4` files in the `root_path` directory and append them to the list of prerolls.

If you have organized your prerolls into subdirectories, you can specify specific subdirectories to match, or use `**`
to match all subdirectories.

```yaml
always:
enabled: true
paths:
- /remote/path/1.mp4
- /remote/path/2.mp4
- /remote/path/3.mp4
path_globs:
- "subdir1/*.mp4"
- "subdir2/*.mp4"
- "subdir3/**/*.mp4"
```

You can use both `paths` and `path_globs` in the same section, allowing you to mix and match specific files with glob
patterns.
Please note that `paths` entries must be fully-qualified **remote** paths (as seen by Plex), while `path_globs` entries
are relative to the **local** `root_path` directory.

---

## Scheduling Script

**NOTE:** Scheduling is handled automatically in the Docker version of this script via the `CRON_SCHEDULE` environment
Expand Down
68 changes: 41 additions & 27 deletions config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ plex:
always:
enabled: true
paths:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
- "remote/path/to/video1.mp4"
- "remote/path/to/video2.mp4"
- "remote/path/to/video3.mp4"
path_globs:
- "local/path/to/prerolls/*.mp4" # Optional, use globbing to match local paths
count: 10 # Optional, randomly select X many videos from the list rather than all of them
weight: 1 # Optional, how much to emphasize these pre-rolls over others (higher = more likely to play)

Expand All @@ -23,46 +25,50 @@ date_range:
start_date: 2020-01-01 # Jan 1st, 2020
end_date: 2020-01-02 # Jan 2nd, 2020
paths:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
- "remote/path/to/video1.mp4"
- "remote/path/to/video2.mp4"
- "remote/path/to/video3.mp4"
path_globs:
- "local/path/to/prerolls/*.mp4" # Optional, use globbing to match local paths
weight: 2 # Optional, add these paths to the list twice (make up greater percentage of prerolls - more likely to be selected)
disable_always: true # Optional, if present and true, disable the always prerolls when this schedule is active
- start_date: xxxx-07-04 # Every year on July 4th
end_date: xxxx-07-04 # Every year on July 4th
paths:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
- "remote/path/to/video1.mp4"
- "remote/path/to/video2.mp4"
- "remote/path/to/video3.mp4"
disable_always: false
- start_date: xxxx-xx-02 # Every year on the 2nd of every month
end_date: xxxx-xx-03 # Every year on the 3rd of every month
paths:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
- "remote/path/to/video1.mp4"
- "remote/path/to/video2.mp4"
- "remote/path/to/video3.mp4"
- 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
paths:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
- "remote/path/to/video1.mp4"
- "remote/path/to/video2.mp4"
- "remote/path/to/video3.mp4"

# Schedule prerolls by week of the year
weekly:
enabled: false
weeks:
- number: 1 # First week of the year
paths:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
- "remote/path/to/video1.mp4"
- "remote/path/to/video2.mp4"
- "remote/path/to/video3.mp4"
path_globs:
- "local/path/to/prerolls/*.mp4" # Optional, use globbing to match local paths
weight: 1 # Optional, how much to emphasize these pre-rolls over others (higher = more likely to play)
- number: 2 # Second week of the year
paths:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
- "remote/path/to/video1.mp4"
- "remote/path/to/video2.mp4"
- "remote/path/to/video3.mp4"
disable_always: true # If true, disable the always prerolls when this schedule is active

# Schedule prerolls by month of the year
Expand All @@ -71,13 +77,21 @@ monthly:
months:
- number: 1 # January
paths:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
- "remote/path/to/video1.mp4"
- "remote/path/to/video2.mp4"
- "remote/path/to/video3.mp4"
weight: 1 # Optional, how much to emphasize these pre-rolls over others (higher = more likely to play)
- number: 2 # February
paths:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
- "remote/path/to/video1.mp4"
- "remote/path/to/video2.mp4"
- "remote/path/to/video3.mp4"
path_globs:
- "local/path/to/prerolls/*.mp4" # Optional, use globbing to match local paths
disable_always: false # If true, disable the always prerolls when this schedule is active

advanced:
path_globbing:
enabled: true # If true, use globbing to match paths
root_path: /files # The root folder to use for globbing
plex_path: /path/to/prerolls/in/plex # The path to use for the Plex server
Loading

0 comments on commit 0e71b87

Please sign in to comment.