Add show updated
This commit is contained in:
1 parent
b13b32952f
commit
0a0a1704be
5 files changed
+166
-188
No files matched your search
@@ -86,7 +86,8 @@ class ShowBase(MediaBase):
|
|||||||
# Can we make a base function to do this stuff?
|
# Can we make a base function to do this stuff?
|
||||||
|
|
||||||
# Remove season info for later use (save separately)
|
# Remove season info for later use (save separately)
|
||||||
season_info = info.get('seasons', {})
|
seasons_info = info.get('seasons', {})
|
||||||
|
identifiers = info.get('identifiers', {})
|
||||||
|
|
||||||
# Make sure we don't nest in_wanted data
|
# Make sure we don't nest in_wanted data
|
||||||
del info['identifiers']
|
del info['identifiers']
|
||||||
@@ -103,7 +104,7 @@ class ShowBase(MediaBase):
|
|||||||
|
|
||||||
new = False
|
new = False
|
||||||
try:
|
try:
|
||||||
m = db.run('media', 'identifiers', params.get('identifiers'), with_doc = True)['doc']
|
m = fireEvent('media.with_identifiers', params.get('identifiers'), with_doc = True, single = True)['doc']
|
||||||
except:
|
except:
|
||||||
new = True
|
new = True
|
||||||
m = db.insert(media)
|
m = db.insert(media)
|
||||||
@@ -124,7 +125,7 @@ class ShowBase(MediaBase):
|
|||||||
elif force_readd:
|
elif force_readd:
|
||||||
|
|
||||||
# Clean snatched history
|
# Clean snatched history
|
||||||
for release in db.run('release', 'for_media', m['_id']):
|
for release in fireEvent('release.for_media', m['_id'], single = True):
|
||||||
if release.get('status') in ['downloaded', 'snatched', 'done']:
|
if release.get('status') in ['downloaded', 'snatched', 'done']:
|
||||||
if params.get('ignore_previous', False):
|
if params.get('ignore_previous', False):
|
||||||
release['status'] = 'ignored'
|
release['status'] = 'ignored'
|
||||||
@@ -147,19 +148,32 @@ class ShowBase(MediaBase):
|
|||||||
# Trigger update info
|
# Trigger update info
|
||||||
if added and update_after:
|
if added and update_after:
|
||||||
# Do full update to get images etc
|
# Do full update to get images etc
|
||||||
fireEventAsync('show.update_info', m['_id'], on_complete = onComplete)
|
fireEventAsync('show.update_info', m['_id'], info = info, on_complete = onComplete)
|
||||||
|
|
||||||
# Remove releases
|
# Remove releases
|
||||||
for rel in db.run('release', 'for_media', m['_id']):
|
for rel in fireEvent('release.for_media', m['_id'], single = True):
|
||||||
if rel['status'] is 'available':
|
if rel['status'] is 'available':
|
||||||
db.delete(rel)
|
db.delete(rel)
|
||||||
|
|
||||||
movie_dict = db.run('media', 'to_dict', m['_id'])
|
movie_dict = fireEvent('media.get', m['_id'], single = True)
|
||||||
|
|
||||||
if do_search and search_after:
|
if do_search and search_after:
|
||||||
onComplete = self.createOnComplete(m['_id'])
|
onComplete = self.createOnComplete(m['_id'])
|
||||||
onComplete()
|
onComplete()
|
||||||
|
|
||||||
|
# Add Seasons
|
||||||
|
for season_nr in seasons_info:
|
||||||
|
|
||||||
|
season_info = seasons_info[season_nr]
|
||||||
|
season = fireEvent('show.season.add', media.get('_id'), season_info, single = True)
|
||||||
|
|
||||||
|
# Add Episodes
|
||||||
|
for episode_nr in season_info.get('episodes', {}):
|
||||||
|
|
||||||
|
episode_info = season_info['episodes'][episode_nr]
|
||||||
|
fireEvent('show.episode.add', season.get('_id'), episode_info, single = True)
|
||||||
|
|
||||||
|
|
||||||
if added and notify_after:
|
if added and notify_after:
|
||||||
|
|
||||||
if params.get('title'):
|
if params.get('title'):
|
||||||
@@ -170,22 +184,17 @@ class ShowBase(MediaBase):
|
|||||||
message = 'Successfully added "%s" to your wanted list.' % title
|
message = 'Successfully added "%s" to your wanted list.' % title
|
||||||
else:
|
else:
|
||||||
message = 'Successfully added to your wanted list.'
|
message = 'Successfully added to your wanted list.'
|
||||||
fireEvent('notify.frontend', type = 'movie.added', data = movie_dict, message = message)
|
fireEvent('notify.frontend', type = 'show.added', data = movie_dict, message = message)
|
||||||
|
|
||||||
|
|
||||||
return movie_dict
|
return movie_dict
|
||||||
except:
|
except:
|
||||||
log.error('Failed adding media: %s', traceback.format_exc())
|
log.error('Failed adding media: %s', traceback.format_exc())
|
||||||
|
|
||||||
# Add Seasons
|
def updateInfo(self, media_id = None, identifiers = None, info = None):
|
||||||
for season_info in info.get('seasons', []):
|
if not info: info = {}
|
||||||
|
if not identifiers: identifiers = {}
|
||||||
|
|
||||||
season = fireEvent('show.season.add', media.get('_id'), season_info)
|
|
||||||
|
|
||||||
for episode_info in season_info.get('seasons', []):
|
|
||||||
|
|
||||||
fireEvent('show.episode.add', season.get('_id'), episode_info)
|
|
||||||
|
|
||||||
def updateInfo(self, media_id = None, identifiers = None):
|
|
||||||
"""
|
"""
|
||||||
Update movie information inside media['doc']['info']
|
Update movie information inside media['doc']['info']
|
||||||
|
|
||||||
@@ -211,9 +220,14 @@ class ShowBase(MediaBase):
|
|||||||
else:
|
else:
|
||||||
media = db.get('media', identifiers, with_doc = True)['doc']
|
media = db.get('media', identifiers, with_doc = True)['doc']
|
||||||
|
|
||||||
info = fireEvent('show.info', identifiers = media.get('identifiers'), merge = True)
|
if not info:
|
||||||
|
info = fireEvent('show.info', identifiers = media.get('identifiers'), merge = True)
|
||||||
|
|
||||||
# Don't need those here
|
# Don't need those here
|
||||||
|
try: del info['seasons']
|
||||||
|
except: pass
|
||||||
|
try: del info['identifiers']
|
||||||
|
except: pass
|
||||||
try: del info['in_wanted']
|
try: del info['in_wanted']
|
||||||
except: pass
|
except: pass
|
||||||
try: del info['in_library']
|
try: del info['in_library']
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
from couchpotato.core.event import addEvent, fireEvent
|
from couchpotato import get_db
|
||||||
|
from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
|
||||||
from couchpotato.core.helpers.encoding import toUnicode
|
from couchpotato.core.helpers.encoding import toUnicode
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.helpers.variable import tryInt
|
from couchpotato.core.helpers.variable import tryInt
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.media import MediaBase
|
||||||
|
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
autload = 'Episode'
|
autoload = 'Episode'
|
||||||
|
|
||||||
class Episode(Plugin):
|
class Episode(MediaBase):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
addEvent('media.search_query', self.query)
|
addEvent('media.search_query', self.query)
|
||||||
@@ -18,53 +19,72 @@ class Episode(Plugin):
|
|||||||
addEvent('show.episode.add', self.add)
|
addEvent('show.episode.add', self.add)
|
||||||
addEvent('show.episode.update_info', self.updateInfo)
|
addEvent('show.episode.update_info', self.updateInfo)
|
||||||
|
|
||||||
def add(self, parent_id, update_after = True):
|
def add(self, parent_id, info = None, update_after = True):
|
||||||
|
if not info: info = {}
|
||||||
|
|
||||||
|
identifiers = info.get('identifiers')
|
||||||
|
try: del info['identifiers']
|
||||||
|
except: pass
|
||||||
|
|
||||||
# Add Season
|
# Add Season
|
||||||
season = {
|
episode_info = {
|
||||||
'_t': 'media',
|
'_t': 'media',
|
||||||
'type': 'episode',
|
'type': 'episode',
|
||||||
'nr': 1,
|
'identifiers': identifiers,
|
||||||
'identifiers': {
|
'parent': parent_id,
|
||||||
'imdb': 'tt1234',
|
'info': info, # Returned dict by providers
|
||||||
'thetvdb': 123,
|
|
||||||
'tmdb': 123,
|
|
||||||
'rage': 123
|
|
||||||
},
|
|
||||||
'parent': '_id',
|
|
||||||
'info': {}, # Returned dict by providers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
episode_exists = True or False
|
# Check if season already exists
|
||||||
|
existing_episode = fireEvent('media.with_identifiers', identifiers, with_doc = True, single = True)
|
||||||
|
|
||||||
if episode_exists:
|
db = get_db()
|
||||||
pass #update existing
|
|
||||||
|
if existing_episode:
|
||||||
|
s = existing_episode['doc']
|
||||||
|
s.update(episode_info)
|
||||||
|
episode = db.update(s)
|
||||||
else:
|
else:
|
||||||
pass # Add Episode
|
episode = db.insert(episode_info)
|
||||||
|
|
||||||
|
|
||||||
# Update library info
|
# Update library info
|
||||||
if update_after is not False:
|
if update_after is not False:
|
||||||
handle = fireEventAsync if update_after is 'async' else fireEvent
|
handle = fireEventAsync if update_after is 'async' else fireEvent
|
||||||
handle('show.episode.update_info', season.get('_id'), default_title = toUnicode(attrs.get('title', '')))
|
handle('show.season.update_info', episode.get('_id'), info = info, single = True)
|
||||||
|
|
||||||
return season
|
return episode
|
||||||
|
|
||||||
def updateInfo(self, media_id = None, default_title = '', force = False):
|
def update_info(self, media_id = None, info = None, force = False):
|
||||||
|
if not info: info = {}
|
||||||
|
|
||||||
if self.shuttingDown():
|
if self.shuttingDown():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
db = get_db()
|
||||||
|
|
||||||
|
episode = db.get('id', media_id)
|
||||||
|
|
||||||
# Get new info
|
# Get new info
|
||||||
fireEvent('episode.info', merge = True)
|
if not info:
|
||||||
|
info = fireEvent('episode.info', episode.get('identifiers'), merge = True)
|
||||||
|
|
||||||
# Update/create media
|
# Update/create media
|
||||||
|
if force:
|
||||||
|
|
||||||
|
episode['identifiers'].update(info['identifiers'])
|
||||||
|
if 'identifiers' in info:
|
||||||
|
del info['identifiers']
|
||||||
|
|
||||||
|
episode.update({'info': info})
|
||||||
|
e = db.update(episode)
|
||||||
|
episode.update(e)
|
||||||
|
|
||||||
# Get images
|
# Get images
|
||||||
|
image_urls = info.get('images', [])
|
||||||
|
existing_files = episode.get('files', {})
|
||||||
|
self.getPoster(image_urls, existing_files)
|
||||||
|
|
||||||
|
return episode
|
||||||
return info
|
|
||||||
|
|
||||||
def query(self, library, first = True, condense = True, include_identifier = True, **kwargs):
|
def query(self, library, first = True, condense = True, include_identifier = True, **kwargs):
|
||||||
if library is list or library.get('type') != 'episode':
|
if library is list or library.get('type') != 'episode':
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ class TheTVDb(ShowProvider):
|
|||||||
identifier = tryInt(identifiers.get('thetvdb'))
|
identifier = tryInt(identifiers.get('thetvdb'))
|
||||||
|
|
||||||
cache_key = 'thetvdb.cache.show.%s' % identifier
|
cache_key = 'thetvdb.cache.show.%s' % identifier
|
||||||
result = self.getCache(cache_key)
|
result = None #self.getCache(cache_key)
|
||||||
if result:
|
if result:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -253,15 +253,13 @@ class TheTVDb(ShowProvider):
|
|||||||
'network': get('network'),
|
'network': get('network'),
|
||||||
'plot': get('overview'),
|
'plot': get('overview'),
|
||||||
'networkid': get('networkid'),
|
'networkid': get('networkid'),
|
||||||
'airs_dayofweek': get('airs_dayofweek'),
|
'air_day': (get('airs_dayofweek') or '').lower(),
|
||||||
'airs_time': get('airs_time'),
|
'air_time': self.parseTime(get('airs_time')),
|
||||||
'firstaired': get('firstaired'),
|
'firstaired': get('firstaired'),
|
||||||
'released': get('firstaired'),
|
'runtime': tryInt(get('runtime')),
|
||||||
'runtime': get('runtime'),
|
|
||||||
'contentrating': get('contentrating'),
|
'contentrating': get('contentrating'),
|
||||||
'rating': {},
|
'rating': {},
|
||||||
'actors': splitString(get('actors'), '|'),
|
'actors': splitString(get('actors'), '|'),
|
||||||
'lastupdated': get('lastupdated'),
|
|
||||||
'status': get('status'),
|
'status': get('status'),
|
||||||
'language': get('language'),
|
'language': get('language'),
|
||||||
}
|
}
|
||||||
@@ -272,21 +270,16 @@ 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)
|
||||||
|
|
||||||
# Parse season and episode data
|
# Parse season and episode data
|
||||||
seasons = {}
|
show_data['seasons'] = {}
|
||||||
episodes = get('episodes')
|
|
||||||
if episodes:
|
|
||||||
for episode in episodes:
|
|
||||||
episode_nr = episode.get('nr')
|
|
||||||
episode_season = episode.get('season')
|
|
||||||
|
|
||||||
# Create season
|
for season_nr in show:
|
||||||
if seasons.get(episode_season):
|
season = self._parseSeason(show, season_nr, show[season_nr])
|
||||||
seasons[episode_season] = {
|
season['episodes'] = {}
|
||||||
'episodes': {}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add episode information
|
for episode_nr in show[season_nr]:
|
||||||
seasons[episode_season]['episodes'][episode_nr] = self._parseEpisode(show, episode)
|
season['episodes'][episode_nr] = self._parseEpisode(show[season_nr][episode_nr])
|
||||||
|
|
||||||
|
show_data['seasons'][season_nr] = season
|
||||||
|
|
||||||
# Add alternative titles
|
# Add alternative titles
|
||||||
# try:
|
# try:
|
||||||
@@ -302,52 +295,36 @@ class TheTVDb(ShowProvider):
|
|||||||
|
|
||||||
return show_data
|
return show_data
|
||||||
|
|
||||||
def _parseSeason(self, show, season_tuple):
|
def _parseSeason(self, show, number, season):
|
||||||
"""
|
"""
|
||||||
contains no data
|
contains no data
|
||||||
"""
|
"""
|
||||||
|
|
||||||
number, season = season_tuple
|
|
||||||
title = toUnicode('%s - Season %s' % (show['seriesname'] or u'', str(number)))
|
|
||||||
poster = []
|
poster = []
|
||||||
try:
|
try:
|
||||||
|
temp_poster = {}
|
||||||
for id, data in show.data['_banners']['season']['season'].items():
|
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':
|
if data.get('season') == str(number) and data.get('language') == self.tvdb_api_parms['language']:
|
||||||
poster.append(data.get('_bannerpath'))
|
temp_poster[tryFloat(data.get('rating')) * tryInt(data.get('ratingcount'))] = data.get('_bannerpath')
|
||||||
break # Only really need one
|
#break
|
||||||
|
poster.append(temp_poster[sorted(temp_poster, reverse = True)[0]])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
|
||||||
id = (show['id'] + ':' + str(number))
|
|
||||||
except:
|
|
||||||
id = None
|
|
||||||
|
|
||||||
# XXX: work on title; added defualt_title to fix an error
|
|
||||||
season_data = {
|
season_data = {
|
||||||
'id': id,
|
'identifiers': {
|
||||||
'type': 'season',
|
'thetvdb': show[number][1]['seasonid']
|
||||||
'primary_provider': 'thetvdb',
|
},
|
||||||
'titles': [title, ],
|
'number': number,
|
||||||
'original_title': title,
|
|
||||||
'via_thetvdb': True,
|
|
||||||
'parent_identifier': show['id'] or None,
|
|
||||||
'seasonnumber': str(number),
|
|
||||||
'images': {
|
'images': {
|
||||||
'poster': poster,
|
'poster': poster,
|
||||||
'backdrop': [],
|
|
||||||
'poster_original': [],
|
|
||||||
'backdrop_original': [],
|
|
||||||
},
|
},
|
||||||
'year': None,
|
|
||||||
'genres': None,
|
|
||||||
'imdb': None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, episode):
|
||||||
"""
|
"""
|
||||||
('episodenumber', u'1'),
|
('episodenumber', u'1'),
|
||||||
('thumb_added', None),
|
('thumb_added', None),
|
||||||
@@ -383,86 +360,36 @@ class TheTVDb(ShowProvider):
|
|||||||
('episodename', u'Pilot')]
|
('episodename', u'Pilot')]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
poster = episode.get('filename', [])
|
def get(name, default = None):
|
||||||
backdrop = []
|
return episode.get(name, default)
|
||||||
genres = []
|
|
||||||
plot = "%s - %sx%s - %s" % (show['seriesname'] or u'',
|
|
||||||
episode.get('seasonnumber', u'?'),
|
|
||||||
episode.get('episodenumber', u'?'),
|
|
||||||
episode.get('overview', u''))
|
|
||||||
if episode.get('firstaired', None) is not None:
|
|
||||||
try: year = datetime.strptime(episode['firstaired'], '%Y-%m-%d').year
|
|
||||||
except: year = None
|
|
||||||
else:
|
|
||||||
year = None
|
|
||||||
|
|
||||||
try:
|
poster = get('filename', [])
|
||||||
id = int(episode['id'])
|
|
||||||
except:
|
|
||||||
id = None
|
|
||||||
|
|
||||||
episode_data = {
|
episode_data = {
|
||||||
'id': id,
|
'number': get('episodenumber'),
|
||||||
|
'absolute_number': get('absolute_number'),
|
||||||
|
'identifiers': {
|
||||||
|
'thetvdb': tryInt(episode['id'])
|
||||||
|
},
|
||||||
'type': 'episode',
|
'type': 'episode',
|
||||||
'primary_provider': 'thetvdb',
|
'titles': [get('episodename')] if get('episodename') else [],
|
||||||
'via_thetvdb': True,
|
|
||||||
'thetvdb_id': id,
|
|
||||||
'titles': [episode.get('episodename', u''), ],
|
|
||||||
'original_title': episode.get('episodename', u'') ,
|
|
||||||
'images': {
|
'images': {
|
||||||
'poster': [poster] if poster else [],
|
'poster': [poster] if poster else [],
|
||||||
'backdrop': [backdrop] if backdrop else [],
|
|
||||||
'poster_original': [],
|
|
||||||
'backdrop_original': [],
|
|
||||||
},
|
},
|
||||||
'imdb': episode.get('imdb_id', None),
|
'released': get('firstaired'),
|
||||||
'runtime': None,
|
'plot': get('overview'),
|
||||||
'released': episode.get('firstaired', None),
|
'firstaired': get('firstaired'),
|
||||||
'year': year,
|
'language': get('language'),
|
||||||
'plot': plot,
|
|
||||||
'genres': genres,
|
|
||||||
'parent_identifier': show['id'] or None,
|
|
||||||
'seasonnumber': episode.get('seasonnumber', None),
|
|
||||||
'episodenumber': episode.get('episodenumber', None),
|
|
||||||
'combined_episodenumber': episode.get('combined_episodenumber', None),
|
|
||||||
'absolute_number': episode.get('absolute_number', None),
|
|
||||||
'combined_season': episode.get('combined_season', None),
|
|
||||||
'productioncode': episode.get('productioncode', None),
|
|
||||||
'seriesid': episode.get('seriesid', None),
|
|
||||||
'seasonid': episode.get('seasonid', None),
|
|
||||||
'firstaired': episode.get('firstaired', None),
|
|
||||||
'thumb_added': episode.get('thumb_added', None),
|
|
||||||
'thumb_height': episode.get('thumb_height', None),
|
|
||||||
'thumb_width': episode.get('thumb_width', None),
|
|
||||||
'rating': episode.get('rating', None),
|
|
||||||
'ratingcount': episode.get('ratingcount', None),
|
|
||||||
'epimgflag': episode.get('epimgflag', None),
|
|
||||||
'dvd_episodenumber': episode.get('dvd_episodenumber', None),
|
|
||||||
'dvd_discid': episode.get('dvd_discid', None),
|
|
||||||
'dvd_chapter': episode.get('dvd_chapter', None),
|
|
||||||
'dvd_season': episode.get('dvd_season', None),
|
|
||||||
'tms_export': episode.get('tms_export', None),
|
|
||||||
'writer': episode.get('writer', None),
|
|
||||||
'director': episode.get('director', None),
|
|
||||||
'gueststars': episode.get('gueststars', None),
|
|
||||||
'lastupdated': episode.get('lastupdated', None),
|
|
||||||
'language': episode.get('language', None),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if get('imdb_id'):
|
||||||
|
episode_data['identifiers']['imdb'] = get('imdb_id')
|
||||||
|
|
||||||
episode_data = dict((k, v) for k, v in episode_data.iteritems() if v)
|
episode_data = dict((k, v) for k, v in episode_data.iteritems() if v)
|
||||||
return episode_data
|
return episode_data
|
||||||
|
|
||||||
#def getImage(self, show, type = 'poster', size = 'cover'):
|
def parseTime(self, time):
|
||||||
#""""""
|
return time
|
||||||
## 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
|
|
||||||
|
|
||||||
#return image_url
|
|
||||||
|
|
||||||
def isDisabled(self):
|
def isDisabled(self):
|
||||||
if self.conf('api_key') == '':
|
if self.conf('api_key') == '':
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from couchpotato import Env, get_session
|
from couchpotato import Env
|
||||||
from couchpotato.core.event import addEvent, fireEvent
|
from couchpotato.core.event import addEvent, fireEvent
|
||||||
from couchpotato.core.helpers.variable import getTitle, toIterable
|
from couchpotato.core.helpers.variable import getTitle, toIterable
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
@@ -31,8 +31,6 @@ class ShowSearcher(SearcherBase, ShowTypeBase):
|
|||||||
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'])
|
show, season, episode = self.getLibraries(media['library'])
|
||||||
|
|
||||||
db = get_session()
|
|
||||||
|
|
||||||
if media['type'] == 'show':
|
if media['type'] == 'show':
|
||||||
for library in season:
|
for library in season:
|
||||||
# TODO ideally we shouldn't need to fetch the media for each season library here
|
# TODO ideally we shouldn't need to fetch the media for each season library here
|
||||||
|
|||||||
@@ -1,71 +1,90 @@
|
|||||||
from couchpotato.core.event import addEvent, fireEvent
|
from couchpotato import get_db
|
||||||
|
from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.helpers.variable import tryInt
|
from couchpotato.core.helpers.variable import tryInt
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.media import MediaBase
|
||||||
|
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
autload = 'Season'
|
autoload = 'Season'
|
||||||
|
|
||||||
|
|
||||||
class Season(Plugin):
|
class Season(MediaBase):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
addEvent('media.search_query', self.query)
|
addEvent('media.search_query', self.query)
|
||||||
addEvent('media.identifier', self.identifier)
|
addEvent('media.identifier', self.identifier)
|
||||||
|
|
||||||
addEvent('show.season.add', self.update)
|
addEvent('show.season.add', self.add)
|
||||||
addEvent('show.season.update_info', self.update)
|
addEvent('show.season.update_info', self.update_info)
|
||||||
|
|
||||||
def add(self, parent_id, update_after = True):
|
def add(self, parent_id, info = None, update_after = True):
|
||||||
|
if not info: info = {}
|
||||||
|
|
||||||
|
identifiers = info.get('identifiers')
|
||||||
|
try: del info['identifiers']
|
||||||
|
except: pass
|
||||||
|
|
||||||
# Add Season
|
# Add Season
|
||||||
season = {
|
season_info = {
|
||||||
'_t': 'media',
|
'_t': 'media',
|
||||||
'type': 'season',
|
'type': 'season',
|
||||||
'nr': 1,
|
'identifiers': identifiers,
|
||||||
'identifiers': {
|
'parent': parent_id,
|
||||||
'imdb': 'tt1234',
|
'info': info, # Returned dict by providers
|
||||||
'thetvdb': 123,
|
|
||||||
'tmdb': 123,
|
|
||||||
'rage': 123
|
|
||||||
},
|
|
||||||
'parent': '_id',
|
|
||||||
'info': {}, # Returned dict by providers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if season already exists
|
# Check if season already exists
|
||||||
season_exists = True or False
|
existing_season = fireEvent('media.with_identifiers', identifiers, with_doc = True, single = True)
|
||||||
|
|
||||||
if season_exists:
|
db = get_db()
|
||||||
pass #update existing
|
|
||||||
|
if existing_season:
|
||||||
|
s = existing_season['doc']
|
||||||
|
s.update(season_info)
|
||||||
|
season = db.update(s)
|
||||||
else:
|
else:
|
||||||
|
season = db.insert(season_info)
|
||||||
db.insert(season)
|
|
||||||
|
|
||||||
|
|
||||||
# Update library info
|
# Update library info
|
||||||
if update_after is not False:
|
if update_after is not False:
|
||||||
handle = fireEventAsync if update_after is 'async' else fireEvent
|
handle = fireEventAsync if update_after is 'async' else fireEvent
|
||||||
handle('show.season.update_info', episode.get('_id'))
|
handle('show.season.update_info', season.get('_id'), info = info, single = True)
|
||||||
|
|
||||||
return season
|
return season
|
||||||
|
|
||||||
def update_info(self, media_id = None, default_title = '', force = False):
|
def update_info(self, media_id = None, info = None, force = False):
|
||||||
|
if not info: info = {}
|
||||||
|
|
||||||
if self.shuttingDown():
|
if self.shuttingDown():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
db = get_db()
|
||||||
|
|
||||||
|
season = db.get('id', media_id)
|
||||||
|
|
||||||
# Get new info
|
# Get new info
|
||||||
fireEvent('season.info', merge = True)
|
if not info:
|
||||||
|
info = fireEvent('season.info', season.get('identifiers'), merge = True)
|
||||||
|
|
||||||
# Update/create media
|
# Update/create media
|
||||||
|
if force:
|
||||||
|
|
||||||
|
season['identifiers'].update(info['identifiers'])
|
||||||
|
if 'identifiers' in info:
|
||||||
|
del info['identifiers']
|
||||||
|
|
||||||
|
season.update({'info': info})
|
||||||
|
s = db.update(season)
|
||||||
|
season.update(s)
|
||||||
|
|
||||||
# Get images
|
# Get images
|
||||||
|
image_urls = info.get('images', [])
|
||||||
|
existing_files = season.get('files', {})
|
||||||
|
self.getPoster(image_urls, existing_files)
|
||||||
|
|
||||||
|
return season
|
||||||
return info
|
|
||||||
|
|
||||||
def query(self, library, first = True, condense = True, include_identifier = True, **kwargs):
|
def query(self, library, first = True, condense = True, include_identifier = True, **kwargs):
|
||||||
if library is list or library.get('type') != 'season':
|
if library is list or library.get('type') != 'season':
|
||||||
|
|||||||
Reference in new issue
Block a user