Skip to content

Commit 347f453

Browse files
committed
Enable TMDB Title Check / Refactor TMDB File Grouping Check
- the tmdb title check was from the old tvdb implementation and wasn't functional after changes - use nested list comprehension to condense the tmdb file grouping check - don't check for episode groups when the tmdb type is a movie - log the tmdb type along with the id
1 parent 587944d commit 347f453

2 files changed

Lines changed: 23 additions & 25 deletions

File tree

Contents/Code/__init__.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ def Update(self, metadata, media, lang, force):
7979
if title.startswith(CommonTitlePrefixes): title_mod, title = '(Prefix Moved) [LANG]:', (lambda t: t[1] + ' — ' + t[0])(title.split(' ', 1))
8080

8181
# If SingleSeasonOrdering isn't enabled determine the TMDB type
82-
tmdb_type, tmdb_title, tmdb_group_size = None, '', 0
82+
tmdb_type, tmdb_type_log, tmdb_title, tmdb_group = None, '', '', False
8383
if not Prefs['SingleSeasonOrdering']:
84-
if try_get(series_data['TMDB']['Shows'], 0, None) : tmdb_type = 'Shows'
85-
elif try_get(series_data['TMDB']['Movies'], 0, None) : tmdb_type = 'Movies'
84+
if try_get(series_data['TMDB']['Shows'], 0, None) : tmdb_type, tmdb_type_log = 'Shows' , 'tv/'
85+
elif try_get(series_data['TMDB']['Movies'], 0, None) : tmdb_type, tmdb_type_log = 'Movies' , 'movie/'
8686
if tmdb_type: # If TMDB type is populated add the title as a comparison to the regular one to help spot mismatches
8787
tmdb_title, tmdb_id = try_get(series_data['TMDB'][tmdb_type][0], 'Title', None), try_get(series_data['TMDB'][tmdb_type][0], 'ID', None)
88-
tmdb_episode_groups = HttpReq('api/v3/Series/%s/TMDB/Show/CrossReferences/EpisodeGroups?tmdbShowID=%s&pageSize=0&page=1' % (series_id, tmdb_id)) # http://127.0.0.1:8111/api/v3/Series/24/TMDB/Show/CrossReferences/EpisodeGroups?tmdbShowID=1873&pageSize=0&page=1
89-
if not tmdb_title: tmdb_title = 'N/A (CRITICAL: Removed from TMDB or Missing Data) - Falling Back to AniDB Ordering!' # Account for rare cases where Shoko has a TMDB ID that returns no data
90-
Log('TMDB Check (Title [ID]): %s [%s]' % (tmdb_title, tmdb_id))
88+
tmdb_title_log = 'N/A (CRITICAL: Removed from TMDB or Missing Data) - Falling Back to AniDB Ordering!' if not tmdb_title else tmdb_title # Account for rare cases where Shoko has a TMDB ID that returns no data
89+
Log('TMDB Check (Title [ID]): %s [%s%s]' % (tmdb_title_log, tmdb_type_log, tmdb_id))
90+
tmdb_ep_groups = HttpReq('api/v3/Series/%s/TMDB/Show/CrossReferences/EpisodeGroups?tmdbShowID=%s&pageSize=0' % (series_id, tmdb_id)) if tmdb_type == 'Shows' else None # http://127.0.0.1:8111/api/v3/Series/24/TMDB/Show/CrossReferences/EpisodeGroups?tmdbShowID=1873&pageSize=0
9191

9292
metadata.title = title
9393
Log('Title %s %s [%s]' % (title_mod, title, lang.upper()))
@@ -259,15 +259,14 @@ def Update(self, metadata, media, lang, force):
259259
# Get episode data
260260
episode_id = episode['IDs']['ID']
261261
episode_data = HttpReq('api/v3/Episode/%s?includeDataFrom=AniDB,TMDB' % episode_id) # http://127.0.0.1:8111/api/v3/Episode/212?includeDataFrom=AniDB,TMDB
262-
tmdb_ep_data = try_get(episode_data['TMDB']['Episodes'], 0, None)
262+
tmdb_ep_data = try_get(episode_data['TMDB']['Episodes'], 0, None) if tmdb_title else None
263263
episode_type = episode_data['AniDB']['Type'] # Get episode type
264264

265265
# Ignore TMDB numbering for episodes split across multiple files (prevent file stacking in Plex)
266-
if tmdb_ep_data:
267-
for group in [g for g in tmdb_episode_groups['List'] if len(g) > 1]:
268-
for xref in group:
269-
if tmdb_group_size > 0: continue
270-
if xref['AnidbEpisodeID'] == episode_data['AniDB']['ID']: tmdb_group_size = len(group)
266+
if tmdb_ep_data and tmdb_ep_groups:
267+
for xref in [group for groups in [grp for grp in tmdb_ep_groups['List'] if len(grp) > 1] for group in groups]:
268+
if tmdb_group: continue
269+
if xref['AnidbEpisodeID'] == episode_data['AniDB']['ID']: tmdb_group = True
271270

272271
# Get season and episode numbers
273272
episode_source, season = '(AniDB):', 0
@@ -277,7 +276,7 @@ def Update(self, metadata, media, lang, force):
277276
elif episode_type == 'Trailer' : season = -2
278277
elif episode_type == 'Parody' : season = -3
279278
elif episode_type == 'Other' : season = -4
280-
if not tmdb_group_size and tmdb_ep_data: episode_source, season, episode_number = '(TMDB): ', tmdb_ep_data['SeasonNumber'], tmdb_ep_data['EpisodeNumber'] # Grab TMDB info when possible and enabled
279+
if tmdb_ep_data and not tmdb_group: episode_source, season, episode_number = '(TMDB): ', tmdb_ep_data['SeasonNumber'], tmdb_ep_data['EpisodeNumber'] # Grab TMDB info when possible and enabled
281280
else: episode_number = episode_data['AniDB']['EpisodeNumber'] # Fallback to AniDB info
282281

283282
Log('Season %s %s' % (episode_source, season))

Contents/Scanners/Series/Shoko Relay Scanner.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ def Scan(path, files, mediaList, subdirs, language=None, root=None):
115115
Log.info(' Title [ShokoID]: %s [%s]' % (show_title, series_id))
116116

117117
# If SingleSeasonOrdering isn't enabled determine the TMDB type
118-
tmdb_type, tmdb_title, tmdb_group_size = None, '', 0
118+
tmdb_type, tmdb_type_log, tmdb_title, tmdb_group = None, '', '', False
119119
if not Prefs['SingleSeasonOrdering']:
120-
if try_get(series_data['TMDB']['Shows'], 0, None) : tmdb_type = 'Shows'
121-
elif try_get(series_data['TMDB']['Movies'], 0, None) : tmdb_type = 'Movies'
120+
if try_get(series_data['TMDB']['Shows'], 0, None) : tmdb_type, tmdb_type_log = 'Shows' , 'tv/'
121+
elif try_get(series_data['TMDB']['Movies'], 0, None) : tmdb_type, tmdb_type_log = 'Movies' , 'movie/'
122122
if tmdb_type: # If TMDB type is populated add the title as a comparison to the regular one to help spot mismatches
123123
tmdb_title, tmdb_id = try_get(series_data['TMDB'][tmdb_type][0], 'Title', None), try_get(series_data['TMDB'][tmdb_type][0], 'ID', None)
124-
tmdb_episode_groups = HttpReq('api/v3/Series/%s/TMDB/Show/CrossReferences/EpisodeGroups?tmdbShowID=%s&pageSize=0&page=1' % (series_id, tmdb_id)) # http://127.0.0.1:8111/api/v3/Series/24/TMDB/Show/CrossReferences/EpisodeGroups?tmdbShowID=1873&pageSize=0&page=1
125-
if not tmdb_title: tmdb_title = 'N/A (CRITICAL: Removed from TMDB or Missing Data) - Falling Back to AniDB Ordering!' # Account for rare cases where Shoko has a TMDB ID that returns no data
126-
Log.info(' TMDB Check (Title [ID]): %s [%s]' % (tmdb_title, tmdb_id))
124+
tmdb_title_log = 'N/A (CRITICAL: Removed from TMDB or Missing Data) - Falling Back to AniDB Ordering!' if not tmdb_title else tmdb_title # Account for rare cases where Shoko has a TMDB ID that returns no data
125+
Log.info(' TMDB Check (Title [ID]): %s [%s%s]' % (tmdb_title_log, tmdb_type_log, tmdb_id))
126+
tmdb_ep_groups = HttpReq('api/v3/Series/%s/TMDB/Show/CrossReferences/EpisodeGroups?tmdbShowID=%s&pageSize=0' % (series_id, tmdb_id)) if tmdb_type == 'Shows' else None # http://127.0.0.1:8111/api/v3/Series/24/TMDB/Show/CrossReferences/EpisodeGroups?tmdbShowID=1873&pageSize=0
127127

128128
for episode in range(episode_multi):
129129
# Get episode data
@@ -136,11 +136,10 @@ def Scan(path, files, mediaList, subdirs, language=None, root=None):
136136
episode_type = episode_data['AniDB']['Type'] # Get episode type
137137

138138
# Ignore TMDB numbering for episodes split across multiple files (prevent file stacking in Plex)
139-
if tmdb_ep_data:
140-
for group in [groups for groups in tmdb_episode_groups['List'] if len(groups) > 1]:
141-
for xref in group:
142-
if tmdb_group_size > 0: continue
143-
if xref['AnidbEpisodeID'] == episode_data['AniDB']['ID']: tmdb_group_size = len(group)
139+
if tmdb_ep_data and tmdb_ep_groups:
140+
for xref in [group for groups in [grp for grp in tmdb_ep_groups['List'] if len(grp) > 1] for group in groups]:
141+
if tmdb_group: continue
142+
if xref['AnidbEpisodeID'] == episode_data['AniDB']['ID']: tmdb_group = True
144143

145144
# Get season and episode numbers
146145
episode_source, season = '(AniDB):', 0
@@ -150,7 +149,7 @@ def Scan(path, files, mediaList, subdirs, language=None, root=None):
150149
elif episode_type == 'Trailer' : season = -2
151150
elif episode_type == 'Parody' : season = -3
152151
elif episode_type == 'Other' : season = -4
153-
if not tmdb_group_size and tmdb_ep_data: episode_source, season, episode_number = '(TMDB): ', tmdb_ep_data['SeasonNumber'], tmdb_ep_data['EpisodeNumber'] # Grab TMDB info when possible and enabled
152+
if tmdb_ep_data and not tmdb_group: episode_source, season, episode_number = '(TMDB): ', tmdb_ep_data['SeasonNumber'], tmdb_ep_data['EpisodeNumber'] # Grab TMDB info when possible and enabled
154153
else: episode_number = episode_data['AniDB']['EpisodeNumber'] # Fallback to AniDB info
155154

156155
Log.info(' Season %s %s' % (episode_source, season))

0 commit comments

Comments
 (0)