diff --git a/subgen/subgen.py b/subgen/subgen.py index e1937b4..087d7d5 100644 --- a/subgen/subgen.py +++ b/subgen/subgen.py @@ -128,8 +128,13 @@ def receive_plex_webhook( logging.debug("Path of file: " + fullpath) gen_subtitles(path_mapping(fullpath), transcribe_or_translate, True) - else: - print("This doesn't appear to be a properly configured Plex webhook, please review the instructions again!") + try: + refresh_plex_metadata(item_id, plexserver, plextoken) + logging.info(f"Metadata for item {item_id} refreshed successfully.") + except Exception as e: + logging.error(f"Failed to refresh metadata for item {item_id}: {e}") + else: + print("This doesn't appear to be a properly configured Plex webhook, please review the instructions again!") return "" @@ -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"http://{server_ip}:32400/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.