Skip to content

Commit

Permalink
Add: Option for Adding all Posters and Backdrops
Browse files Browse the repository at this point in the history
also, account for undefined art_url variable and plex agent settings name change to (legacy)
  • Loading branch information
natyusha committed Aug 28, 2024
1 parent 56ec7e5 commit d8e1485
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
28 changes: 19 additions & 9 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ShokoRelayAgent:
def Search(self, results, media, lang, manual):
# Search for the series using the name from the scanner
name = media.show
prelimresults = HttpReq('api/v3/Series/Search?query=%s&fuzzy=false&limit=10' % (urllib.quote_plus(name.encode('utf8')))) # http://127.0.0.1:8111/api/v3/Series/Search?query=Clannad&fuzzy=false&limit=10
prelimresults = HttpReq('api/v3/Series/Search?query=%s&fuzzy=false&limit=10' % (urllib.quote_plus(name.encode('utf8')))) # http://127.0.0.1:8111/api/v3/Series/Search?query=Kowarekake%20no%20Orgel&fuzzy=false&limit=10
for idx, series_data in enumerate(prelimresults):
series_id = series_data['IDs']['ID'] # Get series series id from series data
airdate = try_get(HttpReq('api/v3/Series/%s/AniDB' % series_id), 'AirDate', None) # Get airdate from series id
Expand All @@ -59,7 +59,7 @@ def Update(self, metadata, media, lang, force):

# Get series data
Log('==================[Shoko Relay for Series ID: %s]==================' % aid.zfill(6))
series_data = HttpReq('api/v3/Series/%s?includeDataFrom=AniDB,TMDB' % aid) # http://127.0.0.1:8111/api/v3/Series/24?includeDataFrom=AniDB
series_data = HttpReq('api/v3/Series/%s?includeDataFrom=AniDB,TMDB' % aid) # http://127.0.0.1:8111/api/v3/Series/24?includeDataFrom=AniDB,TMDB

# Make a dict of language -> title for all series titles in the AniDB series data (one pair per language)
title_mod, series_titles = '[LANG]: ', {}
Expand Down Expand Up @@ -168,7 +168,7 @@ def Update(self, metadata, media, lang, force):
Log('Genres: %s' % ', '.join(tags))

# Get Collections
groupinfo = HttpReq('api/v3/Series/%s/Group' % aid)
groupinfo = HttpReq('api/v3/Series/%s/Group' % aid) # http://127.0.0.1:8111/api/v3/Series/24/Group
metadata.collections.clear()
if groupinfo['Size'] > 1: metadata.collections = [groupinfo['Name']]
Log('Collection: %s' % metadata.collections[0])
Expand Down Expand Up @@ -197,9 +197,19 @@ def Update(self, metadata, media, lang, force):
Log('Content Rating (Assumed): %s' % metadata.content_rating)

# Get Posters & Backgrounds
images = try_get(series_data, 'Images', {})
self.image_add(metadata.posters, try_get(images, 'Posters', []))
self.image_add(metadata.art, try_get(images, 'Backdrops', []))
if Prefs['addEveryImage']:
images = HttpReq('api/v3/Series/%s/Images?includeDisabled=false' % aid) # http://127.0.0.1:8111/api/v3/Series/24/Images?includeDisabled=false
posters, backdrops = try_get(images, 'Posters', []), try_get(images, 'Backdrops', [])
for poster in posters: # Move preferred poster to the top of the list
if poster['Preferred']: posters.insert(0, posters.pop(posters.index(poster)))
self.image_add(metadata.posters, posters)
for backdrop in backdrops: # Move preferred backdrop to the top of the list
if backdrop['Preferred']: backdrops.insert(0, backdrops.pop(backdrops.index(backdrop)))
self.image_add(metadata.art, backdrops)
else:
preferred_image = try_get(series_data, 'Images', {}) # Series data only contains the preferred image for each type
self.image_add(metadata.posters, try_get(preferred_image, 'Posters', []))
self.image_add(metadata.art, try_get(preferred_image, 'Backdrops', []))

# Get Cast & Crew
cast_crew = HttpReq('api/v3/Series/%s/Cast' % aid) # http://127.0.0.1:8111/api/v3/Series/24/Cast
Expand Down Expand Up @@ -244,7 +254,7 @@ def Update(self, metadata, media, lang, force):
if not staff_check: Log('N/A')

# Get episode list using series ID
episodes = HttpReq('api/v3/Series/%s/Episode?pageSize=0' % aid) # http://127.0.0.1:8111/api/v3/Series/212/Episode?pageSize=0
episodes = HttpReq('api/v3/Series/%s/Episode?pageSize=0' % aid) # http://127.0.0.1:8111/api/v3/Series/24/Episode?pageSize=0

for episode in episodes['List']:
# Get episode data
Expand Down Expand Up @@ -310,7 +320,7 @@ def Update(self, metadata, media, lang, force):
else: episode_obj.originally_available_at = None
# Remove the air dates for negative seasons according to the language preference
if season == -4 and Prefs['disableNegativeSeasonAirdates'] == 'Exclude Other': pass
elif season < 0 and Prefs['disableNegativeSeasonAirdates'] != 'None':
elif season < 0 and Prefs['disableNegativeSeasonAirdates'] != 'Disabled':
airdate_log, episode_obj.originally_available_at = 'Disabled in Agent Settings - Skipping!', None
Log('Originally Available: %s' % airdate_log)

Expand Down Expand Up @@ -374,7 +384,7 @@ def Update(self, metadata, media, lang, force):
Log('Error Adding Theme Music: %s (Not Found)' % THEME_URL)

def image_add(self, meta, images):
valid, art_url = list(), ''
valid, url = list(), ''
for image in images:
try:
url = 'http://%s:%s/api/v3/Image/%s/%s/%s' % (Prefs['Hostname'], Prefs['Port'], image['Source'], image['Type'], image['ID'])
Expand Down
9 changes: 8 additions & 1 deletion Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
"default": false
},

{
"id": "addEveryImage",
"label": "Add all posters and backdrops from Shoko instead of just the preferred one",
"type": "bool",
"default": false
},

{
"id": "sanitizeSummary",
"label": "The degree to which the summary is cleaned of extraneous info ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ This includes lines starting with general info (\"Source: \", \"Note: \", \"Summary: \"), as well as other miscellaneous lines (\"* \", \"-- \", \"~ \").",
Expand All @@ -112,7 +119,7 @@
"id": "disableNegativeSeasonAirdates",
"label": "Leave the \"Originally Available\" field blank for \"Credits\", \"Trailers\", \"Parodies\", and \"Other\" episode types. This is a workaround to prevent Plex from playing them before regular episodes and specials.",
"type": "enum",
"values" : ["All", "Exclude Other", "None"],
"values" : ["Enabled", "Exclude Other", "Disabled"],
"default": "Exclude Other"
}
]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This is a bundle containing a Plex metadata agent, scanner, and automation scrip
- The Shoko Server Port
- Collections: `Hide items which are in collections`
- Seasons: `Hide for single-season series`
- In Plex: `Settings > Agents > Shows > ShokoRelay` move the following entry to the top of the list and enable it:
- In Plex: `Settings > Agents (Legacy) > Shows > ShokoRelay` move the following entry to the top of the list and enable it:
- [x] Local Media Assets (TV)

### Recommended Shoko Server Configuration
Expand Down

0 comments on commit d8e1485

Please sign in to comment.