Improve webhook error handling and URL building

Adjusted indentation in the webhook receiver to correctly fall back to a
warning message when receiving a misconfigured webhook. Also, updated
metadata refresh function to construct the request URL dynamically,
allowing for more robust handling of server addresses, including those
served over HTTPS. These changes ensure better user feedback and improve
compatibility with secure Plex server configurations.
This commit is contained in:
Rikiar
2023-12-19 11:55:54 +01:00
parent e514fc16be
commit 5c5fe8d114
2 changed files with 8 additions and 3 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
subgen/tmp27tjle0a
subgen/.locks/*
subgen/__pycache__/subgen.cpython-310.pyc
subgen/models--Systran--faster-whisper-medium/*

View File

@@ -133,8 +133,8 @@ def receive_plex_webhook(
logging.info(f"Metadata for item {plex_json['Metadata']['ratingKey']} refreshed successfully.") logging.info(f"Metadata for item {plex_json['Metadata']['ratingKey']} refreshed successfully.")
except Exception as e: except Exception as e:
logging.error(f"Failed to refresh metadata for item {plex_json['Metadata']['ratingKey']}: {e}") logging.error(f"Failed to refresh metadata for item {plex_json['Metadata']['ratingKey']}: {e}")
else: else:
print("This doesn't appear to be a properly configured Plex webhook, please review the instructions again!") print("This doesn't appear to be a properly configured Plex webhook, please review the instructions again!")
return "" return ""
@@ -374,7 +374,7 @@ def refresh_plex_metadata(itemid: str, server_ip: str, plex_token: str) -> None:
""" """
# Plex API endpoint to refresh metadata for a specific item # Plex API endpoint to refresh metadata for a specific item
url = f"http://{server_ip}:32400/library/metadata/{itemid}/refresh" url = f"{server_ip}/library/metadata/{itemid}/refresh"
# Headers to include the Plex token for authentication # Headers to include the Plex token for authentication
headers = { headers = {