7 changed files with 161 additions and 139 deletions
@ -0,0 +1,71 @@ |
|||
from couchpotato.core.event import addEvent, fireEvent |
|||
from couchpotato.core.helpers.variable import tryInt |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.media._base.library.base import LibraryBase |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
autoload = 'EpisodeLibraryPlugin' |
|||
|
|||
|
|||
class EpisodeLibraryPlugin(LibraryBase): |
|||
def __init__(self): |
|||
addEvent('library.query', self.query) |
|||
addEvent('library.identifier', self.identifier) |
|||
|
|||
def query(self, media, first = True, condense = True, include_identifier = True, **kwargs): |
|||
if media.get('type') != 'episode': |
|||
return |
|||
|
|||
related = fireEvent('library.related', media, single = True) |
|||
|
|||
# Get season titles |
|||
titles = fireEvent( |
|||
'library.query', related['season'], |
|||
|
|||
first = False, |
|||
include_identifier = include_identifier, |
|||
condense = condense, |
|||
|
|||
single = True |
|||
) |
|||
|
|||
# Add episode identifier to titles |
|||
if include_identifier: |
|||
identifier = fireEvent('library.identifier', media, single = True) |
|||
|
|||
if identifier and identifier.get('episode'): |
|||
titles = [title + ('E%02d' % identifier['episode']) for title in titles] |
|||
|
|||
if first: |
|||
return titles[0] if titles else None |
|||
|
|||
return titles |
|||
|
|||
def identifier(self, media): |
|||
if media.get('type') != 'episode': |
|||
return |
|||
|
|||
identifier = { |
|||
'season': None, |
|||
'episode': None |
|||
} |
|||
|
|||
# TODO identifier mapping |
|||
# scene_map = media['info'].get('map_episode', {}).get('scene') |
|||
|
|||
# if scene_map: |
|||
# # Use scene mappings if they are available |
|||
# identifier['season'] = scene_map.get('season_nr') |
|||
# identifier['episode'] = scene_map.get('episode_nr') |
|||
# else: |
|||
# Fallback to normal season/episode numbers |
|||
identifier['season'] = media['info'].get('season_number') |
|||
identifier['episode'] = media['info'].get('number') |
|||
|
|||
# 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 |
@ -0,0 +1,52 @@ |
|||
from couchpotato.core.event import addEvent, fireEvent |
|||
from couchpotato.core.helpers.variable import tryInt |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.media._base.library.base import LibraryBase |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
autoload = 'SeasonLibraryPlugin' |
|||
|
|||
|
|||
class SeasonLibraryPlugin(LibraryBase): |
|||
def __init__(self): |
|||
addEvent('library.query', self.query) |
|||
addEvent('library.identifier', self.identifier) |
|||
|
|||
def query(self, media, first = True, condense = True, include_identifier = True, **kwargs): |
|||
if media.get('type') != 'season': |
|||
return |
|||
|
|||
related = fireEvent('library.related', media, single = True) |
|||
|
|||
# Get show titles |
|||
titles = fireEvent( |
|||
'library.query', related['show'], |
|||
|
|||
first = False, |
|||
condense = condense, |
|||
|
|||
single = True |
|||
) |
|||
|
|||
# TODO map_names |
|||
|
|||
# Add season identifier to titles |
|||
if include_identifier: |
|||
identifier = fireEvent('library.identifier', media, single = True) |
|||
|
|||
if identifier and identifier.get('season') is not None: |
|||
titles = [title + (' S%02d' % identifier['season']) for title in titles] |
|||
|
|||
if first: |
|||
return titles[0] if titles else None |
|||
|
|||
return titles |
|||
|
|||
def identifier(self, media): |
|||
if media.get('type') != 'season': |
|||
return |
|||
|
|||
return { |
|||
'season': tryInt(media['info']['number'], None) |
|||
} |
@ -0,0 +1,38 @@ |
|||
from couchpotato.core.event import addEvent |
|||
from couchpotato.core.helpers.encoding import simplifyString |
|||
from couchpotato.core.logger import CPLog |
|||
from couchpotato.core.media._base.library.base import LibraryBase |
|||
from qcond import QueryCondenser |
|||
|
|||
log = CPLog(__name__) |
|||
|
|||
autoload = 'ShowLibraryPlugin' |
|||
|
|||
|
|||
class ShowLibraryPlugin(LibraryBase): |
|||
query_condenser = QueryCondenser() |
|||
|
|||
def __init__(self): |
|||
addEvent('library.query', self.query) |
|||
|
|||
def query(self, media, first = True, condense = True, include_identifier = True, **kwargs): |
|||
if media.get('type') != 'show': |
|||
return |
|||
|
|||
titles = media['info']['titles'] |
|||
|
|||
if condense: |
|||
# Use QueryCondenser to build a list of optimal search titles |
|||
condensed_titles = self.query_condenser.distinct(titles) |
|||
|
|||
if condensed_titles: |
|||
# Use condensed titles if we got a valid result |
|||
titles = condensed_titles |
|||
else: |
|||
# Fallback to simplifying titles |
|||
titles = [simplifyString(title) for title in titles] |
|||
|
|||
if first: |
|||
return titles[0] if titles else None |
|||
|
|||
return titles |
Loading…
Reference in new issue