def add(self, attrs={}, update_after=True): db = get_session() l = db.query(Library).filter_by( identifier=attrs.get('identifier')).first() if not l: status = fireEvent('status.get', 'needs_update', single=True) l = Library(year=attrs.get('year'), identifier=attrs.get('identifier'), plot=attrs.get('plot'), tagline=attrs.get('tagline'), status_id=status.get('id')) title = LibraryTitle(title=attrs.get('title')) l.titles.append(title) db.add(l) db.commit() # Update library info if update_after: fireEventAsync('library.update', identifier=l.identifier, default_title=attrs.get('title', '')) return l.to_dict(self.default_dict)
def add(self, attrs={}, update_after=True): db = get_session() l = db.query(Library).filter_by( identifier=attrs.get('identifier')).first() if not l: status = fireEvent('status.get', 'needs_update', single=True) l = Library(year=attrs.get('year'), identifier=attrs.get('identifier'), plot=toUnicode(attrs.get('plot')), tagline=toUnicode(attrs.get('tagline')), status_id=status.get('id')) title = LibraryTitle(title=toUnicode(attrs.get('title')), simple_title=self.simplifyTitle( attrs.get('title'))) l.titles.append(title) db.add(l) db.commit() # Update library info if update_after is not False: handle = fireEventAsync if update_after is 'async' else fireEvent handle('library.update', identifier=l.identifier, default_title=toUnicode(attrs.get('title', ''))) library_dict = l.to_dict(self.default_dict) return library_dict
def add(self, attrs={}): db = get_session() l = db.query(Library).filter_by( identifier=attrs.get('identifier')).first() if not l: l = Library(year=attrs.get('year'), identifier=attrs.get('identifier'), plot=attrs.get('plot'), tagline=attrs.get('tagline')) title = LibraryTitle(title=attrs.get('title')) l.titles.append(title) db.add(l) db.commit() # Update library info fireEventAsync('library.update', library=l, default_title=attrs.get('title', '')) #db.remove() return l
def add(self, attrs={}, update_after=True): type = attrs.get('type', 'season') primary_provider = attrs.get('primary_provider', 'thetvdb') db = get_session() parent_identifier = attrs.get('parent_identifier', None) parent = None if parent_identifier: parent = db.query(ShowLibrary).filter_by( primary_provider=primary_provider, identifier=attrs.get('parent_identifier')).first() l = db.query(SeasonLibrary).filter_by( type=type, identifier=attrs.get('identifier')).first() if not l: status = fireEvent('status.get', 'needs_update', single=True) l = SeasonLibrary( type=type, primary_provider=primary_provider, year=attrs.get('year'), identifier=attrs.get('identifier'), plot=toUnicode(attrs.get('plot')), tagline=toUnicode(attrs.get('tagline')), status_id=status.get('id'), info={}, parent=parent, ) title = LibraryTitle( title=toUnicode(attrs.get('title')), simple_title=self.simplifyTitle(attrs.get('title')), ) l.titles.append(title) db.add(l) db.commit() # Update library info if update_after is not False: handle = fireEventAsync if update_after is 'async' else fireEvent handle('library.update.season', identifier=l.identifier, default_title=toUnicode(attrs.get('title', ''))) library_dict = l.to_dict(self.default_dict) db.expire_all() return library_dict
def add(self, attrs=None, update_after=True): if not attrs: attrs = {} primary_provider = attrs.get('primary_provider', 'imdb') try: db = get_session() l = db.query(Library).filter_by( identifier=attrs.get('identifier')).first() if not l: status = fireEvent('status.get', 'needs_update', single=True) l = Library(year=attrs.get('year'), identifier=attrs.get('identifier'), plot=toUnicode(attrs.get('plot')), tagline=toUnicode(attrs.get('tagline')), status_id=status.get('id'), info={}) title = LibraryTitle( title=toUnicode(attrs.get('title')), simple_title=self.simplifyTitle(attrs.get('title')), ) l.titles.append(title) db.add(l) db.commit() # Update library info if update_after is not False: handle = fireEventAsync if update_after is 'async' else fireEvent handle('library.update.movie', identifier=l.identifier, default_title=toUnicode(attrs.get('title', ''))) library_dict = l.to_dict(self.default_dict) return library_dict except: log.error('Failed adding media: %s', traceback.format_exc()) db.rollback() finally: db.close() return {}
def update(self, library, default_title=''): db = get_session() library = db.query(Library).filter_by( identifier=library.identifier).first() info = fireEvent('provider.movie.info', merge=True, identifier=library.identifier) # Main info library.plot = info.get('plot', '') library.tagline = info.get('tagline', '') library.year = info.get('year', 0) # Titles [db.delete(title) for title in library.titles] titles = info.get('titles') log.debug('Adding titles: %s' % titles) for title in titles: t = LibraryTitle(title=title, default=title.lower() == default_title.lower()) library.titles.append(t) db.commit() # Files images = info.get('images') for type in images: for image in images[type]: file_path = fireEvent('file.download', url=image, single=True) file = fireEvent('file.add', path=file_path, type=('image', type[:-1]), single=True) try: library.files.append(file) db.commit() except: log.debug('File already attached to library') fireEvent('library.update.after')
def add(self, attrs={}, update_after=True): # movies don't yet contain these, so lets make sure to set defaults type = attrs.get('type', 'movie') primary_provider = attrs.get('primary_provider', 'imdb') db = get_session() l = db.query(Library).filter_by( type=type, identifier=attrs.get('identifier')).first() if not l: status = fireEvent('status.get', 'needs_update', single=True) l = Library(type=type, primary_provider=primary_provider, year=attrs.get('year'), identifier=attrs.get('identifier'), plot=toUnicode(attrs.get('plot')), tagline=toUnicode(attrs.get('tagline')), status_id=status.get('id'), info={}, parent=None) title = LibraryTitle( title=toUnicode(attrs.get('title')), simple_title=self.simplifyTitle(attrs.get('title')), ) l.titles.append(title) db.add(l) db.commit() # Update library info if update_after is not False: handle = fireEventAsync if update_after is 'async' else fireEvent handle('library.update.movie', identifier=l.identifier, default_title=toUnicode(attrs.get('title', ''))) library_dict = l.to_dict(self.default_dict) db.expire_all() return library_dict
def update(self, identifier, default_title='', force=False): db = get_session() library = db.query(Library).filter_by(identifier=identifier).first() done_status = fireEvent('status.get', 'done', single=True) if library: library_dict = library.to_dict(self.default_dict) do_update = True if library.status_id == done_status.get('id') and not force: do_update = False else: info = fireEvent('provider.movie.info', merge=True, identifier=identifier) if not info or len(info) == 0: log.error('Could not update, no movie info to work with: %s' % identifier) return False # Main info if do_update: library.plot = info.get('plot', '') library.tagline = info.get('tagline', '') library.year = info.get('year', 0) library.status_id = done_status.get('id') db.commit() # Titles [db.delete(title) for title in library.titles] db.commit() titles = info.get('titles', []) log.debug('Adding titles: %s' % titles) for title in titles: t = LibraryTitle( title=title, default=title.lower() == default_title.lower()) library.titles.append(t) db.commit() # Files images = info.get('images', []) for type in images: for image in images[type]: if not isinstance(image, str): continue file_path = fireEvent('file.download', url=image, single=True) file = fireEvent('file.add', path=file_path, type=('image', type[:-1]), single=True) try: file = db.query(File).filter_by( id=file.get('id')).one() library.files.append(file) db.commit() except: log.debug('Failed to attach to library: %s' % traceback.format_exc()) library_dict = library.to_dict(self.default_dict) fireEvent('library.update_finish', data=library_dict) return library_dict
def update(self, identifier, default_title='', force=False): db = get_session() library = db.query(Library).filter_by(identifier=identifier).first() done_status = fireEvent('status.get', 'done', single=True) if library: library_dict = library.to_dict(self.default_dict) do_update = True if library.status_id == done_status.get('id') and not force: do_update = False else: info = fireEvent('movie.info', merge=True, identifier=identifier) # Don't need those here try: del info['in_wanted'] except: pass try: del info['in_library'] except: pass if not info or len(info) == 0: log.error('Could not update, no movie info to work with: %s', identifier) return False # Main info if do_update: library.plot = toUnicode(info.get('plot', '')) library.tagline = toUnicode(info.get('tagline', '')) library.year = info.get('year', 0) library.status_id = done_status.get('id') library.info = info db.commit() # Titles [db.delete(title) for title in library.titles] db.commit() titles = info.get('titles', []) log.debug('Adding titles: %s', titles) for title in titles: if not title: continue title = toUnicode(title) t = LibraryTitle( title=title, simple_title=self.simplifyTitle(title), default=title.lower() == toUnicode(default_title.lower()) or (toUnicode(default_title) == u'' and toUnicode(titles[0]) == title)) library.titles.append(t) 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 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()) library_dict = library.to_dict(self.default_dict) return library_dict
def update(self, identifier, default_title='', force=False): if self.shuttingDown(): return db = get_session() library = db.query(SeasonLibrary).filter_by( identifier=identifier).first() done_status = fireEvent('status.get', 'done', single=True) if library: library_dict = library.to_dict(self.default_dict) do_update = True parent_identifier = None if library.parent is not None: parent_identifier = library.parent.identifier if library.status_id == done_status.get('id') and not force: do_update = False season_params = {'season_identifier': identifier} info = fireEvent('season.info', merge=True, identifier=parent_identifier, params=season_params) # Don't need those here try: del info['in_wanted'] except: pass try: del info['in_library'] except: pass if not info or len(info) == 0: log.error('Could not update, no movie info to work with: %s', identifier) return False # Main info if do_update: library.plot = toUnicode(info.get('plot', '')) library.tagline = toUnicode(info.get('tagline', '')) library.year = info.get('year', 0) library.status_id = done_status.get('id') library.season_number = tryInt(info.get('seasonnumber', None)) library.info.update(info) db.commit() # Titles [db.delete(title) for title in library.titles] db.commit() titles = info.get('titles', []) log.debug('Adding titles: %s', titles) counter = 0 for title in titles: if not title: continue title = toUnicode(title) t = LibraryTitle( title=title, simple_title=self.simplifyTitle(title), # XXX: default was None; so added a quick hack since we don't really need titiles for seasons anyway #default = (len(default_title) == 0 and counter == 0) or len(titles) == 1 or title.lower() == toUnicode(default_title.lower()) or (toUnicode(default_title) == u'' and toUnicode(titles[0]) == title) default=True, ) library.titles.append(t) counter += 1 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 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()) library_dict = library.to_dict(self.default_dict) db.expire_all() return library_dict
def update(self, identifier, default_title = '', force = False): if self.shuttingDown(): return db = get_session() library = db.query(ShowLibrary).filter_by(identifier = identifier).first() done_status = fireEvent('status.get', 'done', single = True) if library: library_dict = library.to_dict(self.default_dict) do_update = True info = fireEvent('show.info', merge = True, identifier = identifier) # Don't need those here try: del info['in_wanted'] except: pass try: del info['in_library'] except: pass if not info or len(info) == 0: log.error('Could not update, no show info to work with: %s', identifier) return False # Main info if do_update: library.plot = toUnicode(info.get('plot', '')) library.tagline = toUnicode(info.get('tagline', '')) library.year = info.get('year', 0) library.status_id = done_status.get('id') library.show_status = toUnicode(info.get('status', '').lower()) library.airs_time = info.get('airs_time', None) # Bits days_of_week_map = { u'Monday': 1, u'Tuesday': 2, u'Wednesday': 4, u'Thursday': 8, u'Friday': 16, u'Saturday': 32, u'Sunday': 64, u'Daily': 127, } try: library.airs_dayofweek = days_of_week_map.get(info.get('airs_dayofweek')) except: library.airs_dayofweek = 0 try: library.last_updated = int(info.get('lastupdated')) except: library.last_updated = int(time.time()) library.info.update(info) db.commit() # Titles [db.delete(title) for title in library.titles] db.commit() titles = info.get('titles', []) log.debug('Adding titles: %s', titles) counter = 0 for title in titles: if not title: continue title = toUnicode(title) t = LibraryTitle( title = title, simple_title = self.simplifyTitle(title), default = (len(default_title) == 0 and counter == 0) or len(titles) == 1 or title.lower() == toUnicode(default_title.lower()) or (toUnicode(default_title) == u'' and toUnicode(titles[0]) == title) ) library.titles.append(t) counter += 1 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 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()) library_dict = library.to_dict(self.default_dict) db.expire_all() return library_dict