Skip to content

Commit 6534119

Browse files
committed
helper: commands: extraids: allow to provide TV shows IMDB ID
When resolving episodes, sometimes the first aired date returned by TheTVDB is not matching the one of IMDB. In such situations, a TV shows might be discarded even though it was the right one. This thus allows to instead match using the IMDB ID even when the year does not match. Fixes #98 Signed-off-by: Raphaël Beamonte <[email protected]>
1 parent 6c136e5 commit 6534119

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

helper/commands/extraids.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
##############################################################################
4444
# To resolve an episode ids
45-
def resolve_episode_ids(series, season, episode, year=None):
45+
def resolve_episode_ids(series, season, episode, year=None, imdbid=None):
4646
# To store the IDs found
4747
ids = {}
4848

@@ -60,22 +60,24 @@ def resolve_episode_ids(series, season, episode, year=None):
6060
# Try getting the series directly, but check the year if available
6161
# as sometimes series have the same name but are from different years
6262
tvdb_series = tvdb[series]
63-
if year is not None and tvdb_series['firstAired'] and \
63+
if (imdbid is None or tvdb_series['imdbId'] != imdbid) and \
64+
year is not None and tvdb_series['firstAired'] and \
6465
year != int(tvdb_series['firstAired'].split('-')[0]):
6566
# It is not the expected year, we thus need to perform a search
6667
tvdb_series = None
6768
tvdb_search = tvdb.search(series)
6869
for s in tvdb_search:
69-
if not s['seriesName'].startswith(series):
70-
LOGGER.debug('TVDB: Discarding result because of the name '
71-
'not beginning with the expected series '
72-
'name: {}'.format(s))
73-
continue
74-
75-
if int(s['firstAired'].split('-')[0]) != year:
76-
LOGGER.debug('TVDB: Discarding result because of the year '
77-
'not matching: {}'.format(s))
78-
continue
70+
if imdbid is None or s['imdbId'] != imdbid:
71+
if not s['seriesName'].startswith(series):
72+
LOGGER.debug('TVDB: Discarding result because of the '
73+
'name not beginning with the expected '
74+
'series name: {}'.format(s))
75+
continue
76+
77+
if int(s['firstAired'].split('-')[0]) != year:
78+
LOGGER.debug('TVDB: Discarding result because of the '
79+
'year not matching: {}'.format(s))
80+
continue
7981

8082
tvdb_series = tvdb[s['seriesName']]
8183
break
@@ -174,6 +176,7 @@ class Media(object):
174176
episode = None
175177
movie = None
176178
year = None
179+
imdbid = None
177180

178181

179182
##############################################################################
@@ -186,12 +189,12 @@ def __init__(self, option_strings, dest, default=None,
186189
required=required, help=help)
187190

188191
def __call__(self, parser, namespace, values, option_strings=None):
189-
if len(values) < 3 or len(values) > 4:
192+
if len(values) < 3 or len(values) > 5:
190193
parser.error('argument {}: format is SERIES_NAME SEASON_NUMBER '
191-
'EPISODE_NUMBER [YEAR]')
194+
'EPISODE_NUMBER [YEAR [SERIES_IMDBID]]')
192195
return
193196

194-
for i, v in enumerate(values[1:]):
197+
for i, v in enumerate(values[1:-1]):
195198
try:
196199
values[i + 1] = int(v)
197200
except ValueError:
@@ -203,8 +206,10 @@ def __call__(self, parser, namespace, values, option_strings=None):
203206
media.series = values[0]
204207
media.season = values[1]
205208
media.episode = values[2]
206-
if len(values) > 3:
209+
if len(values) > 3 and values[3]:
207210
media.year = values[3]
211+
if len(values) > 4 and values[4]:
212+
media.imdbid = values[4]
208213

209214
current = getattr(namespace, self.dest)
210215
if current is None:
@@ -237,7 +242,7 @@ def __call__(self, parser, namespace, values, option_strings=None):
237242

238243
media = Media()
239244
media.movie = values[0]
240-
if len(values) > 1:
245+
if len(values) > 1 and values[1]:
241246
media.year = values[1]
242247

243248
current = getattr(namespace, self.dest)
@@ -280,7 +285,7 @@ def run(self, episodes, movies):
280285

281286
for e in episodes:
282287
ep_ids = resolve_episode_ids(e.series, e.season,
283-
e.episode, e.year)
288+
e.episode, e.year, e.imdbid)
284289

285290
ids.setdefault(
286291
'episode', {}).setdefault(

helper/commands/resolve.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,9 @@ def insert_hash(media, ratio):
875875
m_season = m['base']['season']
876876
m_ep = m['base']['episode']
877877
m_year = m['base']['parentTitle']['year']
878-
ids = resolve_episode_ids(m_series, m_season, m_ep, m_year)
878+
m_series_imdbid = m['base']['parentTitle']['id'][7:-1]
879+
ids = resolve_episode_ids(m_series, m_season, m_ep, m_year,
880+
m_series_imdbid)
879881
else:
880882
m_movie = m['base']['title']
881883
m_year = m['base']['year']

trakt.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,12 @@ function process_scrobble_ready()
24142414
table.insert(command, imdbinfo.parentTitle.title)
24152415
table.insert(command, tostring(imdbinfo.season))
24162416
table.insert(command, tostring(imdbinfo.episode))
2417-
table.insert(command, tostring(imdbinfo.parentTitle.year))
2417+
table.insert(
2418+
command,
2419+
tostring(imdbinfo.parentTitle.year))
2420+
table.insert(
2421+
command,
2422+
string.sub(imdbinfo.parentTitle.id, 8, -2))
24182423
else
24192424
table.insert(command, '--movie')
24202425
table.insert(command, imdbinfo.title)

0 commit comments

Comments
 (0)