Moved 'searcher.get_media_identifier' into season and episode libraries as 'library.identifier'
This commit is contained in:
@@ -17,10 +17,39 @@ class EpisodeLibraryPlugin(LibraryBase):
|
||||
default_dict = {'titles': {}, 'files':{}}
|
||||
|
||||
def __init__(self):
|
||||
addEvent('library.identifier', self.identifier)
|
||||
addEvent('library.add.episode', self.add)
|
||||
addEvent('library.update.episode', self.update)
|
||||
addEvent('library.update.episode_release_date', self.updateReleaseDate)
|
||||
|
||||
def identifier(self, library):
|
||||
if library.get('type') != 'episode':
|
||||
return
|
||||
|
||||
identifier = {
|
||||
'season': None,
|
||||
'episode': None
|
||||
}
|
||||
|
||||
scene_map = library['info'].get('map_episode', {}).get('scene')
|
||||
|
||||
if scene_map:
|
||||
# Use scene mappings if they are available
|
||||
identifier['season'] = scene_map.get('season')
|
||||
identifier['episode'] = scene_map.get('episode')
|
||||
else:
|
||||
# Fallback to normal season/episode numbers
|
||||
identifier['season'] = library.get('season')
|
||||
identifier['episode'] = library.get('episode')
|
||||
|
||||
|
||||
# Cast identifiers to integers
|
||||
# TODO this will need changing to support identifiers with trailing 'a', 'b' characters
|
||||
identifier['season'] = tryInt(identifier['season'], None)
|
||||
identifier['episode'] = tryInt(identifier['episode'], None)
|
||||
|
||||
return identifier
|
||||
|
||||
def add(self, attrs = {}, update_after = True):
|
||||
type = attrs.get('type', 'episode')
|
||||
primary_provider = attrs.get('primary_provider', 'thetvdb')
|
||||
|
||||
@@ -17,10 +17,22 @@ class SeasonLibraryPlugin(LibraryBase):
|
||||
default_dict = {'titles': {}, 'files':{}}
|
||||
|
||||
def __init__(self):
|
||||
addEvent('library.identifier', self.identifier)
|
||||
addEvent('library.add.season', self.add)
|
||||
addEvent('library.update.season', self.update)
|
||||
addEvent('library.update.season_release_date', self.updateReleaseDate)
|
||||
|
||||
def identifier(self, library):
|
||||
if library.get('type') != 'season':
|
||||
return
|
||||
|
||||
season_num = tryInt(library['season_number'], None)
|
||||
|
||||
return {
|
||||
'season': season_num,
|
||||
'episode': None
|
||||
}
|
||||
|
||||
def add(self, attrs = {}, update_after = True):
|
||||
type = attrs.get('type', 'season')
|
||||
primary_provider = attrs.get('primary_provider', 'thetvdb')
|
||||
|
||||
@@ -39,8 +39,6 @@ class ShowSearcher(Plugin):
|
||||
addEvent('searcher.correct_match', self.correctMatch)
|
||||
addEvent('searcher.correct_release', self.correctRelease)
|
||||
|
||||
addEvent('searcher.get_media_identifier', self.getMediaIdentifier)
|
||||
|
||||
def single(self, media, search_protocols = None, manual = False):
|
||||
show, season, episode = self.getLibraries(media['library'])
|
||||
|
||||
@@ -175,9 +173,9 @@ class ShowSearcher(Plugin):
|
||||
return None
|
||||
|
||||
# Add the identifier to search title
|
||||
# TODO supporting other identifier formats
|
||||
identifier = fireEvent('searcher.get_media_identifier', media['library'], single = True)
|
||||
identifier = fireEvent('library.identifier', media['library'], single = True)
|
||||
|
||||
# TODO this needs to support other identifier formats
|
||||
if identifier['season']:
|
||||
title += ' S%02d' % identifier['season']
|
||||
|
||||
@@ -200,6 +198,7 @@ class ShowSearcher(Plugin):
|
||||
if not fireEvent('searcher.correct_words', release['name'], media, single = True):
|
||||
return False
|
||||
|
||||
# TODO Matching is quite costly, maybe we should be caching release matches somehow? (also look at caper optimizations)
|
||||
match = fireEvent('matcher.best', release, media, quality, single = True)
|
||||
if match:
|
||||
return match.weight
|
||||
@@ -224,36 +223,6 @@ class ShowSearcher(Plugin):
|
||||
|
||||
return True
|
||||
|
||||
# TODO move this somewhere else
|
||||
def getMediaIdentifier(self, media_library):
|
||||
if media_library['type'] not in ['show', 'season', 'episode']:
|
||||
return None
|
||||
|
||||
identifier = {
|
||||
'season': None,
|
||||
'episode': None
|
||||
}
|
||||
|
||||
if media_library['type'] == 'episode':
|
||||
map_episode = media_library['info'].get('map_episode')
|
||||
|
||||
if map_episode and 'scene' in map_episode:
|
||||
identifier['season'] = map_episode['scene'].get('season')
|
||||
identifier['episode'] = map_episode['scene'].get('episode')
|
||||
else:
|
||||
# TODO xem mapping?
|
||||
identifier['season'] = media_library.get('season_number')
|
||||
identifier['episode'] = media_library.get('episode_number')
|
||||
|
||||
if media_library['type'] == 'season':
|
||||
identifier['season'] = media_library.get('season_number')
|
||||
|
||||
# Try cast identifier values to integers
|
||||
identifier['season'] = tryInt(identifier['season'], None)
|
||||
identifier['episode'] = tryInt(identifier['episode'], None)
|
||||
|
||||
return identifier
|
||||
|
||||
def getLibraries(self, library):
|
||||
if 'related_libraries' not in library:
|
||||
log.warning("'related_libraries' missing from media library, unable to continue searching")
|
||||
|
||||
@@ -50,7 +50,7 @@ class Matcher(Plugin):
|
||||
return set([key for key, value in tags.items() if None not in value]) == set(found_tags)
|
||||
|
||||
def correctIdentifier(self, chain, media):
|
||||
required_id = fireEvent('searcher.get_media_identifier', media['library'], single = True)
|
||||
required_id = fireEvent('library.identifier', media['library'], single = True)
|
||||
|
||||
if 'identifier' not in chain.info:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user