mirror of
https://github.com/meisnate12/Plex-Meta-Manager
synced 2024-11-10 06:54:21 +00:00
#568 dont ignore ranges
This commit is contained in:
parent
98c7e633e2
commit
f942191251
2 changed files with 24 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
|||
import logging, os, re, time
|
||||
from datetime import datetime, timedelta
|
||||
from modules import anidb, anilist, flixpatrol, icheckmovies, imdb, letterboxd, mal, plex, radarr, sonarr, stevenlu, tautulli, tmdb, trakt, tvdb, util
|
||||
from modules.util import Failed, ImageData, NotScheduled
|
||||
from modules.util import Failed, ImageData, NotScheduled, NotScheduledRange
|
||||
from PIL import Image
|
||||
from plexapi.audio import Artist, Album, Track
|
||||
from plexapi.exceptions import BadRequest, NotFound
|
||||
|
@ -275,16 +275,23 @@ class CollectionBuilder:
|
|||
logger.debug(f"Value: {data[methods['delete_not_scheduled']]}")
|
||||
self.details["delete_not_scheduled"] = self._parse("delete_not_scheduled", self.data, datatype="bool", methods=methods, default=False)
|
||||
|
||||
if "schedule" in methods and not self.config.requested_collections and not self.config.ignore_schedules:
|
||||
if "schedule" in methods and not self.config.requested_collections:
|
||||
logger.debug("")
|
||||
logger.debug("Validating Method: schedule")
|
||||
if not self.data[methods["schedule"]]:
|
||||
raise Failed(f"{self.Type} Error: schedule attribute is blank")
|
||||
else:
|
||||
logger.debug(f"Value: {self.data[methods['schedule']]}")
|
||||
e = None
|
||||
not_running = False
|
||||
try:
|
||||
util.schedule_check("schedule", self.data[methods['schedule']], self.current_time, self.config.run_hour)
|
||||
except NotScheduledRange as e:
|
||||
not_running = True
|
||||
except NotScheduled as e:
|
||||
if not self.config.ignore_schedules:
|
||||
not_running = True
|
||||
if not_running:
|
||||
suffix = ""
|
||||
if self.details["delete_not_scheduled"]:
|
||||
try:
|
||||
|
|
|
@ -24,6 +24,9 @@ class Failed(Exception):
|
|||
class NotScheduled(Exception):
|
||||
pass
|
||||
|
||||
class NotScheduledRange(NotScheduled):
|
||||
pass
|
||||
|
||||
class ImageData:
|
||||
def __init__(self, attribute, location, prefix="", is_poster=True, is_url=True):
|
||||
self.attribute = attribute
|
||||
|
@ -375,12 +378,14 @@ def check_day(_m, _d):
|
|||
|
||||
def schedule_check(attribute, data, current_time, run_hour):
|
||||
skip_collection = True
|
||||
range_collection = False
|
||||
schedule_list = get_list(data)
|
||||
next_month = current_time.replace(day=28) + timedelta(days=4)
|
||||
last_day = next_month - timedelta(days=next_month.day)
|
||||
schedule_str = ""
|
||||
for schedule in schedule_list:
|
||||
run_time = str(schedule).lower()
|
||||
display = f"{attribute} attribute {schedule} invalid"
|
||||
if run_time.startswith(("day", "daily")):
|
||||
skip_collection = False
|
||||
elif run_time == "never":
|
||||
|
@ -400,10 +405,10 @@ def schedule_check(attribute, data, current_time, run_hour):
|
|||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
logger.error(f"Schedule Error: hourly {attribute} attribute {schedule} invalid must be an integer between 0 and 23")
|
||||
logger.error(f"Schedule Error: hourly {display} must be an integer between 0 and 23")
|
||||
elif run_time.startswith("week"):
|
||||
if param.lower() not in days_alias:
|
||||
logger.error(f"Schedule Error: weekly {attribute} attribute {schedule} invalid must be a day of the week i.e. weekly(Monday)")
|
||||
logger.error(f"Schedule Error: weekly {display} must be a day of the week i.e. weekly(Monday)")
|
||||
continue
|
||||
weekday = days_alias[param.lower()]
|
||||
schedule_str += f"\nScheduled weekly on {pretty_days[weekday]}"
|
||||
|
@ -419,7 +424,7 @@ def schedule_check(attribute, data, current_time, run_hour):
|
|||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
logger.error(f"Schedule Error: monthly {attribute} attribute {schedule} invalid must be an integer between 1 and 31")
|
||||
logger.error(f"Schedule Error: monthly {display} must be an integer between 1 and 31")
|
||||
elif run_time.startswith("year"):
|
||||
try:
|
||||
if "/" in param:
|
||||
|
@ -433,12 +438,11 @@ def schedule_check(attribute, data, current_time, run_hour):
|
|||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
logger.error(
|
||||
f"Schedule Error: yearly {attribute} attribute {schedule} invalid must be in the MM/DD format i.e. yearly(11/22)")
|
||||
logger.error(f"Schedule Error: yearly {display} must be in the MM/DD format i.e. yearly(11/22)")
|
||||
elif run_time.startswith("range"):
|
||||
match = re.match("^(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])-(1[0-2]|0?[1-9])/(3[01]|[12][0-9]|0?[1-9])$", param)
|
||||
if not match:
|
||||
logger.error(f"Schedule Error: range {attribute} attribute {schedule} invalid must be in the MM/DD-MM/DD format i.e. range(12/01-12/25)")
|
||||
logger.error(f"Schedule Error: range {display} must be in the MM/DD-MM/DD format i.e. range(12/01-12/25)")
|
||||
continue
|
||||
month_start, day_start = check_day(int(match.group(1)), int(match.group(2)))
|
||||
month_end, day_end = check_day(int(match.group(3)), int(match.group(4)))
|
||||
|
@ -446,12 +450,15 @@ def schedule_check(attribute, data, current_time, run_hour):
|
|||
check = datetime.strptime(f"{month_check}/{day_check}", "%m/%d")
|
||||
start = datetime.strptime(f"{month_start}/{day_start}", "%m/%d")
|
||||
end = datetime.strptime(f"{month_end}/{day_end}", "%m/%d")
|
||||
range_collection = True
|
||||
schedule_str += f"\nScheduled between {pretty_months[month_start]} {make_ordinal(day_start)} and {pretty_months[month_end]} {make_ordinal(day_end)}"
|
||||
if start <= check <= end if start < end else (check <= end or check >= start):
|
||||
skip_collection = False
|
||||
else:
|
||||
logger.error(f"Schedule Error: {attribute} attribute {schedule} invalid")
|
||||
logger.error(f"Schedule Error: {display}")
|
||||
if len(schedule_str) == 0:
|
||||
skip_collection = False
|
||||
if skip_collection:
|
||||
if skip_collection and range_collection:
|
||||
raise NotScheduledRange(schedule_str)
|
||||
elif skip_collection:
|
||||
raise NotScheduled(schedule_str)
|
||||
|
|
Loading…
Reference in a new issue