def __init__(self, rec_show_prov, series_id, title, mapped_indexer, mapped_series_id, **show_attr): """Create a show recommendation. :param rec_show_prov: Recommended shows provider. Used to keep track of the provider, which facilitated the recommended shows list. :param series_id: as provided by the list provider :param title: of the show as displayed in the recommended show page :param indexer: used to map the show to :param indexer_id: a mapped indexer_id for indexer :param rating: of the show in percent :param votes: number of votes :param image_href: the href when clicked on the show image (poster) :param image_src: the local url to the "cached" image (poster) :param default_img_src: a default image when no poster available """ self.recommender = rec_show_prov.recommender self.cache_subfolder = rec_show_prov.cache_subfolder or 'recommended' self.default_img_src = getattr(rec_show_prov, 'default_img_src', '') self.series_id = series_id self.title = title self.mapped_indexer = int(mapped_indexer) self.mapped_indexer_name = indexer_id_to_name(mapped_indexer) try: self.mapped_series_id = int(mapped_series_id) except ValueError: raise MissingTvdbMapping('Could not parse the indexer_id [{0}]'.format(mapped_series_id)) self.rating = show_attr.get('rating') or 0 self.votes = show_attr.get('votes') if self.votes and not isinstance(self.votes, int): trans_mapping = {ord(c): None for c in ['.', ',']} if PY2: self.votes = int(self.votes.decode('utf-8').translate(trans_mapping)) else: self.votes = int(self.votes.translate(trans_mapping)) self.image_href = show_attr.get('image_href') self.image_src = show_attr.get('image_src') self.ids = show_attr.get('ids', {}) self.is_anime = False # Check if the show is currently already in the db indexers = {mapped_indexer: mapped_series_id} indexers.update({indexer_name_mapping[indexer_name]: indexers_series_id for indexer_name, indexers_series_id in self.ids.items() if indexer_name in indexer_name_mapping}) self.show_in_list = False for show in app.showList: if show.indexer in indexers and show.series_id == indexers[show.indexer]: self.show_in_list = True self.mapped_indexer = show.indexer self.mapped_indexer_name = show.identifier.indexer.slug self.series_id = show.series_id self.session = session
def update_library(self, show=None): """ Update the Emby Media Server host via HTTP API. :return: True for no issue or False if there was an error """ if app.USE_EMBY: if not app.EMBY_HOST: log.debug('EMBY: No host specified, check your settings') return False if show: # EMBY only supports TVDB ids provider = 'tvdbid' if show.indexer == INDEXER_TVDBV2: tvdb_id = show.indexerid else: # Try using external ids to get a TVDB id tvdb_id = show.externals.get(mappings[INDEXER_TVDBV2], None) if tvdb_id is None: if show.indexer == INDEXER_TVRAGE: log.warning('EMBY: TVRage indexer no longer valid') else: log.warning( 'EMBY: Unable to find a TVDB ID for {series},' ' and {indexer} indexer is unsupported', {'series': show.name, 'indexer': indexer_id_to_name(show.indexer)} ) return False params = { provider: str(tvdb_id) } else: params = {} url = 'http://{host}/emby/Library/Series/Updated'.format(host=app.EMBY_HOST) try: resp = self.session.post( url=url, params=params, headers={ 'X-MediaBrowser-Token': app.EMBY_APIKEY } ) resp.raise_for_status() if resp.content: log.debug('EMBY: HTTP response: {0}', resp.content.replace('\n', '')) log.info('EMBY: Successfully sent a "Series Library Updated" command.') return True except (HTTPError, RequestException) as error: log.warning('EMBY: Warning: Unable to contact Emby at {url}: {error}', {'url': url, 'error': ex(error)}) return False
def update_library(self, show=None): """ Update the Emby Media Server host via HTTP API. :return: True for no issue or False if there was an error """ if app.USE_EMBY: if not app.EMBY_HOST: log.debug('EMBY: No host specified, check your settings') return False if show: # EMBY only supports TVDB ids provider = 'tvdbid' if show.indexer == INDEXER_TVDBV2: tvdb_id = show.indexerid else: # Try using external ids to get a TVDB id tvdb_id = show.externals.get(mappings[INDEXER_TVDBV2], None) if tvdb_id is None: if show.indexer == INDEXER_TVRAGE: log.warning('EMBY: TVRage indexer no longer valid') else: log.warning( 'EMBY: Unable to find a TVDB ID for {series},' ' and {indexer} indexer is unsupported', {'series': show.name, 'indexer': indexer_id_to_name(show.indexer)} ) return False params = { provider: text_type(tvdb_id) } else: params = {} url = 'http://{host}/emby/Library/Series/Updated'.format(host=app.EMBY_HOST) try: resp = self.session.post( url=url, params=params, headers={ 'X-MediaBrowser-Token': app.EMBY_APIKEY } ) resp.raise_for_status() if resp.content: log.debug('EMBY: HTTP response: {0}', resp.content.replace('\n', '')) log.info('EMBY: Successfully sent a "Series Library Updated" command.') return True except (HTTPError, RequestException) as error: log.warning('EMBY: Warning: Unable to contact Emby at {url}: {error}', {'url': url, 'error': ex(error)}) return False
def changeEpisodeStatuses(self, oldStatus, newStatus, *args, **kwargs): status_list = [int(oldStatus)] if status_list[0] == SNATCHED: status_list = [SNATCHED, SNATCHED_PROPER, SNATCHED_BEST] to_change = {} # make a list of all shows and their associated args for arg in kwargs: indexer_id, series_id, what = arg.split('-') # we don't care about unchecked checkboxes if kwargs[arg] != 'on': continue if (indexer_id, series_id) not in to_change: to_change[(indexer_id, series_id)] = [] to_change[(indexer_id, series_id)].append(what) main_db_con = db.DBConnection() for cur_indexer_id, cur_series_id in to_change: # get a list of all the eps we want to change if they just said 'all' if 'all' in to_change[(cur_indexer_id, cur_series_id)]: all_eps_results = main_db_con.select( b'SELECT season, episode ' b'FROM tv_episodes ' b'WHERE status IN ({statuses}) ' b'AND season != 0 ' b'AND indexer = ? ' b'AND showid = ?'.format( statuses=','.join(['?'] * len(status_list))), status_list + [cur_indexer_id, cur_series_id]) all_eps = [ '{season}x{episode}'.format(season=x[b'season'], episode=x[b'episode']) for x in all_eps_results ] to_change[cur_indexer_id, cur_series_id] = all_eps self.setStatus(indexer_id_to_name(int(cur_indexer_id)), cur_series_id, '|'.join(to_change[(cur_indexer_id, cur_series_id)]), newStatus, direct=True) return self.redirect('/manage/episodeStatuses/')
def __init__(self, rec_show_prov, series_id, title, mapped_indexer, mapped_series_id, **show_attr): """Create a show recommendation. :param rec_show_prov: Recommended shows provider. Used to keep track of the provider, which facilitated the recommended shows list. :param series_id: as provided by the list provider :param title: of the show as displayed in the recommended show page :param indexer: used to map the show to :param indexer_id: a mapped indexer_id for indexer :param rating: of the show in percent :param votes: number of votes :param image_href: the href when clicked on the show image (poster) :param image_src: the local url to the "cached" image (poster) :param default_img_src: a default image when no poster available """ self.recommender = rec_show_prov.recommender self.cache_subfolder = rec_show_prov.cache_subfolder or 'recommended' self.default_img_src = getattr(rec_show_prov, 'default_img_src', '') self.series_id = series_id self.title = title self.mapped_indexer = int(mapped_indexer) self.mapped_indexer_name = indexer_id_to_name(mapped_indexer) try: self.mapped_series_id = int(mapped_series_id) except ValueError: raise MissingTvdbMapping('Could not parse the indexer_id [{0}]'.format(mapped_series_id)) self.rating = show_attr.get('rating') or 0 self.votes = show_attr.get('votes') if self.votes and not isinstance(self.votes, int): trans_mapping = {ord(c): None for c in ['.', ',']} if PY2: self.votes = int(self.votes.decode('utf-8').translate(trans_mapping)) else: self.votes = int(self.votes.translate(trans_mapping)) self.image_href = show_attr.get('image_href') self.image_src = show_attr.get('image_src') self.ids = show_attr.get('ids', {}) self.is_anime = False # Check if the show is currently already in the db self.show_in_list = bool([show.indexerid for show in app.showList if show.series_id == self.mapped_series_id and show.indexer == self.mapped_indexer]) self.session = session
def changeEpisodeStatuses(self, oldStatus, newStatus, *args, **kwargs): status_list = [int(oldStatus)] if status_list[0] == SNATCHED: status_list = [SNATCHED, SNATCHED_PROPER, SNATCHED_BEST] to_change = {} # make a list of all shows and their associated args for arg in kwargs: indexer_id, series_id, what = arg.split('-') # we don't care about unchecked checkboxes if kwargs[arg] != 'on': continue if (indexer_id, series_id) not in to_change: to_change[(indexer_id, series_id)] = [] to_change[(indexer_id, series_id)].append(what) main_db_con = db.DBConnection() for cur_indexer_id, cur_series_id in to_change: # get a list of all the eps we want to change if they just said 'all' if 'all' in to_change[(cur_indexer_id, cur_series_id)]: all_eps_results = main_db_con.select( 'SELECT season, episode ' 'FROM tv_episodes ' 'WHERE status IN ({statuses}) ' 'AND season != 0 ' 'AND indexer = ? ' 'AND showid = ?'.format(statuses=','.join(['?'] * len(status_list))), status_list + [cur_indexer_id, cur_series_id] ) all_eps = ['s{season}e{episode}'.format(season=x['season'], episode=x['episode']) for x in all_eps_results] to_change[cur_indexer_id, cur_series_id] = all_eps self.setStatus( indexername=indexer_id_to_name(int(cur_indexer_id)), seriesid=cur_series_id, eps='|'.join(to_change[(cur_indexer_id, cur_series_id)]), status=newStatus, direct=True ) return self.redirect('/manage/episodeStatuses/')
def slug(self): """Slug name.""" return indexer_id_to_name(self.id)