Merge pull request #298 from JonnyWong16/feature/hide_episode_spoilers
Update hide_episode_spoilers to work with entire show or season
This commit is contained in:
commit
72fd5c4e51
@ -9,24 +9,25 @@
|
|||||||
# * Notify on watched (optional - to remove the artwork after being watched)
|
# * Notify on watched (optional - to remove the artwork after being watched)
|
||||||
# Tautulli script conditions:
|
# Tautulli script conditions:
|
||||||
# * Condition {1}:
|
# * Condition {1}:
|
||||||
# [ Media Type | is | episode ]
|
# [Media Type | is | show or season or episode]
|
||||||
# * Condition {2} (optional):
|
# * Condition {2} (optional):
|
||||||
# [ Library Name | is | DVR ]
|
# [ Library Name | is | DVR ]
|
||||||
# [ Show Namme | is | Game of Thrones ]
|
# [ Show Namme | is | Game of Thrones ]
|
||||||
# Tautulli script arguments:
|
# Tautulli script arguments:
|
||||||
# * Recently Added:
|
# * Recently Added:
|
||||||
# To use an image file (can be image in the same directory as this script, or full path to an image):
|
# To use an image file (can be image in the same directory as this script, or full path to an image):
|
||||||
# --rating_key {rating_key} --file {file} --image spoilers.png
|
# --rating_key {rating_key} --image spoilers.png
|
||||||
# To blur the episode artwork (optional blur in pixels):
|
# To blur the episode artwork (optional blur in pixels):
|
||||||
# --rating_key {rating_key} --file {file} --blur 25
|
# --rating_key {rating_key} --blur 25
|
||||||
# * Watched (optional):
|
# * Watched (optional):
|
||||||
# --rating_key {rating_key} --file {file} --remove
|
# --rating_key {rating_key} --remove
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
from plexapi.server import PlexServer
|
from plexapi.server import PlexServer
|
||||||
|
|
||||||
TAUTULLI_URL = ''
|
TAUTULLI_URL = ''
|
||||||
@ -63,49 +64,56 @@ def get_blurred_image(rating_key, blur=25):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--rating_key', required=True, type=int)
|
parser.add_argument('--rating_key', required=True, type=int)
|
||||||
parser.add_argument('--file', required=True)
|
|
||||||
parser.add_argument('--image')
|
parser.add_argument('--image')
|
||||||
parser.add_argument('--blur', type=int, default=25)
|
parser.add_argument('--blur', type=int, default=25)
|
||||||
parser.add_argument('--remove', action='store_true')
|
parser.add_argument('--remove', action='store_true')
|
||||||
opts = parser.parse_args()
|
opts = parser.parse_args()
|
||||||
|
|
||||||
if opts.remove:
|
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
|
||||||
# File path to episode artwork using the same episode file name without extension
|
item = plex.fetchItem(opts.rating_key)
|
||||||
episode_path = os.path.dirname(opts.file)
|
|
||||||
episode_filename = os.path.splitext(os.path.basename(opts.file))[0]
|
|
||||||
|
|
||||||
# Find image files with the same name as the episode
|
if item.type == 'show':
|
||||||
for filename in os.listdir(episode_path):
|
episodes = item.episodes()
|
||||||
if filename.startswith(episode_filename) and filename.endswith(('.jpg', '.png')):
|
show = item
|
||||||
# Delete the episode artwork image file
|
elif item.type == 'season':
|
||||||
os.remove(os.path.join(episode_path, filename))
|
episodes = item.episodes()
|
||||||
|
show = item.show()
|
||||||
|
elif item.type == 'episode':
|
||||||
|
episodes = [item]
|
||||||
|
show = item.show()
|
||||||
|
else:
|
||||||
|
print('Only media type show, season, or episode is supported: '
|
||||||
|
'{item.title} ({item.ratingKey}) is media type {item.type}.'.format(item=item))
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# Refresh metadata for the TV show
|
for episode in episodes:
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
|
for part in episode.iterParts():
|
||||||
plex.fetchItem(opts.rating_key).show().refresh()
|
episode_filepath = part.file
|
||||||
|
episode_folder = os.path.dirname(episode_filepath)
|
||||||
|
episode_filename = os.path.splitext(os.path.basename(episode_filepath))[0]
|
||||||
|
|
||||||
elif opts.image:
|
if opts.remove:
|
||||||
# File path to episode artwork using the same episode file name
|
# Find image files with the same name as the episode
|
||||||
episode_artwork = os.path.splitext(opts.file)[0] + os.path.splitext(opts.image)[1]
|
for filename in os.listdir(episode_folder):
|
||||||
|
if filename.startswith(episode_filename) and filename.endswith(('.jpg', '.png')):
|
||||||
|
# Delete the episode artwork image file
|
||||||
|
os.remove(os.path.join(episode_folder, filename))
|
||||||
|
|
||||||
# Copy the image to the episode artwork
|
elif opts.image:
|
||||||
shutil.copy2(opts.image, episode_artwork)
|
# 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)
|
||||||
|
|
||||||
# Refresh metadata for the TV show
|
elif opts.blur:
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
|
# File path to episode artwork using the same episode file name
|
||||||
plex.fetchItem(opts.rating_key).show().refresh()
|
episode_artwork = os.path.splitext(episode_filepath)[0] + '.png'
|
||||||
|
# Get the blurred artwork from Tautulli
|
||||||
|
blurred_artwork = get_blurred_image(episode.ratingKey, opts.blur)
|
||||||
|
if blurred_artwork:
|
||||||
|
# Copy the image to the episode artwork
|
||||||
|
with open(episode_artwork, 'wb') as f:
|
||||||
|
shutil.copyfileobj(blurred_artwork, f)
|
||||||
|
|
||||||
elif opts.blur:
|
# Refresh metadata for the episode
|
||||||
# File path to episode artwork using the same episode file name
|
episode.refresh()
|
||||||
episode_artwork = os.path.splitext(opts.file)[0] + '.png'
|
|
||||||
|
|
||||||
# Get the blurred artwork from Tautulli
|
|
||||||
blurred_artwork = get_blurred_image(opts.rating_key, opts.blur)
|
|
||||||
if blurred_artwork:
|
|
||||||
# Copy the image to the episode artwork
|
|
||||||
with open(episode_artwork, 'wb') as f:
|
|
||||||
shutil.copyfileobj(blurred_artwork, f)
|
|
||||||
|
|
||||||
# Refresh metadata for the TV show
|
|
||||||
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
|
|
||||||
plex.fetchItem(opts.rating_key).show().refresh()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user