Skip to content

Commit

Permalink
Fix Some Episode Title Variable Assignments and Tweak the Fallback
Browse files Browse the repository at this point in the history
- The wrong variable was assigned to break the episode title preference loop (only affected the preferred title being overridden)
- The wrong variable was also assigned for the final tmdb episode title override

also:
- bump versions
- compress the series_titles dict creation
- don't do the final tmdb episode title fallback if the tmdb title is Episode/Volume # (same result but better logging)
- specify that the final tmdb episode title fallback is using the preferred language in the logs
  • Loading branch information
natyusha committed Sep 30, 2024
1 parent 6d03b82 commit 5a47951
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def ValidatePrefs():
pass

def Start():
Log('======================[Shoko Relay Agent v1.2.12]======================')
Log('======================[Shoko Relay Agent v1.2.13]======================')
HTTP.Headers['Accept'] = 'application/json'
HTTP.ClearCache() # Clear the cache possibly removing stuck metadata
HTTP.CacheTime = 0.1 # Reduce the cache time as much as possible since Shoko has all the metadata
Expand Down Expand Up @@ -60,8 +60,7 @@ def Update(self, metadata, media, lang, force):

# Make a dict of language -> title for all series titles in the AniDB series data (one pair per language)
title_mod, series_titles = '[LANG]: ', {}
for item in sorted(series_data['AniDB']['Titles'], key=lambda item: item['Type'], reverse=True): # Sort by reversed Type (Synonym -> Short -> Official -> Main) so that the dict prioritises official titles over synonyms
if item['Type'] != 'Short': series_titles[item['Language']] = item['Name'] # Exclude all short titles
for item in [i for i in sorted(series_data['AniDB']['Titles'], key=lambda i: i['Type'], reverse=True) if i['Type'] != 'Short']: series_titles[item['Language']] = item['Name'] # Sort by reversed Type (Synonym -> Short (Excluded) -> Official -> Main) so that the dict prioritises official titles over synonyms
series_titles['shoko'] = series_data['Name'] # Add Shoko's preferred series title to the dict

# Get Title according to the language preference
Expand Down Expand Up @@ -275,12 +274,12 @@ def Update(self, metadata, media, lang, force):
ep_title_mod, tmdb_ep_title = '[LANG]: ', try_get(tmdb_ep_data, 'Title', None)
for lang in [l.strip().lower() for l in Prefs['EpisodeTitleLanguage'].split(',')]:
episode_title = try_get(episode_titles, lang, None)
if title: break
if episode_title: break
if not episode_title: episode_title, lang = episode_titles['shoko'], 'shoko (fallback)' # If not found, fallback to Shoko's preferred episode title

# Replace ambiguous title with series title
SingleEntryTitles = ('Complete Movie', 'Music Video', 'OAD', 'OVA', 'Short Movie', 'Special', 'TV Special', 'Web') # AniDB titles used for single entries which are ambiguous
if episode_title in SingleEntryTitles:
ambiguous_titles = ('Complete Movie', 'Music Video', 'OAD', 'OVA', 'Short Movie', 'Special', 'TV Special', 'Web') # AniDB titles used for single entries which are ambiguous
if episode_title in ambiguous_titles:
# Get series title according to the language preference
ep_title_mod, original_title = '(FromSeries) [LANG]: ', episode_title
for lang in [l.strip().lower() for l in Prefs['EpisodeTitleLanguage'].split(',')]:
Expand All @@ -293,7 +292,8 @@ def Update(self, metadata, media, lang, force):
episode_title += ' — ' + original_title

# TMDB episode title override (if the episode title is Episode/Volume [S]# on AniDB excluding Episode/Volume 0) and there is a TMDB match
if tmdb_ep_title and re.match(r'^(?:Episode|Volume)(?: | S)[1-9][0-9]*$', episode_title): ep_title_mod, episode_title = '(TMDB Override) [LANG]: ', tmdb_title
default_titles = r'^(Episode|Volume) S?[1-9][0-9]*$' # Regex pattern for default episode titles
if tmdb_ep_title and re.match(default_titles, episode_title) and not re.match(default_titles, tmdb_ep_title): ep_title_mod, episode_title, lang = '(TMDB Override) [LANG]: ', tmdb_ep_title, 'shoko'

episode_obj.title = episode_title
Log('Title %s %s [%s]' % (ep_title_mod, episode_obj.title, lang.upper()))
Expand Down
2 changes: 1 addition & 1 deletion Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>CFBundleName</key>
<string>Shoko Relay</string>
<key>CFBundleVersion</key>
<string>1.2.12</string>
<string>1.2.13</string>
<key>CFBundleIdentifier</key>
<string>com.plexapp.agents.shokorelay</string>
<key>PlexClientPlatforms</key>
Expand Down
2 changes: 1 addition & 1 deletion Contents/Scanners/Series/Shoko Relay Scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def Scan(path, files, mediaList, subdirs, language=None, root=None):
if files : Log.debug('[Files] %s' % ', '.join(files))

for subdir in subdirs: Log.debug('[Folder] %s' % os.path.relpath(subdir, root))
Log.info('===========================[Shoko Relay Scanner v1.2.12]' + '=' * 244)
Log.info('===========================[Shoko Relay Scanner v1.2.13]' + '=' * 244)

if files:
# Scan for video files
Expand Down

0 comments on commit 5a47951

Please sign in to comment.