Merge pull request #33 from Rikiar73574/113e0a2

Enhance post-webhook metadata handling
This commit is contained in:
McCloudS
2023-12-19 12:06:26 -07:00
committed by GitHub
3 changed files with 41 additions and 0 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/*

0
Dockerfile Normal file → Executable file
View File

View File

@@ -128,6 +128,11 @@ def receive_plex_webhook(
logging.debug("Path of file: " + fullpath)
gen_subtitles(path_mapping(fullpath), transcribe_or_translate, True)
try:
refresh_plex_metadata(plex_json['Metadata']['ratingKey'], plexserver, plextoken)
logging.info(f"Metadata for item {plex_json['Metadata']['ratingKey']} refreshed successfully.")
except Exception as e:
logging.error(f"Failed to refresh metadata for item {plex_json['Metadata']['ratingKey']}: {e}")
else:
print("This doesn't appear to be a properly configured Plex webhook, please review the instructions again!")
@@ -355,6 +360,37 @@ def get_plex_file_name(itemid: str, server_ip: str, plex_token: str) -> str:
else:
raise Exception(f"Error: {response.status_code}")
def refresh_plex_metadata(itemid: str, server_ip: str, plex_token: str) -> None:
"""
Refreshes the metadata of a Plex library item.
Args:
itemid: The ID of the item in the Plex library whose metadata needs to be refreshed.
server_ip: The IP address of the Plex server.
plex_token: The Plex token used for authentication.
Raises:
Exception: If the server does not respond with a successful status code.
"""
# Plex API endpoint to refresh metadata for a specific item
url = f"{server_ip}/library/metadata/{itemid}/refresh"
# Headers to include the Plex token for authentication
headers = {
"X-Plex-Token": plex_token,
}
# Sending the PUT request to refresh metadata
response = requests.put(url, headers=headers)
# Check if the request was successful
if response.status_code == 200:
print("Metadata refresh initiated successfully.")
else:
raise Exception(f"Error refreshing metadata: {response.status_code}")
def get_jellyfin_file_name(item_id: str, jellyfin_url: str, jellyfin_token: str) -> str:
"""Gets the full path to a file from the Jellyfin server.