- Add disable_always option to any date_range, week or month entry

This commit is contained in:
nwithan8 2023-12-14 00:48:31 -07:00
parent 9cc867953d
commit a8d3cf69d4
5 changed files with 77 additions and 17 deletions

View File

@ -126,6 +126,44 @@ You can define as many schedules as you want, in the following categories (order
### Advanced Scheduling
#### Weight
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 a `misc` entry, but place more weight/emphasis on the `date_range` entry.
```yaml
date_range:
enabled: true
ranges:
- start_date: 2020-01-01 # Jan 1st, 2020
end_date: 2020-01-02 # Jan 2nd, 2020
paths:
- /path/to/video.mp4
- /path/to/another/video.mp4
weight: 2 # Add these paths to the list twice (make up greater percentage of prerolls - more likely to be selected)
```
#### 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
for other holidays.
```yaml
date_range:
enabled: true
ranges:
- start_date: 2020-01-01 # Jan 1st, 2020
end_date: 2020-01-02 # Jan 2nd, 2020
paths:
- /path/to/video.mp4
- /path/to/another/video.mp4
disable_always: true # Disable the inclusion of the `always` section when this entry is active
```
#### 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).
@ -143,35 +181,26 @@ date_range:
paths:
- /path/to/video.mp4
- /path/to/another/video.mp4
weight: 2 # Add these paths to the list twice (make up greater percentage of prerolls - more likely to be selected)
- start_date: xxxx-07-04 # Every year on July 4th
end_date: xxxx-07-04 # Every year on July 4th
paths:
- /path/to/video.mp4
- /path/to/another/video.mp4
weight: 1
- name: "My Schedule" # Optional name for logging purposes
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/video.mp4
- /path/to/another/video.mp4
weight: 1
- 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/video.mp4
- /path/to/another/video.mp4
weight: 1
```
You should [adjust your cron schedule](#scheduling-script) to run the script more frequently if you use this feature.
`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.
---

View File

@ -27,12 +27,14 @@ date_range:
- "path/to/video2.mp4"
- "path/to/video3.mp4"
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"
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:
@ -61,6 +63,7 @@ weekly:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "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
monthly:
@ -77,3 +80,4 @@ monthly:
- "path/to/video1.mp4"
- "path/to/video2.mp4"
- "path/to/video3.mp4"
disable_always: false # If true, disable the always prerolls when this schedule is active

View File

@ -36,6 +36,10 @@ class Entry(YAMLElement):
def weight(self) -> int:
return self._get_value(key="weight", default=1)
@property
def disable_always(self) -> bool:
return self._get_value(key="disable_always", default=False)
class NumericalEntry(Entry):
def __init__(self, data):

View File

@ -14,6 +14,7 @@ class ScheduleEntry(NamedTuple):
paths: List[str]
weight: int
name_prefix: str
disable_always: bool = False
@property
def should_be_used(self) -> bool:
@ -44,7 +45,7 @@ def schedule_entry_from_always(paths: List[str], count: int, weight: int) -> Sch
name_prefix="Always")
def schedule_entry_from_week_number(week_number: int, paths: List[str], weight: int) -> Union[ScheduleEntry, None]:
def schedule_entry_from_week_number(week_number: int, paths: List[str], weight: int, disable_always: bool = False) -> Union[ScheduleEntry, None]:
start_date = utils.start_of_week_number(week_number=week_number)
end_date = utils.end_of_week_number(week_number=week_number)
@ -53,10 +54,11 @@ def schedule_entry_from_week_number(week_number: int, paths: List[str], weight:
end_date=end_date,
paths=paths,
weight=weight,
disable_always=disable_always,
name_prefix=f"Week {week_number}")
def schedule_entry_from_month_number(month_number: int, paths: List[str], weight: int) -> Union[ScheduleEntry, None]:
def schedule_entry_from_month_number(month_number: int, paths: List[str], weight: int, disable_always: bool = False) -> Union[ScheduleEntry, None]:
start_date = utils.start_of_month(month_number=month_number)
end_date = utils.end_of_month(month_number=month_number)
@ -65,11 +67,12 @@ def schedule_entry_from_month_number(month_number: int, paths: List[str], weight
end_date=end_date,
paths=paths,
weight=weight,
disable_always=disable_always,
name_prefix=f"Month {month_number}")
def schedule_entry_from_date_range(start_date_string: str, end_date_string: str, paths: List[str], weight: int,
name: str = None) \
disable_always: bool = False, name: str = None) \
-> Union[ScheduleEntry, None]:
if not name:
name = "Date Range"
@ -89,4 +92,5 @@ def schedule_entry_from_date_range(start_date_string: str, end_date_string: str,
end_date=end_date,
paths=paths,
weight=weight,
disable_always=disable_always,
name_prefix=name)

View File

@ -1,11 +1,11 @@
from typing import List
import modules.logs as logging
from modules import models
from modules.config_parser import (
Config,
)
from modules.models import ScheduleEntry
import modules.logs as logging
class ScheduleManager:
@ -23,20 +23,23 @@ class ScheduleManager:
for week in self._config.weekly.weeks:
self.weekly_schedules.append(models.schedule_entry_from_week_number(week_number=week.number,
paths=week.paths,
weight=week.weight))
weight=week.weight,
disable_always=week.disable_always))
if self._config.monthly.enabled:
for month in self._config.monthly.months:
self.monthly_schedules.append(models.schedule_entry_from_month_number(month_number=month.number,
paths=month.paths,
weight=month.weight))
weight=month.weight,
disable_always=month.disable_always))
if self._config.date_ranges.enabled:
for date_range in self._config.date_ranges.ranges:
entry = models.schedule_entry_from_date_range(start_date_string=date_range.start_date,
end_date_string=date_range.end_date,
paths=date_range.paths,
weight=date_range.weight,
name=date_range.name)
name=date_range.name,
disable_always=date_range.disable_always)
if entry:
self.date_range_schedules.append(entry)
@ -92,6 +95,9 @@ class ScheduleManager:
@property
def valid_always_schedules(self) -> List[ScheduleEntry]:
if self.disable_always:
return []
return [schedule for schedule in self.always_schedules if schedule.should_be_used]
@property
@ -105,9 +111,22 @@ class ScheduleManager:
valid_schedules += f"- {schedule.name}\n"
return valid_schedules
@property
def all_schedules_except_always(self) -> List[ScheduleEntry]:
return self.weekly_schedules + self.monthly_schedules + self.date_range_schedules
@property
def disable_always(self) -> bool:
return any([schedule.disable_always for schedule in self.all_schedules_except_always])
@property
def all_schedules(self) -> List[ScheduleEntry]:
return self.always_schedules + self.weekly_schedules + self.monthly_schedules + self.date_range_schedules
schedules = self.all_schedules_except_always
if not self.disable_always:
schedules += self.always_schedules
return schedules
@property
def all_valid_schedules(self) -> List[ScheduleEntry]: