Browse Source

thetvdb, add alternate titles if they exist

pull/2139/head
Jason Mehring 12 years ago
parent
commit
a37a4a8cd4
  1. 27
      couchpotato/core/media/show/_base/main.py
  2. 65
      couchpotato/core/providers/info/thetvdb/main.py

27
couchpotato/core/media/show/_base/main.py

@ -54,12 +54,10 @@ class ShowBase(MediaBase):
addEvent('show.add', self.add) addEvent('show.add', self.add)
def search(self, q = '', **kwargs): def search(self, q = '', **kwargs):
cache_key = u'%s/%s' % (__name__, simplifyString(q)) cache_key = u'%s/%s' % (__name__, simplifyString(q))
shows = Env.get('cache').get(cache_key) shows = Env.get('cache').get(cache_key)
if not shows: if not shows:
if getImdb(q): if getImdb(q):
shows = [fireEvent('show.info', identifier = q, merge = True)] shows = [fireEvent('show.info', identifier = q, merge = True)]
else: else:
@ -73,7 +71,6 @@ class ShowBase(MediaBase):
} }
def addView(self, **kwargs): def addView(self, **kwargs):
movie_dict = fireEvent('show.add', params=kwargs) # XXX: Temp added so we can catch a breakpoint movie_dict = fireEvent('show.add', params=kwargs) # XXX: Temp added so we can catch a breakpoint
#movie_dict = self.add(params = kwargs) #movie_dict = self.add(params = kwargs)
@ -83,26 +80,6 @@ class ShowBase(MediaBase):
'movie': movie_dict, '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): def add(self, params = {}, force_readd = True, search_after = True, update_library = False, status_id = None):
""" """
1. Add Show 1. Add Show
@ -125,11 +102,10 @@ class ShowBase(MediaBase):
log.debug("show.add") log.debug("show.add")
# Add show parent to db first # Add show parent to db first
parent = self.addToDatabase(params = params, type = 'show') parent = self.addToDatabase(params = params, type = 'show')
identifier = params.get('id') identifier = params.get('id')
# XXX: add seasons
# XXX: Fix so we dont have a nested list [0] (fireEvent) # XXX: Fix so we dont have a nested list [0] (fireEvent)
try: try:
seasons = fireEvent('season.info', identifier = identifier)[0] seasons = fireEvent('season.info', identifier = identifier)[0]
@ -156,7 +132,6 @@ class ShowBase(MediaBase):
episode['parent_identifier'] = season['identifier'] episode['parent_identifier'] = season['identifier']
self.addToDatabase(params=episode, type = "episode") self.addToDatabase(params=episode, type = "episode")
#self.debug(str(identifier)) # XXX: Remove DEBUG only
return parent return parent
def addToDatabase(self, params = {}, type="show", force_readd = True, search_after = True, update_library = False, status_id = None): def addToDatabase(self, params = {}, type="show", force_readd = True, search_after = True, update_library = False, status_id = None):

65
couchpotato/core/providers/info/thetvdb/main.py

@ -72,8 +72,8 @@ class TheTVDb(ShowProvider):
if raw: if raw:
try: try:
nr = 0 nr = 0
for show in raw: for show_info in raw:
show = self.tvdb[int(show['id'])] show = self.tvdb[int(show_info['id'])]
results.append(self.parseShow(show)) results.append(self.parseShow(show))
nr += 1 nr += 1
if nr == limit: if nr == limit:
@ -97,6 +97,23 @@ class TheTVDb(ShowProvider):
return show 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): def getSeasonInfo(self, identifier=None, season_identifier=None):
"""Either return a list of all seasons or a single season by number. """Either return a list of all seasons or a single season by number.
identifier is the show 'id' identifier is the show 'id'
@ -177,23 +194,6 @@ class TheTVDb(ShowProvider):
self.setCache(cache_key, result) self.setCache(cache_key, result)
return 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): def parseShow(self, show):
""" """
show[74713] = { show[74713] = {
@ -229,10 +229,10 @@ class TheTVDb(ShowProvider):
# return None # return None
## Images ## Images
poster = self.getImage(show, type = 'poster', size = 'cover') poster = show['poster']
backdrop = self.getImage(show, type = 'fanart', size = 'w1280') backdrop = show['fanart']
#poster_original = self.getImage(show, type = 'poster', size = 'original') #poster = self.getImage(show, type = 'poster', size = 'cover')
#backdrop_original = self.getImage(show, type = 'backdrop', size = 'original') #backdrop = self.getImage(show, type = 'fanart', size = 'w1280')
genres = [] if show['genre'] is None else show['genre'].strip('|').split('|') genres = [] if show['genre'] is None else show['genre'].strip('|').split('|')
if show['firstaired'] is not None: 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) show_data = dict((k, v) for k, v in show_data.iteritems() if v)
## Add alternative names # Add alternative titles
#for alt in ['original_name', 'alternative_name']: try:
#alt_name = toUnicode(show['alt)) raw = self.tvdb.search(show['seriesname'])
#if alt_name and not alt_name in show_data['titles'] and alt_name.lower() != 'none' and alt_name != None: if raw:
#show_data['titles'].append(alt_name) 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 return show_data
def parseSeason(self, show, season_tuple): def parseSeason(self, show, season_tuple):
""" """
contains no data contains no data
""" """
@ -316,7 +321,7 @@ class TheTVDb(ShowProvider):
season_data = dict((k, v) for k, v in season_data.iteritems() if v) season_data = dict((k, v) for k, v in season_data.iteritems() if v)
return season_data return season_data
def parseEpisode(self, show, episode): def parseEpisode(self, show, episode):
""" """
('episodenumber', u'1'), ('episodenumber', u'1'),
('thumb_added', None), ('thumb_added', None),

Loading…
Cancel
Save