From 8c6689796c24f557b6bea93affc8bb40e192150f Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Wed, 28 Jul 2021 15:32:29 -0700 Subject: [PATCH 1/4] Add option for summary prefix in hide_episode_spoilers.py --- utility/hide_episode_spoilers.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/utility/hide_episode_spoilers.py b/utility/hide_episode_spoilers.py index 79b3b1b..adc8531 100644 --- a/utility/hide_episode_spoilers.py +++ b/utility/hide_episode_spoilers.py @@ -19,6 +19,8 @@ # --rating_key {rating_key} --image spoilers.png # To blur the episode artwork (optional blur in pixels): # --rating_key {rating_key} --blur 25 +# To add a prefix to the summary: +# --rating_key --summary_prefix "** SPOILERS **" # * Watched (optional): # --rating_key {rating_key} --remove @@ -54,7 +56,7 @@ def get_blurred_image(rating_key, blur=25): 'img_format': 'png', 'fallback': 'art' } - + r = requests.get(TAUTULLI_URL.rstrip('/') + '/api/v2', params=params, stream=True) if r.status_code == 200: r.raw.decode_content = True @@ -66,12 +68,13 @@ if __name__ == "__main__": parser.add_argument('--rating_key', required=True, type=int) parser.add_argument('--image') parser.add_argument('--blur', type=int, default=25) + parser.add_argument('--summary_prefix') parser.add_argument('--remove', action='store_true') opts = parser.parse_args() plex = PlexServer(PLEX_URL, PLEX_TOKEN) item = plex.fetchItem(opts.rating_key) - + if item.type == 'show': episodes = item.episodes() show = item @@ -91,7 +94,7 @@ if __name__ == "__main__": episode_filepath = part.file episode_folder = os.path.dirname(episode_filepath) episode_filename = os.path.splitext(os.path.basename(episode_filepath))[0] - + if opts.remove: # Find image files with the same name as the episode for filename in os.listdir(episode_folder): @@ -99,12 +102,15 @@ if __name__ == "__main__": # Delete the episode artwork image file os.remove(os.path.join(episode_folder, filename)) - elif opts.image: + episode.edit(**{'summary.locked': 0}) + continue + + if opts.image: # File path to episode artwork using the same episode file name episode_artwork = os.path.splitext(episode_filepath)[0] + os.path.splitext(opts.image)[1] # Copy the image to the episode artwork shutil.copy2(opts.image, episode_artwork) - + elif opts.blur: # File path to episode artwork using the same episode file name episode_artwork = os.path.splitext(episode_filepath)[0] + '.png' @@ -115,5 +121,9 @@ if __name__ == "__main__": with open(episode_artwork, 'wb') as f: shutil.copyfileobj(blurred_artwork, f) + if opts.summary_prefix and not episode.summary.startswith(opts.summary_prefix): + # Use a zero-width space for blank lines + episode.edit(**{'summary.value': opts.summary_prefix + '\n\u200b\n' + episode.summary, 'summary.locked': 1}) + # Refresh metadata for the episode episode.refresh() From d076426bf78ff1f5e7e978522d8a4071176c5fb3 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Wed, 28 Jul 2021 18:25:00 -0700 Subject: [PATCH 2/4] Fix line formatting --- utility/hide_episode_spoilers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utility/hide_episode_spoilers.py b/utility/hide_episode_spoilers.py index adc8531..b2daaf2 100644 --- a/utility/hide_episode_spoilers.py +++ b/utility/hide_episode_spoilers.py @@ -102,6 +102,7 @@ if __name__ == "__main__": # Delete the episode artwork image file os.remove(os.path.join(episode_folder, filename)) + # Unlock the summary so it will get updated on refresh episode.edit(**{'summary.locked': 0}) continue @@ -122,8 +123,11 @@ if __name__ == "__main__": shutil.copyfileobj(blurred_artwork, f) if opts.summary_prefix and not episode.summary.startswith(opts.summary_prefix): - # Use a zero-width space for blank lines - episode.edit(**{'summary.value': opts.summary_prefix + '\n\u200b\n' + episode.summary, 'summary.locked': 1}) + # Use a zero-width space (\u200b) for blank lines + episode.edit(**{ + 'summary.value': opts.summary_prefix + '\n\u200b\n' + episode.summary, + 'summary.locked': 1 + }) # Refresh metadata for the episode episode.refresh() From 3204a0cd447ef89c429a811375ea741a719230c1 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Wed, 28 Jul 2021 18:25:54 -0700 Subject: [PATCH 3/4] Fix summary prefix example --- utility/hide_episode_spoilers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utility/hide_episode_spoilers.py b/utility/hide_episode_spoilers.py index b2daaf2..9fac037 100644 --- a/utility/hide_episode_spoilers.py +++ b/utility/hide_episode_spoilers.py @@ -20,7 +20,7 @@ # To blur the episode artwork (optional blur in pixels): # --rating_key {rating_key} --blur 25 # To add a prefix to the summary: -# --rating_key --summary_prefix "** SPOILERS **" +# --rating_key {rating_key} --summary_prefix "** SPOILERS **" # * Watched (optional): # --rating_key {rating_key} --remove From 42bd315c1ea52470969ec13d29df98be3316a609 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Thu, 29 Jul 2021 13:14:10 +0000 Subject: [PATCH 4/4] Make summay_prefix string optional --- utility/hide_episode_spoilers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utility/hide_episode_spoilers.py b/utility/hide_episode_spoilers.py index 9fac037..1f75850 100644 --- a/utility/hide_episode_spoilers.py +++ b/utility/hide_episode_spoilers.py @@ -19,7 +19,7 @@ # --rating_key {rating_key} --image spoilers.png # To blur the episode artwork (optional blur in pixels): # --rating_key {rating_key} --blur 25 -# To add a prefix to the summary: +# To add a prefix to the summary (optional string prefix): # --rating_key {rating_key} --summary_prefix "** SPOILERS **" # * Watched (optional): # --rating_key {rating_key} --remove @@ -68,7 +68,7 @@ if __name__ == "__main__": parser.add_argument('--rating_key', required=True, type=int) parser.add_argument('--image') parser.add_argument('--blur', type=int, default=25) - parser.add_argument('--summary_prefix') + parser.add_argument('--summary_prefix', nargs='?', const='** SPOILERS **') parser.add_argument('--remove', action='store_true') opts = parser.parse_args()