added posters for seasons

This commit is contained in:
Jason Mehring
2013-09-11 00:36:12 -04:00
parent a37a4a8cd4
commit e180addc3c
2 changed files with 70 additions and 74 deletions
@@ -135,23 +135,23 @@ class SeasonLibraryPlugin(LibraryBase):
db.commit()
# Files
#images = info.get('images', [])
#for image_type in ['poster']:
#for image in images.get(image_type, []):
#if not isinstance(image, (str, unicode)):
#continue
images = info.get('images', [])
for image_type in ['poster']:
for image in images.get(image_type, []):
if not isinstance(image, (str, unicode)):
continue
#file_path = fireEvent('file.download', url = image, single = True)
#if file_path:
#file_obj = fireEvent('file.add', path = file_path, type_tuple = ('image', image_type), single = True)
#try:
#file_obj = db.query(File).filter_by(id = file_obj.get('id')).one()
#library.files.append(file_obj)
#db.commit()
file_path = fireEvent('file.download', url = image, single = True)
if file_path:
file_obj = fireEvent('file.add', path = file_path, type_tuple = ('image', image_type), single = True)
try:
file_obj = db.query(File).filter_by(id = file_obj.get('id')).one()
library.files.append(file_obj)
db.commit()
#break
#except:
#log.debug('Failed to attach to library: %s', traceback.format_exc())
break
except:
log.debug('Failed to attach to library: %s', traceback.format_exc())
library_dict = library.to_dict(self.default_dict)
+55 -59
View File
@@ -11,12 +11,8 @@ import os
log = CPLog(__name__)
# TODO: Consider grabbing zips to put less strain on tvdb
# TODO: alternate titles do exist for show and episodes; add them
# TODO: Unicode stuff
# TODO: cwNotifyNotigy frontend on error (tvdb down at monent)
# TODO: Unicode stuff (check)
# TODO: Notigy frontend on error (tvdb down at monent)
# TODO: Expose apikey in setting so it can be changed by user
class TheTVDb(ShowProvider):
@@ -74,7 +70,7 @@ class TheTVDb(ShowProvider):
nr = 0
for show_info in raw:
show = self.tvdb[int(show_info['id'])]
results.append(self.parseShow(show))
results.append(self._parseShow(show))
nr += 1
if nr == limit:
break
@@ -109,7 +105,7 @@ class TheTVDb(ShowProvider):
show = self.getShow(identifier=identifier)
if show:
result = self.parseShow(show)
result = self._parseShow(show)
self.setCache(cache_key, result)
return result
@@ -142,11 +138,11 @@ class TheTVDb(ShowProvider):
result = []
for number, season in show.items():
if season_identifier is not None and number == season_identifier:
result = self.parseSeason(show, (number, season))
result = self._parseSeason(show, (number, season))
self.setCache(cache_key, result)
return result
else:
result.append(self.parseSeason(show, (number, season)))
result.append(self._parseSeason(show, (number, season)))
self.setCache(cache_key, result)
return result
@@ -185,43 +181,42 @@ class TheTVDb(ShowProvider):
for episode in season.values():
if episode_identifier is not None and episode['id'] == toUnicode(episode_identifier):
result = self.parseEpisode(show, episode)
result = self._parseEpisode(show, episode)
self.setCache(cache_key, result)
return result
else:
result.append(self.parseEpisode(show, episode))
result.append(self._parseEpisode(show, episode))
self.setCache(cache_key, result)
return result
def parseShow(self, show):
def _parseShow(self, show):
"""
show[74713] = {
'actors': u'|Bryan Cranston|Aaron Paul|Dean Norris|RJ Mitte|Betsy Brandt|Anna Gunn|Laura Fraser|Jesse Plemons|Christopher Cousins|Steven Michael Quezada|Jonathan Banks|Giancarlo Esposito|Bob Odenkirk|',
'added': None,
'addedby': None,
'airs_dayofweek': u'Sunday',
'airs_time': u'9:00 PM',
'banner': u'http://thetvdb.com/banners/graphical/81189-g13.jpg',
'contentrating': u'TV-MA',
'fanart': u'http://thetvdb.com/banners/fanart/original/81189-28.jpg',
'firstaired': u'2008-01-20',
'genre': u'|Crime|Drama|Suspense|',
'id': u'81189',
'imdb_id': u'tt0903747',
'language': u'en',
'lastupdated': u'1376620212',
'network': u'AMC',
'networkid': None,
'overview': u"Walter White, a struggling high school chemistry teacher is diagnosed with advanced lung cancer. He turns to a life of crime, producing and selling methamphetamine accompanied by a former student, Jesse Pinkman with the aim of securing his family's financial future before he dies.",
'poster': u'http://thetvdb.com/banners/posters/81189-22.jpg',
'rating': u'9.3',
'ratingcount': u'473',
'runtime': u'60',
'seriesid': u'74713',
'seriesname': u'Breaking Bad',
'status': u'Continuing',
'zap2it_id': u'SH01009396'}
'actors': u'|Bryan Cranston|Aaron Paul|Dean Norris|RJ Mitte|Betsy Brandt|Anna Gunn|Laura Fraser|Jesse Plemons|Christopher Cousins|Steven Michael Quezada|Jonathan Banks|Giancarlo Esposito|Bob Odenkirk|',
'added': None,
'addedby': None,
'airs_dayofweek': u'Sunday',
'airs_time': u'9:00 PM',
'banner': u'http://thetvdb.com/banners/graphical/81189-g13.jpg',
'contentrating': u'TV-MA',
'fanart': u'http://thetvdb.com/banners/fanart/original/81189-28.jpg',
'firstaired': u'2008-01-20',
'genre': u'|Crime|Drama|Suspense|',
'id': u'81189',
'imdb_id': u'tt0903747',
'language': u'en',
'lastupdated': u'1376620212',
'network': u'AMC',
'networkid': None,
'overview': u"Walter White, a struggling high school chemistry teacher is diagnosed with advanced lung cancer. He turns to a life of crime, producing and selling methamphetamine accompanied by a former student, Jesse Pinkman with the aim of securing his family's financial future before he dies.",
'poster': u'http://thetvdb.com/banners/posters/81189-22.jpg',
'rating': u'9.3',
'ratingcount': u'473',
'runtime': u'60',
'seriesid': u'74713',
'seriesname': u'Breaking Bad',
'status': u'Continuing',
'zap2it_id': u'SH01009396'
"""
# Make sure we have a valid show id, not '' or None
@@ -285,17 +280,25 @@ class TheTVDb(ShowProvider):
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()))
log.error('Failed searching TheTVDB for "%s": %s', (show['seriesname'], traceback.format_exc()))
return show_data
def parseSeason(self, show, season_tuple):
def _parseSeason(self, show, season_tuple):
"""
contains no data
"""
number, season = season_tuple
title = toUnicode('%s - Season %s' % (show['seriesname'], str(number)))
poster = []
try:
for id, data in show.data['_banners']['season']['season'].items():
if data.get('season', None) == str(number) and data['bannertype'] == 'season' and data['bannertype2'] == 'season':
poster.append(data.get('_bannerpath'))
break # Only really need one
except:
pass
# XXX: work on title; added defualt_title to fix an error
season_data = {
@@ -308,7 +311,7 @@ class TheTVDb(ShowProvider):
'parent_identifier': show['id'],
'seasonnumber': str(number),
'images': {
'poster': [],
'poster': poster,
'backdrop': [],
'poster_original': [],
'backdrop_original': [],
@@ -321,7 +324,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),
@@ -425,26 +428,19 @@ class TheTVDb(ShowProvider):
}
episode_data = dict((k, v) for k, v in episode_data.iteritems() if v)
## Add alternative names
#for alt in ['original_name', 'alternative_name']:
#alt_name = toUnicode(episode['alt))
#if alt_name and not alt_name in episode_data['titles'] and alt_name.lower() != 'none' and alt_name != None:
#episode_data['titles'].append(alt_name)
return episode_data
def getImage(self, show, type = 'poster', size = 'cover'):
""""""
# XXX: Need to implement size
image_url = ''
#def getImage(self, show, type = 'poster', size = 'cover'):
#""""""
## XXX: Need to implement size
#image_url = ''
for res, res_data in show['_banners'].get(type, {}).items():
for bid, banner_info in res_data.items():
image_url = banner_info.get('_bannerpath', '')
break
#for res, res_data in show['_banners'].get(type, {}).items():
#for bid, banner_info in res_data.items():
#image_url = banner_info.get('_bannerpath', '')
#break
return image_url
#return image_url
def isDisabled(self):
if self.conf('api_key') == '':