searcher and matcher now uses the new related_libraries and root_library from media instead of using extra db queries
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
from couchpotato import get_session, Env
|
from couchpotato import Env, get_session
|
||||||
from couchpotato.core.event import addEvent, fireEvent
|
from couchpotato.core.event import addEvent, fireEvent
|
||||||
from couchpotato.core.helpers.variable import getTitle, tryInt, toIterable
|
from couchpotato.core.helpers.variable import getTitle, tryInt, toIterable
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.media._base.searcher.main import SearchSetupError
|
from couchpotato.core.media._base.searcher.main import SearchSetupError
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
from couchpotato.core.settings.model import Media, Library
|
from couchpotato.core.settings.model import Media
|
||||||
from qcond import QueryCondenser
|
from qcond import QueryCondenser
|
||||||
from qcond.helpers import simplify
|
from qcond.helpers import simplify
|
||||||
|
|
||||||
@@ -42,6 +42,8 @@ class ShowSearcher(Plugin):
|
|||||||
addEvent('searcher.get_media_identifier', self.getMediaIdentifier)
|
addEvent('searcher.get_media_identifier', self.getMediaIdentifier)
|
||||||
|
|
||||||
def single(self, media, search_protocols = None, manual = False):
|
def single(self, media, search_protocols = None, manual = False):
|
||||||
|
show, season, episode = self.getLibraries(media['library'])
|
||||||
|
|
||||||
if media['type'] == 'show':
|
if media['type'] == 'show':
|
||||||
# TODO handle show searches (scan all seasons)
|
# TODO handle show searches (scan all seasons)
|
||||||
return
|
return
|
||||||
@@ -72,9 +74,7 @@ class ShowSearcher(Plugin):
|
|||||||
#fireEvent('episode.delete', episode['id'], single = True)
|
#fireEvent('episode.delete', episode['id'], single = True)
|
||||||
return
|
return
|
||||||
|
|
||||||
# TODO replace with 'related_libraries'
|
if not show or not season:
|
||||||
show, season, episode = self.getMedia(media)
|
|
||||||
if show is None or season is None:
|
|
||||||
log.error('Unable to find show or season library in database, missing required data for searching')
|
log.error('Unable to find show or season library in database, missing required data for searching')
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ class ShowSearcher(Plugin):
|
|||||||
# Don't search for quality lower then already available.
|
# Don't search for quality lower then already available.
|
||||||
if has_better_quality is 0:
|
if has_better_quality is 0:
|
||||||
|
|
||||||
log.info('Search for %s S%02d%s in %s', (getTitle(show), season.season_number, "E%02d" % episode.episode_number if episode else "", quality_type['quality']['label']))
|
log.info('Search for %s S%02d%s in %s', (getTitle(show), season['season_number'], "E%02d" % episode['episode_number'] if episode else "", quality_type['quality']['label']))
|
||||||
quality = fireEvent('quality.single', identifier = quality_type['quality']['identifier'], single = True)
|
quality = fireEvent('quality.single', identifier = quality_type['quality']['identifier'], single = True)
|
||||||
|
|
||||||
results = fireEvent('searcher.search', search_protocols, media, quality, single = True)
|
results = fireEvent('searcher.search', search_protocols, media, quality, single = True)
|
||||||
@@ -139,16 +139,16 @@ class ShowSearcher(Plugin):
|
|||||||
if media['type'] not in ['show', 'season', 'episode']:
|
if media['type'] not in ['show', 'season', 'episode']:
|
||||||
return
|
return
|
||||||
|
|
||||||
# TODO replace with 'related_libraries'
|
show, season, episode = self.getLibraries(media['library'])
|
||||||
show, season, episode = self.getMedia(media)
|
|
||||||
if show is None:
|
if not show:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
titles = []
|
titles = []
|
||||||
|
|
||||||
# Add season map_names if they exist
|
# Add season map_names if they exist
|
||||||
if season is not None and 'map_names' in show.info:
|
if season is not None and 'map_names' in show['info']:
|
||||||
season_names = show.info['map_names'].get(str(season.season_number), {})
|
season_names = show['info']['map_names'].get(str(season['season_number']), {})
|
||||||
|
|
||||||
# Add titles from all locations
|
# Add titles from all locations
|
||||||
# TODO only add name maps from a specific location
|
# TODO only add name maps from a specific location
|
||||||
@@ -156,7 +156,7 @@ class ShowSearcher(Plugin):
|
|||||||
titles += [name for name in names if name not in titles]
|
titles += [name for name in names if name not in titles]
|
||||||
|
|
||||||
# Add show titles
|
# Add show titles
|
||||||
titles += [title.title for title in show.titles if title.title not in titles]
|
titles += [title['title'] for title in show['titles'] if title['title'] not in titles]
|
||||||
|
|
||||||
# Use QueryCondenser to build a list of optimal search titles
|
# Use QueryCondenser to build a list of optimal search titles
|
||||||
condensed_titles = self.query_condenser.distinct(titles)
|
condensed_titles = self.query_condenser.distinct(titles)
|
||||||
@@ -200,12 +200,6 @@ class ShowSearcher(Plugin):
|
|||||||
if not fireEvent('searcher.correct_words', release['name'], media, single = True):
|
if not fireEvent('searcher.correct_words', release['name'], media, single = True):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# TODO replace with 'related_libraries'
|
|
||||||
show, season, episode = self.getMedia(media)
|
|
||||||
if show is None or season is None:
|
|
||||||
log.error('Unable to find show or season library in database, missing required data for searching')
|
|
||||||
return
|
|
||||||
|
|
||||||
match = fireEvent('matcher.best', release, media, quality, single = True)
|
match = fireEvent('matcher.best', release, media, quality, single = True)
|
||||||
if match:
|
if match:
|
||||||
return match.weight
|
return match.weight
|
||||||
@@ -260,26 +254,24 @@ class ShowSearcher(Plugin):
|
|||||||
|
|
||||||
return identifier
|
return identifier
|
||||||
|
|
||||||
# TODO move this somewhere else
|
def getLibraries(self, library):
|
||||||
def getMedia(self, media):
|
if 'related_libraries' not in library:
|
||||||
db = get_session()
|
log.warning("'related_libraries' missing from media library, unable to continue searching")
|
||||||
|
return None, None, None
|
||||||
|
|
||||||
media_library = db.query(Library).filter_by(id = media['library_id']).first()
|
libraries = library['related_libraries']
|
||||||
|
|
||||||
show = None
|
# Get libraries and return lists only if there is multiple items
|
||||||
season = None
|
show = libraries.get('show', [])
|
||||||
episode = None
|
if len(show) <= 1:
|
||||||
|
show = show[0] if len(show) else None
|
||||||
|
|
||||||
if media['type'] == 'episode':
|
season = libraries.get('season', [])
|
||||||
show = media_library.parent.parent
|
if len(season) <= 1:
|
||||||
season = media_library.parent
|
season = season[0] if len(season) else None
|
||||||
episode = media_library
|
|
||||||
|
|
||||||
if media['type'] == 'season':
|
episode = libraries.get('episode', [])
|
||||||
show = media_library.parent
|
if len(episode) <= 1:
|
||||||
season = media_library
|
episode = episode[0] if len(episode) else None
|
||||||
|
|
||||||
if media['type'] == 'show':
|
|
||||||
show = media_library
|
|
||||||
|
|
||||||
return show, season, episode
|
return show, season, episode
|
||||||
|
|||||||
@@ -73,8 +73,7 @@ class Matcher(Plugin):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def correctTitle(self, chain, media):
|
def correctTitle(self, chain, media):
|
||||||
# TODO need to switch this to use media['related_libraries']
|
root_library = media['library']['root_library']
|
||||||
root_library = fireEvent('searcher.get_media_root', media['library'], single = True)
|
|
||||||
|
|
||||||
if 'show_name' not in chain.info or not len(chain.info['show_name']):
|
if 'show_name' not in chain.info or not len(chain.info['show_name']):
|
||||||
log.info('Wrong: missing show name in parsed result')
|
log.info('Wrong: missing show name in parsed result')
|
||||||
|
|||||||
Reference in New Issue
Block a user