thetvdb, add alternate titles if they exist
This commit is contained in:
@@ -54,12 +54,10 @@ class ShowBase(MediaBase):
|
||||
addEvent('show.add', self.add)
|
||||
|
||||
def search(self, q = '', **kwargs):
|
||||
|
||||
cache_key = u'%s/%s' % (__name__, simplifyString(q))
|
||||
shows = Env.get('cache').get(cache_key)
|
||||
|
||||
if not shows:
|
||||
|
||||
if getImdb(q):
|
||||
shows = [fireEvent('show.info', identifier = q, merge = True)]
|
||||
else:
|
||||
@@ -73,7 +71,6 @@ class ShowBase(MediaBase):
|
||||
}
|
||||
|
||||
def addView(self, **kwargs):
|
||||
|
||||
movie_dict = fireEvent('show.add', params=kwargs) # XXX: Temp added so we can catch a breakpoint
|
||||
#movie_dict = self.add(params = kwargs)
|
||||
|
||||
@@ -83,26 +80,6 @@ class ShowBase(MediaBase):
|
||||
'movie': movie_dict,
|
||||
}
|
||||
|
||||
# XXX: Remove function and reference to it!
|
||||
def debug(self, identifier):
|
||||
"""
|
||||
XXX: This is only a hook for a breakpoint so we can test database stuff easily
|
||||
REMOVE when finished
|
||||
"""
|
||||
from couchpotato import get_session
|
||||
from couchpotato.core.event import addEvent, fireEventAsync, fireEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode, simplifyString
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Library, LibraryTitle, File
|
||||
from string import ascii_letters
|
||||
import time
|
||||
import traceback
|
||||
|
||||
db = get_session()
|
||||
parent = db.query(Library).filter_by(identifier = identifier).first()
|
||||
return
|
||||
|
||||
def add(self, params = {}, force_readd = True, search_after = True, update_library = False, status_id = None):
|
||||
"""
|
||||
1. Add Show
|
||||
@@ -125,11 +102,10 @@ class ShowBase(MediaBase):
|
||||
log.debug("show.add")
|
||||
|
||||
# Add show parent to db first
|
||||
parent = self.addToDatabase(params = params, type = 'show')
|
||||
parent = self.addToDatabase(params = params, type = 'show')
|
||||
|
||||
identifier = params.get('id')
|
||||
|
||||
# XXX: add seasons
|
||||
# XXX: Fix so we dont have a nested list [0] (fireEvent)
|
||||
try:
|
||||
seasons = fireEvent('season.info', identifier = identifier)[0]
|
||||
@@ -156,7 +132,6 @@ class ShowBase(MediaBase):
|
||||
episode['parent_identifier'] = season['identifier']
|
||||
self.addToDatabase(params=episode, type = "episode")
|
||||
|
||||
#self.debug(str(identifier)) # XXX: Remove DEBUG only
|
||||
return parent
|
||||
|
||||
def addToDatabase(self, params = {}, type="show", force_readd = True, search_after = True, update_library = False, status_id = None):
|
||||
|
||||
@@ -72,8 +72,8 @@ class TheTVDb(ShowProvider):
|
||||
if raw:
|
||||
try:
|
||||
nr = 0
|
||||
for show in raw:
|
||||
show = self.tvdb[int(show['id'])]
|
||||
for show_info in raw:
|
||||
show = self.tvdb[int(show_info['id'])]
|
||||
results.append(self.parseShow(show))
|
||||
nr += 1
|
||||
if nr == limit:
|
||||
@@ -97,6 +97,23 @@ class TheTVDb(ShowProvider):
|
||||
|
||||
return show
|
||||
|
||||
def getShowInfo(self, identifier = None):
|
||||
if not identifier:
|
||||
return None
|
||||
|
||||
cache_key = 'thetvdb.cache.%s' % identifier
|
||||
log.debug('Getting showInfo: %s', cache_key)
|
||||
result = self.getCache(cache_key) or {}
|
||||
if result:
|
||||
return result
|
||||
|
||||
show = self.getShow(identifier=identifier)
|
||||
if show:
|
||||
result = self.parseShow(show)
|
||||
self.setCache(cache_key, result)
|
||||
|
||||
return result
|
||||
|
||||
def getSeasonInfo(self, identifier=None, season_identifier=None):
|
||||
"""Either return a list of all seasons or a single season by number.
|
||||
identifier is the show 'id'
|
||||
@@ -177,23 +194,6 @@ class TheTVDb(ShowProvider):
|
||||
self.setCache(cache_key, result)
|
||||
return result
|
||||
|
||||
def getShowInfo(self, identifier = None):
|
||||
if not identifier:
|
||||
return None
|
||||
|
||||
cache_key = 'thetvdb.cache.%s' % identifier
|
||||
log.debug('Getting showInfo: %s', cache_key)
|
||||
result = self.getCache(cache_key) or {}
|
||||
if result:
|
||||
return result
|
||||
|
||||
show = self.getShow(identifier=identifier)
|
||||
if show:
|
||||
result = self.parseShow(show)
|
||||
self.setCache(cache_key, result)
|
||||
|
||||
return result
|
||||
|
||||
def parseShow(self, show):
|
||||
"""
|
||||
show[74713] = {
|
||||
@@ -229,10 +229,10 @@ class TheTVDb(ShowProvider):
|
||||
# return None
|
||||
|
||||
## Images
|
||||
poster = self.getImage(show, type = 'poster', size = 'cover')
|
||||
backdrop = self.getImage(show, type = 'fanart', size = 'w1280')
|
||||
#poster_original = self.getImage(show, type = 'poster', size = 'original')
|
||||
#backdrop_original = self.getImage(show, type = 'backdrop', size = 'original')
|
||||
poster = show['poster']
|
||||
backdrop = show['fanart']
|
||||
#poster = self.getImage(show, type = 'poster', size = 'cover')
|
||||
#backdrop = self.getImage(show, type = 'fanart', size = 'w1280')
|
||||
|
||||
genres = [] if show['genre'] is None else show['genre'].strip('|').split('|')
|
||||
if show['firstaired'] is not None:
|
||||
@@ -276,15 +276,20 @@ class TheTVDb(ShowProvider):
|
||||
|
||||
show_data = dict((k, v) for k, v in show_data.iteritems() if v)
|
||||
|
||||
## Add alternative names
|
||||
#for alt in ['original_name', 'alternative_name']:
|
||||
#alt_name = toUnicode(show['alt))
|
||||
#if alt_name and not alt_name in show_data['titles'] and alt_name.lower() != 'none' and alt_name != None:
|
||||
#show_data['titles'].append(alt_name)
|
||||
# Add alternative titles
|
||||
try:
|
||||
raw = self.tvdb.search(show['seriesname'])
|
||||
if raw:
|
||||
for show_info in raw:
|
||||
if show_info['id'] == show_data['id'] and show_info.get('aliasnames', None):
|
||||
for alt_name in show_info['aliasnames'].split('|'):
|
||||
show_data['titles'].append(toUnicode(alt_name))
|
||||
except (tvdb_exceptions.tvdb_error, IOError), e:
|
||||
log.error('Failed searching TheTVDB for "%s": %s', (search_string, traceback.format_exc()))
|
||||
|
||||
return show_data
|
||||
|
||||
def parseSeason(self, show, season_tuple):
|
||||
def parseSeason(self, show, season_tuple):
|
||||
"""
|
||||
contains no data
|
||||
"""
|
||||
@@ -316,7 +321,7 @@ class TheTVDb(ShowProvider):
|
||||
season_data = dict((k, v) for k, v in season_data.iteritems() if v)
|
||||
return season_data
|
||||
|
||||
def parseEpisode(self, show, episode):
|
||||
def parseEpisode(self, show, episode):
|
||||
"""
|
||||
('episodenumber', u'1'),
|
||||
('thumb_added', None),
|
||||
|
||||
Reference in New Issue
Block a user