diff --git a/utility/hide_episode_spoilers.py b/utility/hide_episode_spoilers.py index 0d800e1..254b6d4 100644 --- a/utility/hide_episode_spoilers.py +++ b/utility/hide_episode_spoilers.py @@ -23,6 +23,8 @@ # --rating_key {rating_key} --summary_prefix "** SPOILERS **" # To upload the episode artwork instead of creating a local asset (optional, for when the script cannot access the media folder): # --rating_key {rating_key} --blur 25 --upload +# To replace episode title with "Aired %B %d, %Y (May 13, 2025) (optional, for shows where the title is a spoiler e.g. Jeopardy!) +# --hideTitle # * Watched (optional): # To remove the local asset episode artwork: # --rating_key {rating_key} --remove @@ -36,6 +38,7 @@ import os import requests import shutil from plexapi.server import PlexServer +from datetime import datetime PLEX_URL = '' PLEX_TOKEN = '' @@ -45,7 +48,7 @@ PLEX_URL = os.getenv('PLEX_URL', PLEX_URL) PLEX_TOKEN = os.getenv('PLEX_TOKEN', PLEX_TOKEN) -def modify_episode_artwork(plex, rating_key, image=None, blur=None, summary_prefix=None, remove=False, upload=False): +def modify_episode_artwork(plex, rating_key, image=None, blur=None, summary_prefix=None, remove=False, upload=False, hideTitle=False): item = plex.fetchItem(rating_key) if item.type == 'show': @@ -76,8 +79,9 @@ def modify_episode_artwork(plex, rating_key, image=None, blur=None, summary_pref # Delete the episode artwork image file os.remove(os.path.join(episode_folder, filename)) - # Unlock the summary so it will get updated on refresh + # Unlock the summary & title so they will get updated on refresh episode.editSummary(episode.summary, locked=False) + episode.editTitle(episode.title, locked=False) continue if image: @@ -115,7 +119,9 @@ def modify_episode_artwork(plex, rating_key, image=None, blur=None, summary_pref if summary_prefix and not episode.summary.startswith(summary_prefix): # Use a zero-width space (\u200b) for blank lines episode.editSummary(summary_prefix + '\n\u200b\n' + episode.summary) - + if hideTitle: + episode_title = episode.originallyAvailableAt.strftime("%B %d, %Y") + episode.editTitle('Aired ' + episode_title) # Refresh metadata for the episode episode.refresh() @@ -128,6 +134,7 @@ if __name__ == "__main__": parser.add_argument('--summary_prefix', nargs='?', const='** SPOILERS **') parser.add_argument('--remove', action='store_true') parser.add_argument('--upload', action='store_true') + parser.add_argument('--hideTitle', action='store_true') opts = parser.parse_args() plex = PlexServer(PLEX_URL, PLEX_TOKEN)