Skip to content

Commit

Permalink
fix redacted
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Feb 19, 2023
1 parent e8e0428 commit 664e8a5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.10
0.9.11
38 changes: 25 additions & 13 deletions plex_image_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def not_failed(exception):
base_dir = os.path.dirname(os.path.abspath(__file__))
config_dir = os.path.join(base_dir, "config")
pmmargs = PMMArgs("meisnate12/Plex-Image-Cleanup", os.path.dirname(os.path.abspath(__file__)), options, use_nightly=False)
secrets = [pmmargs["url"], pmmargs["token"], quote(str(pmmargs["url"])), requests.utils.urlparse(pmmargs["url"]).netloc]
logger = logging.PMMLogger(script_name, "plex_image_cleanup", os.path.join(config_dir, "logs"), discord_url=pmmargs["discord"], log_requests=pmmargs["trace"])
logger.secret([pmmargs["url"], pmmargs["token"], quote(str(pmmargs["url"])), requests.utils.urlparse(pmmargs["url"]).netloc])
requests.Session.send = util.update_send(requests.Session.send, pmmargs["timeout"])
plexapi.BASE_HEADERS["X-Plex-Client-Identifier"] = pmmargs.uuid

Expand All @@ -94,7 +94,12 @@ def run_plex_image_cleanup(attrs):
do_trash = attrs["empty-trash"] if "empty-trash" in attrs else pmmargs["empty-trash"]
do_bundles = attrs["clean-bundles"] if "clean-bundles" in attrs else pmmargs["clean-bundles"]
do_optimize = attrs["optimize-db"] if "optimize-db" in attrs else pmmargs["optimize-db"]
mode = attrs["mode"].lower() if "mode" in attrs else pmmargs["mode"].lower()
if "mode" in attrs and attrs["mode"]:
mode = str(attrs["mode"]).lower()
elif pmmargs["mode"]:
mode = str(pmmargs["mode"]).lower()
else:
mode = "report"
description = f"Running in {mode.capitalize()} Mode"
extras = []
if do_trash:
Expand All @@ -110,17 +115,18 @@ def run_plex_image_cleanup(attrs):
logger.info(description)
report = []
messages = []
kbi = None
try:
try:
logger.info("Script Started", log=False, discord=True)
except Failed as e:
logger.error(e)

# Check Mode
if mode not in modes:
raise Failed(f"Mode Error: {mode} Invalid. Options: \n\t{mode_descriptions}")
logger.info(f"{mode.capitalize()}: {modes[mode]['desc']}")

try:
logger.info("Script Started", log=False, discord=True)
except Failed as e:
logger.error(f"Discord URL Error: {e}")

# Check Plex Path
if not pmmargs["plex"]:
if not os.path.exists(os.path.join(base_dir, "plex")):
Expand Down Expand Up @@ -313,8 +319,8 @@ def plex_connect():
logger.info(f"Copying database from {os.path.join(databases_dir, plex_db_name)}", start="database")
util.copy_with_progress(os.path.join(databases_dir, plex_db_name), dbpath, description=f"Copying database file to: {dbpath}")
else:
logger.info("Downloading Database via the API. Plex will This will take some time... To see progress, log into\n"
"Plex and go to Settings | Manage | Console and filter on Database.\n"
logger.info("Downloading Database via the Plex API. First Plex will make a backup of your database.\n"
"To see progress, log into Plex and go to Settings | Manage | Console and filter on Database.\n"
"You can also look at the Plex Dashboard to see the progress of the Database backup.", start="database")
logger.info()

Expand Down Expand Up @@ -446,20 +452,26 @@ def plex_connect():
logger.debug(message)
logger.stacktrace()
logger.critical(e, discord=True)
except KeyboardInterrupt:
logger.separator(f"User Exiting {script_name}")
logger.remove_main_handler()
raise

logger.error_report()
logger.switch()
report.append([(f"{script_name} Finished", "")])
report.append([("Total Runtime", f"{logger.runtime()}")])
logger.report(f"{script_name} Summary", description=description, rows=report, discord=True)
logger.remove_main_handler()

if __name__ == "__main__":
try:
if pmmargs["schedule"]:
pmmargs["schedule"] = pmmargs["schedule"].lower().replace(" ", "")
valid_sc = []
schedules = pmmargs["schedule"].split(",")
print()
print("Scheduled Runs: ")
logger.info()
logger.info("Scheduled Runs: ")
for sc in schedules:
run_str = ""
parts = sc.split("|")
Expand Down Expand Up @@ -534,11 +546,11 @@ def plex_connect():
run_str += f" at {time_to_run}"
if options:
run_str += f" (Options: {'; '.join([f'{k}={v}' for k, v in options.items()])})"
print(run_str)
logger.info(run_str)
else:
raise Failed(f'Schedule Error: Invalid Schedule: {sc}\nEach Schedule must be in either the "time|frequency" or "time|frequency|options" format')

print()
logger.info()
while True:
schedule.run_pending()
next_run = schedule.next_run()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ numpy==1.24.2
opencv-python==4.7.0.68
pillow==9.4.0
PlexAPI==4.13.2
pmmutils==0.3.12
pmmutils==0.3.13
requests==2.28.2
retrying==1.3.4
tmdbapis==1.1.0
Expand Down

0 comments on commit 664e8a5

Please sign in to comment.