Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance post-webhook metadata handling #33

Merged
merged 6 commits into from
Dec 19, 2023
Merged

Enhance post-webhook metadata handling #33

merged 6 commits into from
Dec 19, 2023

Conversation

Rikiar73574
Copy link
Contributor

@Rikiar73574 Rikiar73574 commented Dec 18, 2023

tried adding a simple function to update the metadata on titles once the subtitles are generated.

  1. Enhanced Post-subtitle Generation Workflow:
    After subtitles are generated (when the gen_subtitles function is called), there is now an additional step to refresh the metadata of the corresponding Plex library item. This ensures that any updates related to subtitles are immediately reflected in the Plex media library.

  2. Error Handling for Metadata Refresh:
    A try-except block has been added to catch and log any exceptions that occur during the metadata refresh process. This robust error handling is critical because it provides clear feedback in the event of a failure, ensuring that the user is informed about issues with refreshing metadata. The log message specifies the item_id affected and includes the error message for easier troubleshooting.

  3. New Function refresh_plex_metadata:
    A dedicated function has been added to encapsulate the logic for refreshing metadata. Its purpose is to send a PUT request to the Plex API for a specific item in order to trigger a metadata refresh. The function includes error handling to raise an exception if the refresh is not initiated successfully, which would be caught by the aforementioned error handling in the webhook processing block.

  4. Handling Misconfigured Webhooks:
    The message for misconfigured Plex webhooks has been shifted. This message now appears in the else block of the try-except statement, which informs the user if the webhook configuration isn't proper. While this might seem like a minor change, it ensures that the message is clearly associated with webhook configuration errors and not with other operations such as subtitle generation or metadata refreshing.

You can ignore this one if you feel like it changes too much of the original functionality but the other one about the dockerfile im pretty confident was an issue.
feel free to hit me up on discord "rikiar" if you want to discuss this i really like having this as a backup for my subtitles, so i'd gladly for a bit on it.

Added metadata refresh capability immediately after subtitle generation
when handling Plex webhooks. If subtitle generation is successful, the
Plex item's metadata is attempted to be refreshed to ensure that the
updates are reflected. The change includes robust error handling to log
failures in refreshing metadata and alerts the user if the webhook is
misconfigured. This enhancement improves the overall user experience by
ensuring the media library is up-to-date after any subtitle changes.
@McCloudS
Copy link
Owner

McCloudS commented Dec 18, 2023

Neat idea. I've never run into the problem though. I have "Update my library automatically" (See: https://support.plex.tv/articles/200289306-scanning-vs-refreshing-a-library/) enabled in Plex. Any directory file changes on my system seem to get updated near immediately.

item_id isn't defined anywhere. Did you mean to use plex_json['Metadata']['ratingKey']?. Additionally, the metadata refresh would likely finish before the subtitle generation was complete. Stable-ts/whisper appears to use its own threading system, so subgen.py isn't necessarily executing serially.

You would potentially have to drop it at https://github.com/McCloudS/subgen/blob/113e0a203c41c2603626a63447b278cfbc492442/subgen/subgen.py#L303C18-L303C18 but gen_subtitles doesn't track which webhook it came from.

@Rikiar73574
Copy link
Contributor Author

sorry about the item_id, my internet sucks atm so i didn´t really test this.
as per the automatic update i personally don't trust those for more complicated setups, so i prefer to force it just in case, had no idea about the separate threading, i'll look into it then should be easy enough to pass it where you mentioned.

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.
@Rikiar73574
Copy link
Contributor Author

it appears to work,
i can start a movie (with proconmediaplay=true) and without refreshing or closing the movie i can just wait a few minutes and get the subtitles automatically in the list, so i just have to check the subtitles menu every once in a while.
i'm not sure if this also happens with "Update my library automatically" where you don´t even have to close the movie to have new subs added.

and the separate threading you mentioned doesn't seem to be an issue

Transcribing with faster-whisper (medium)...
Saved: /movies/The Ballad of Buster Scruggs (2018)/The.Ballad.Of.Buster.Scruggs.2018.1080p.NF.WEB-DL.DDP5.1.X264-KamiKaze.subgen.medium.aa.srt
Transcription of The.Ballad.Of.Buster.Scruggs.2018.1080p.NF.WEB-DL.DDP5.1.X264-KamiKaze.mkv is completed, it took 6 minutes and 0 seconds to complete.
Metadata refresh initiated successfully.
INFO:root:Metadata for item 4243 refreshed successfully.

feel free to let me know if you don't like something about it.

@McCloudS McCloudS merged commit a5b3ecb into McCloudS:main Dec 19, 2023
@McCloudS
Copy link
Owner

McCloudS commented Dec 19, 2023

Looks good, thanks for the effort! I also modified it to add the refresh for Jellyfin. (Untested, as I don't have my Jellyfin running right now, but the end point is right per: https://api.jellyfin.org/openapi/jellyfin-openapi-stable.json)

@Rikiar73574 Rikiar73574 deleted the 113e0a2 branch December 21, 2023 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants