Skip to content

Commit

Permalink
add discord url to secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Feb 20, 2023
1 parent 664e8a5 commit 1d0a072
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.11
0.9.12
26 changes: 10 additions & 16 deletions plex_image_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def not_failed(exception):
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)
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])
logger.secret([pmmargs["url"], pmmargs["discord"], 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 Down Expand Up @@ -115,7 +115,6 @@ def run_plex_image_cleanup(attrs):
logger.info(description)
report = []
messages = []
kbi = None
try:
# Check Mode
if mode not in modes:
Expand Down Expand Up @@ -146,7 +145,6 @@ def run_plex_image_cleanup(attrs):
f' Should contain "Cache", "Metadata", and "Plug-in Support"\n'
f' Contents:\n {contents}')


# Delete PhotoTranscoder
if do_transcode:
logger.separator(f"Remove PhotoTranscoder Images\nDir: {transcoder_dir}")
Expand All @@ -164,8 +162,7 @@ def run_plex_image_cleanup(attrs):
file = os.path.join(transcoder_dir, f)
messages.append(f"REMOVE: {file}")
logger["size"] += os.path.getsize(file)
if mode != "report":
os.remove(file)
os.remove(file)
for message in messages:
logger.trace(message)

Expand All @@ -174,12 +171,8 @@ def run_plex_image_cleanup(attrs):
logger.info(f"Space Recovered: {space}")
logger.info(f"Runtime: {logger.runtime()}")
report.append([("Remove PhotoTranscoder Images", "")])
report.append([
("Space Recovered", space),
("Files Removed", len(transcode_images)),
("Scan Time", f"{logger.runtime('transcode_scan')}"),
("Remove Time", f"{logger.runtime('transcode')}")
])
report.append([("Space Recovered", space), ("Files Removed", len(transcode_images))])
report.append([("Scan Time", f"{logger.runtime('transcode_scan')}"), ("Remove Time", f"{logger.runtime('transcode')}")])

# Connection to Plex
server = None
Expand Down Expand Up @@ -273,9 +266,7 @@ def plex_connect():
pmmargs["local"] = True
logger.warning("No Plex URL and Plex Token Given assuming Local Run")
if pmmargs["local"]:
db_tmp01 = os.path.join(pmmargs["database"], f"{plex_db_name}-shm")
db_tmp02 = os.path.join(pmmargs["database"], f"{plex_db_name}-wal")
if os.path.exists(db_tmp01) or os.path.exists(db_tmp02):
if any([os.path.exists(os.path.join(databases_dir, f"{plex_db_name}-{t}")) for t in ["shm", "wal"]]):
temp_db_warning = "At least one of the SQLite temp files is next to the Plex DB; this indicates Plex is still running\n" \
"and copying the DB carries a small risk of data loss as the temp files may not have updated the\n" \
"main DB yet.\n" \
Expand Down Expand Up @@ -453,7 +444,7 @@ def plex_connect():
logger.stacktrace()
logger.critical(e, discord=True)
except KeyboardInterrupt:
logger.separator(f"User Exiting {script_name}")
logger.separator(f"User Canceled Run {script_name}")
logger.remove_main_handler()
raise

Expand All @@ -470,6 +461,7 @@ def plex_connect():
pmmargs["schedule"] = pmmargs["schedule"].lower().replace(" ", "")
valid_sc = []
schedules = pmmargs["schedule"].split(",")
logger.separator(f"{script_name} Continuous Scheduled")
logger.info()
logger.info("Scheduled Runs: ")
for sc in schedules:
Expand Down Expand Up @@ -546,10 +538,12 @@ 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()])})"
logger.info(run_str)
logger.info(f"* {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')

logger.info()
logger.separator()
logger.info()
while True:
schedule.run_pending()
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.13
pmmutils==0.3.14
requests==2.28.2
retrying==1.3.4
tmdbapis==1.1.0
Expand Down

0 comments on commit 1d0a072

Please sign in to comment.