Skip to content

Commit

Permalink
Merge pull request #33 from Rikiar73574/113e0a2
Browse files Browse the repository at this point in the history
Enhance post-webhook metadata handling
  • Loading branch information
McCloudS authored Dec 19, 2023
2 parents fb438d9 + 02c97f1 commit a5b3ecb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
subgen/tmp27tjle0a
subgen/.locks/*
subgen/__pycache__/subgen.cpython-310.pyc
subgen/models--Systran--faster-whisper-medium/*

Empty file modified Dockerfile
100644 → 100755
Empty file.
36 changes: 36 additions & 0 deletions subgen/subgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a5b3ecb

Please sign in to comment.