def qualityFromFileMeta(filename): """ Get quality from file metadata :param filename: Filename to analyse :return: Quality prefix """ data = {} quality = Quality.UNKNOWN if os.path.isfile(filename): meta = getFileMetadata(filename) try: if meta.get('resolution_width'): data['resolution_width'] = meta.get('resolution_width') data['resolution_height'] = meta.get('resolution_height') data['aspect'] = round( float(meta.get('resolution_width')) / meta.get('resolution_height', 1), 2) else: data.update(getResolution(filename)) except: sickrage.srCore.srLogger.debug('Error parsing metadata: %s %s', (filename, traceback.format_exc())) pass base_filename = os.path.basename(filename) bluray = re.search(r"blue?-?ray|hddvd|b[rd](rip|mux)", base_filename, re.I) is not None webdl = re.search(r"web.?dl|web(rip|mux|hd)", base_filename, re.I) is not None if data['resolution_height'] > 1000: quality = ((Quality.FULLHDTV, Quality.FULLHDBLURAY)[bluray], Quality.FULLHDWEBDL)[webdl] elif 680 < data['resolution_height'] < 800: quality = ((Quality.HDTV, Quality.HDBLURAY)[bluray], Quality.HDWEBDL)[webdl] elif data['resolution_height'] < 680: quality = (Quality.SDTV, Quality.SDDVD)[re.search( r'dvd|b[rd]rip|blue?-?ray', base_filename, re.I) is not None] sickrage.srCore.srLogger.debug("Quality from file metadata: {}".format( get_quality_string(quality))) return quality
def qualityFromFileMeta(filename): """ Get quality from file metadata :param filename: Filename to analyse :return: Quality prefix """ data = {} quality = Quality.UNKNOWN if os.path.isfile(filename): meta = getFileMetadata(filename) try: if meta.get('resolution_width'): data['resolution_width'] = meta.get('resolution_width') data['resolution_height'] = meta.get('resolution_height') data['aspect'] = round(float(meta.get('resolution_width')) / meta.get('resolution_height', 1), 2) else: data.update(getResolution(filename)) except: sickrage.srCore.srLogger.debug('Error parsing metadata: %s %s', (filename, traceback.format_exc())) pass base_filename = os.path.basename(filename) bluray = re.search(r"blue?-?ray|hddvd|b[rd](rip|mux)", base_filename, re.I) is not None webdl = re.search(r"web.?dl|web(rip|mux|hd)", base_filename, re.I) is not None if data['resolution_height'] > 1000: quality = ((Quality.FULLHDTV, Quality.FULLHDBLURAY)[bluray], Quality.FULLHDWEBDL)[webdl] elif 680 < data['resolution_height'] < 800: quality = ((Quality.HDTV, Quality.HDBLURAY)[bluray], Quality.HDWEBDL)[webdl] elif data['resolution_height'] < 680: quality = (Quality.SDTV, Quality.SDDVD)[ re.search(r'dvd|b[rd]rip|blue?-?ray', base_filename, re.I) is not None] sickrage.srCore.srLogger.debug("Quality from file metadata: {}".format(get_quality_string(quality))) return quality
def get_coming_episodes(categories, sort, group, paused=False): """ :param categories: The categories of coming episodes. See ``ComingEpisodes.categories`` :param sort: The sort to apply to the coming episodes. See ``ComingEpisodes.sorts`` :param group: ``True`` to group the coming episodes by category, ``False`` otherwise :param paused: ``True`` to include paused shows, ``False`` otherwise :return: The list of coming episodes """ paused = sickrage.COMING_EPS_DISPLAY_PAUSED or paused if not isinstance(categories, list): categories = categories.split('|') if sort not in ComingEpisodes.sorts.keys(): sort = 'date' today = date.today().toordinal() next_week = (date.today() + timedelta(days=7)).toordinal() recently = (date.today() - timedelta(days=sickrage.COMING_EPS_MISSED_RANGE)).toordinal() qualities_list = Quality.DOWNLOADED + \ Quality.SNATCHED + \ Quality.SNATCHED_BEST + \ Quality.SNATCHED_PROPER + \ Quality.ARCHIVED + \ Quality.IGNORED fields_to_select = ', '.join( ['airdate', 'airs', 'description', 'episode', 'imdb_id', 'e.indexer', 'indexer_id', 'name', 'network', 'paused', 'quality', 'runtime', 'season', 'show_name', 'showid', 's.status'] ) results = main_db.MainDB().select( 'SELECT %s ' % fields_to_select + 'FROM tv_episodes e, tv_shows s ' 'WHERE season != 0 ' 'AND airdate >= ? ' 'AND airdate < ? ' 'AND s.indexer_id = e.showid ' 'AND e.status NOT IN (' + ','.join(['?'] * len(qualities_list)) + ')', [today, next_week] + qualities_list ) done_shows_list = [int(result[b'showid']) for result in results] placeholder = ','.join(['?'] * len(done_shows_list)) placeholder2 = ','.join( ['?'] * len(Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER)) results += main_db.MainDB().select( 'SELECT %s ' % fields_to_select + 'FROM tv_episodes e, tv_shows s ' 'WHERE season != 0 ' 'AND showid NOT IN (' + placeholder + ') ' 'AND s.indexer_id = e.showid ' 'AND airdate = (SELECT airdate ' 'FROM tv_episodes inner_e ' 'WHERE inner_e.season != 0 ' 'AND inner_e.showid = e.showid ' 'AND inner_e.airdate >= ? ' 'ORDER BY inner_e.airdate ASC LIMIT 1) ' 'AND e.status NOT IN (' + placeholder2 + ')', done_shows_list + [ next_week] + Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER ) results += main_db.MainDB().select( 'SELECT %s ' % fields_to_select + 'FROM tv_episodes e, tv_shows s ' 'WHERE season != 0 ' 'AND s.indexer_id = e.showid ' 'AND airdate < ? ' 'AND airdate >= ? ' 'AND e.status IN (?,?) ' 'AND e.status NOT IN (' + ','.join(['?'] * len(qualities_list)) + ')', [today, recently, WANTED, UNAIRED] + qualities_list ) results = [dict(result) for result in results] for index, item in enumerate(results): results[index][b'localtime'] = srDateTime.convert_to_setting( parse_date_time(item[b'airdate'], item[b'airs'], item[b'network'])) results.sort(ComingEpisodes.sorts[sort]) if not group: return results grouped_results = {category: [] for category in categories} for result in results: if result[b'paused'] and not paused: continue result[b'airs'] = str(result[b'airs']).replace('am', ' AM').replace('pm', ' PM').replace(' ', ' ') result[b'airdate'] = result[b'localtime'].toordinal() if result[b'airdate'] < today: category = 'missed' elif result[b'airdate'] >= next_week: category = 'later' elif result[b'airdate'] == today: category = 'today' else: category = 'soon' if len(categories) > 0 and category not in categories: continue if not result[b'network']: result[b'network'] = '' result[b'quality'] = get_quality_string(result[b'quality']) result[b'airs'] = srDateTime.srftime(result[b'localtime'], t_preset=timeFormat).lstrip('0').replace(' 0', ' ') result[b'weekday'] = 1 + date.fromordinal(result[b'airdate']).weekday() result[b'tvdbid'] = result[b'indexer_id'] result[b'airdate'] = srDateTime.srfdate(result[b'localtime'], d_preset=dateFormat) result[b'localtime'] = result[b'localtime'].toordinal() grouped_results[category].append(result) return grouped_results
def get_coming_episodes(categories, sort, group, paused=False): """ :param categories: The categories of coming episodes. See ``ComingEpisodes.categories`` :param sort: The sort to apply to the coming episodes. See ``ComingEpisodes.sorts`` :param group: ``True`` to group the coming episodes by category, ``False`` otherwise :param paused: ``True`` to include paused shows, ``False`` otherwise :return: The list of coming episodes """ paused = sickrage.srCore.srConfig.COMING_EPS_DISPLAY_PAUSED or paused if not isinstance(categories, list): categories = categories.split('|') if sort not in ComingEpisodes.sorts.keys(): sort = 'date' today = datetime.date.today().toordinal() next_week = (datetime.date.today() + datetime.timedelta(days=7)).toordinal() recently = ( datetime.date.today() - datetime.timedelta( days=sickrage.srCore.srConfig.COMING_EPS_MISSED_RANGE)).toordinal() qualities_list = Quality.DOWNLOADED + \ Quality.SNATCHED + \ Quality.SNATCHED_BEST + \ Quality.SNATCHED_PROPER + \ Quality.ARCHIVED + \ Quality.IGNORED results = [] for s in [s['doc'] for s in sickrage.srCore.mainDB.db.all('tv_shows', with_doc=True)]: for e in [e['doc'] for e in sickrage.srCore.mainDB.db.get_many('tv_episodes', s['indexer_id'], with_doc=True) if e['doc']['season'] != 0 and today <= e['doc']['airdate'] < next_week and e['doc']['status'] not in qualities_list]: results += [{ 'airdate': e['airdate'], 'airs': s['airs'], 'description': e['description'], 'episode': e['episode'], 'imdb_id': s['imdb_id'], 'indexer': e['indexer'], 'indexer_id': s['indexer_id'], 'name': e['name'], 'network': s['network'], 'paused': s['paused'], 'quality': s['quality'], 'runtime': s['runtime'], 'season': e['season'], 'show_name': s['show_name'], 'showid': e['showid'], 'status': s['status'] }] done_shows_list = [int(result['showid']) for result in results] for s in [s['doc'] for s in sickrage.srCore.mainDB.db.all('tv_shows', with_doc=True)]: for e in [e['doc'] for e in sickrage.srCore.mainDB.db.get_many('tv_episodes', s['indexer_id'], with_doc=True) if e['doc']['season'] != 0 and e['doc']['showid'] not in done_shows_list and e['doc']['airdate'] >= next_week and e['doc']['status'] not in Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER]: results += [{ 'airdate': e['airdate'], 'airs': s['airs'], 'description': e['description'], 'episode': e['episode'], 'imdb_id': s['imdb_id'], 'indexer': e['indexer'], 'indexer_id': s['indexer_id'], 'name': e['name'], 'network': s['network'], 'paused': s['paused'], 'quality': s['quality'], 'runtime': s['runtime'], 'season': e['season'], 'show_name': s['show_name'], 'showid': e['showid'], 'status': s['status'] }] for s in [s['doc'] for s in sickrage.srCore.mainDB.db.all('tv_shows', with_doc=True)]: for e in [e['doc'] for e in sickrage.srCore.mainDB.db.get_many('tv_episodes', s['indexer_id'], with_doc=True) if e['doc']['season'] != 0 and today > e['doc']['airdate'] >= recently and e['doc']['status'] in [WANTED, UNAIRED] and e['doc']['status'] not in qualities_list]: results += [{ 'airdate': e['airdate'], 'airs': s['airs'], 'description': e['description'], 'episode': e['episode'], 'imdb_id': s['imdb_id'], 'indexer': e['indexer'], 'indexer_id': s['indexer_id'], 'name': e['name'], 'network': s['network'], 'paused': s['paused'], 'quality': s['quality'], 'runtime': s['runtime'], 'season': e['season'], 'show_name': s['show_name'], 'showid': e['showid'], 'status': s['status'] }] for index, item in enumerate(results): results[index]['localtime'] = srDateTime.convert_to_setting( parse_date_time(item['airdate'], item['airs'], item['network'])) results.sort(ComingEpisodes.sorts[sort]) if not group: return results grouped_results = {category: [] for category in categories} for result in results: if result['paused'] and not paused: continue result['airs'] = str(result['airs']).replace('am', ' AM').replace('pm', ' PM').replace(' ', ' ') result['airdate'] = result['localtime'].toordinal() if result['airdate'] < today: category = 'missed' elif result['airdate'] >= next_week: category = 'later' elif result['airdate'] == today: category = 'today' else: category = 'soon' if len(categories) > 0 and category not in categories: continue if not result['network']: result['network'] = '' result['quality'] = get_quality_string(result['quality']) result['airs'] = srDateTime.srftime(result['localtime'], t_preset=timeFormat).lstrip('0').replace(' 0', ' ') result['weekday'] = 1 + datetime.date.fromordinal(result['airdate']).weekday() result['tvdbid'] = result['indexer_id'] result['airdate'] = srDateTime.srfdate(result['localtime'], d_preset=dateFormat) result['localtime'] = result['localtime'].toordinal() grouped_results[category].append(result) return grouped_results
def get_coming_episodes(categories, sort, group, paused=False): """ :param categories: The categories of coming episodes. See ``ComingEpisodes.categories`` :param sort: The sort to apply to the coming episodes. See ``ComingEpisodes.sorts`` :param group: ``True`` to group the coming episodes by category, ``False`` otherwise :param paused: ``True`` to include paused shows, ``False`` otherwise :return: The list of coming episodes """ def result(show, episode): return [{ 'airdate': episode['airdate'], 'airs': show.airs, 'description': episode['description'], 'episode': episode['episode'], 'imdb_id': show.imdbid, 'indexer': episode['indexer'], 'indexer_id': show.indexerid, 'name': episode['name'], 'network': show.network, 'paused': show.paused, 'quality': show.quality, 'runtime': show.runtime, 'season': episode['season'], 'show_name': show.name, 'showid': episode['showid'], 'status': show.status }] paused = sickrage.app.config.coming_eps_display_paused or paused if not isinstance(categories, list): categories = categories.split('|') if sort not in ComingEpisodes.sorts.keys(): sort = 'date' today = datetime.date.today().toordinal() next_week = (datetime.date.today() + datetime.timedelta(days=7)).toordinal() recently = (datetime.date.today() - datetime.timedelta( days=sickrage.app.config.coming_eps_missed_range)).toordinal() qualities_list = Quality.DOWNLOADED + \ Quality.SNATCHED + \ Quality.SNATCHED_BEST + \ Quality.SNATCHED_PROPER + \ Quality.ARCHIVED + \ Quality.IGNORED results = [] for s in sickrage.app.showlist: for e in sickrage.app.main_db.get_many('tv_episodes', s.indexerid): if e['season'] != 0 and today <= e['airdate'] < next_week and e[ 'status'] not in qualities_list: results += result(s, e) if e['season'] != 0 and e['showid'] not in [int(r['showid']) for r in results] \ and e['airdate'] >= next_week and e['status'] \ not in Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER: results += result(s, e) if e['season'] != 0 and today > e['airdate'] >= recently \ and e['status'] in [WANTED, UNAIRED] and e['status'] not in qualities_list: results += result(s, e) for index, item in enumerate(results): results[index]['localtime'] = srDateTime(parse_date_time( item['airdate'], item['airs'], item['network']), convert=True).dt results.sort(ComingEpisodes.sorts[sort]) if not group: return results grouped_results = {category: [] for category in categories} for result in results: if result['paused'] and not paused: continue result['airs'] = str(result['airs']).replace('am', ' AM').replace( 'pm', ' PM').replace(' ', ' ') result['airdate'] = result['localtime'].toordinal() if result['airdate'] < today: category = 'missed' elif result['airdate'] >= next_week: category = 'later' elif result['airdate'] == today: category = 'today' else: category = 'soon' if len(categories) > 0 and category not in categories: continue if not result['network']: result['network'] = '' result['quality'] = get_quality_string(result['quality']) result['airs'] = srDateTime(result['localtime']).srftime( t_preset=timeFormat).lstrip('0').replace(' 0', ' ') result['weekday'] = 1 + datetime.date.fromordinal( result['airdate']).weekday() result['tvdbid'] = result['indexer_id'] result['airdate'] = srDateTime( result['localtime']).srfdate(d_preset=dateFormat) result['localtime'] = result['localtime'].toordinal() grouped_results[category].append(result) return grouped_results
def add_result(show, episode, grouped=False): to_return = { 'airdate': episode.airdate, 'airs': show.airs, 'description': episode.description, 'episode': episode.episode, 'imdb_id': show.imdb_id, 'indexer': episode.indexer, 'indexer_id': show.indexer_id, 'name': episode.name, 'network': show.network, 'paused': show.paused, 'quality': show.quality, 'runtime': show.runtime, 'season': episode.season, 'show_name': show.name, 'showid': episode.showid, 'status': show.status, 'localtime': SRDateTime(sickrage.app.tz_updater.parse_date_time( episode.airdate, show.airs, show.network), convert=True).dt } if grouped: to_return['airs'] = str(to_return['airs']).replace( 'am', ' AM').replace('pm', ' PM').replace(' ', ' ') to_return['airdate'] = to_return['localtime'].date() to_return['quality'] = get_quality_string(to_return['quality']) to_return['airs'] = SRDateTime(to_return['localtime']).srftime( t_preset=timeFormat).lstrip('0').replace(' 0', ' ') to_return['weekday'] = 1 + to_return['airdate'].weekday() to_return['tvdbid'] = to_return['indexer_id'] to_return['airdate'] = SRDateTime( to_return['localtime']).srfdate(d_preset=dateFormat) if grouped: if to_return['paused'] and not paused: return if to_return['airdate'] < today: category = 'missed' elif to_return['airdate'] >= next_week: category = 'later' elif to_return['airdate'] == today: category = 'today' else: category = 'soon' if len(categories) > 0 and category not in categories: return grouped_results[category].append(to_return) else: results.append(to_return)
def get_coming_episodes(categories, sort, group, paused=False): """ :param categories: The categories of coming episodes. See ``ComingEpisodes.categories`` :param sort: The sort to apply to the coming episodes. See ``ComingEpisodes.sorts`` :param group: ``True`` to group the coming episodes by category, ``False`` otherwise :param paused: ``True`` to include paused shows, ``False`` otherwise :return: The list of coming episodes """ paused = sickrage.COMING_EPS_DISPLAY_PAUSED or paused if not isinstance(categories, list): categories = categories.split('|') if sort not in ComingEpisodes.sorts.keys(): sort = 'date' today = date.today().toordinal() next_week = (date.today() + timedelta(days=7)).toordinal() recently = ( date.today() - timedelta(days=sickrage.COMING_EPS_MISSED_RANGE)).toordinal() qualities_list = Quality.DOWNLOADED + \ Quality.SNATCHED + \ Quality.SNATCHED_BEST + \ Quality.SNATCHED_PROPER + \ Quality.ARCHIVED + \ Quality.IGNORED fields_to_select = ', '.join([ 'airdate', 'airs', 'description', 'episode', 'imdb_id', 'e.indexer', 'indexer_id', 'name', 'network', 'paused', 'quality', 'runtime', 'season', 'show_name', 'showid', 's.status' ]) results = main_db.MainDB().select( 'SELECT %s ' % fields_to_select + 'FROM tv_episodes e, tv_shows s ' 'WHERE season != 0 ' 'AND airdate >= ? ' 'AND airdate < ? ' 'AND s.indexer_id = e.showid ' 'AND e.status NOT IN (' + ','.join(['?'] * len(qualities_list)) + ')', [today, next_week] + qualities_list) done_shows_list = [int(result[b'showid']) for result in results] placeholder = ','.join(['?'] * len(done_shows_list)) placeholder2 = ','.join( ['?'] * len(Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER)) results += main_db.MainDB().select( 'SELECT %s ' % fields_to_select + 'FROM tv_episodes e, tv_shows s ' 'WHERE season != 0 ' 'AND showid NOT IN (' + placeholder + ') ' 'AND s.indexer_id = e.showid ' 'AND airdate = (SELECT airdate ' 'FROM tv_episodes inner_e ' 'WHERE inner_e.season != 0 ' 'AND inner_e.showid = e.showid ' 'AND inner_e.airdate >= ? ' 'ORDER BY inner_e.airdate ASC LIMIT 1) ' 'AND e.status NOT IN (' + placeholder2 + ')', done_shows_list + [next_week] + Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER) results += main_db.MainDB().select( 'SELECT %s ' % fields_to_select + 'FROM tv_episodes e, tv_shows s ' 'WHERE season != 0 ' 'AND s.indexer_id = e.showid ' 'AND airdate < ? ' 'AND airdate >= ? ' 'AND e.status IN (?,?) ' 'AND e.status NOT IN (' + ','.join(['?'] * len(qualities_list)) + ')', [today, recently, WANTED, UNAIRED] + qualities_list) results = [dict(result) for result in results] for index, item in enumerate(results): results[index][b'localtime'] = srDateTime.convert_to_setting( parse_date_time(item[b'airdate'], item[b'airs'], item[b'network'])) results.sort(ComingEpisodes.sorts[sort]) if not group: return results grouped_results = {category: [] for category in categories} for result in results: if result[b'paused'] and not paused: continue result[b'airs'] = str(result[b'airs']).replace( 'am', ' AM').replace('pm', ' PM').replace(' ', ' ') result[b'airdate'] = result[b'localtime'].toordinal() if result[b'airdate'] < today: category = 'missed' elif result[b'airdate'] >= next_week: category = 'later' elif result[b'airdate'] == today: category = 'today' else: category = 'soon' if len(categories) > 0 and category not in categories: continue if not result[b'network']: result[b'network'] = '' result[b'quality'] = get_quality_string(result[b'quality']) result[b'airs'] = srDateTime.srftime( result[b'localtime'], t_preset=timeFormat).lstrip('0').replace(' 0', ' ') result[b'weekday'] = 1 + date.fromordinal( result[b'airdate']).weekday() result[b'tvdbid'] = result[b'indexer_id'] result[b'airdate'] = srDateTime.srfdate(result[b'localtime'], d_preset=dateFormat) result[b'localtime'] = result[b'localtime'].toordinal() grouped_results[category].append(result) return grouped_results
def get_coming_episodes(categories, sort, group, paused=False): """ :param categories: The categories of coming episodes. See ``ComingEpisodes.categories`` :param sort: The sort to apply to the coming episodes. See ``ComingEpisodes.sorts`` :param group: ``True`` to group the coming episodes by category, ``False`` otherwise :param paused: ``True`` to include paused shows, ``False`` otherwise :return: The list of coming episodes """ paused = sickrage.srCore.srConfig.COMING_EPS_DISPLAY_PAUSED or paused if not isinstance(categories, list): categories = categories.split('|') if sort not in ComingEpisodes.sorts.keys(): sort = 'date' today = datetime.date.today().toordinal() next_week = (datetime.date.today() + datetime.timedelta(days=7)).toordinal() recently = (datetime.date.today() - datetime.timedelta( days=sickrage.srCore.srConfig.COMING_EPS_MISSED_RANGE) ).toordinal() qualities_list = Quality.DOWNLOADED + \ Quality.SNATCHED + \ Quality.SNATCHED_BEST + \ Quality.SNATCHED_PROPER + \ Quality.ARCHIVED + \ Quality.IGNORED results = [] for s in [ s['doc'] for s in sickrage.srCore.mainDB.db.all('tv_shows', with_doc=True) ]: for e in [ e['doc'] for e in sickrage.srCore.mainDB.db.get_many( 'tv_episodes', s['indexer_id'], with_doc=True) if e['doc']['season'] != 0 and today <= e['doc']['airdate'] < next_week and e['doc']['status'] not in qualities_list ]: results += [{ 'airdate': e['airdate'], 'airs': s['airs'], 'description': e['description'], 'episode': e['episode'], 'imdb_id': s['imdb_id'], 'indexer': e['indexer'], 'indexer_id': s['indexer_id'], 'name': e['name'], 'network': s['network'], 'paused': s['paused'], 'quality': s['quality'], 'runtime': s['runtime'], 'season': e['season'], 'show_name': s['show_name'], 'showid': e['showid'], 'status': s['status'] }] done_shows_list = [int(result['showid']) for result in results] for s in [ s['doc'] for s in sickrage.srCore.mainDB.db.all('tv_shows', with_doc=True) ]: for e in [ e['doc'] for e in sickrage.srCore.mainDB.db.get_many( 'tv_episodes', s['indexer_id'], with_doc=True) if e['doc']['season'] != 0 and e['doc']['showid'] not in done_shows_list and e['doc']['airdate'] >= next_week and e['doc']['status'] not in Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER ]: results += [{ 'airdate': e['airdate'], 'airs': s['airs'], 'description': e['description'], 'episode': e['episode'], 'imdb_id': s['imdb_id'], 'indexer': e['indexer'], 'indexer_id': s['indexer_id'], 'name': e['name'], 'network': s['network'], 'paused': s['paused'], 'quality': s['quality'], 'runtime': s['runtime'], 'season': e['season'], 'show_name': s['show_name'], 'showid': e['showid'], 'status': s['status'] }] for s in [ s['doc'] for s in sickrage.srCore.mainDB.db.all('tv_shows', with_doc=True) ]: for e in [ e['doc'] for e in sickrage.srCore.mainDB.db.get_many( 'tv_episodes', s['indexer_id'], with_doc=True) if e['doc']['season'] != 0 and today > e['doc']['airdate'] >= recently and e['doc']['status'] in [WANTED, UNAIRED] and e['doc']['status'] not in qualities_list ]: results += [{ 'airdate': e['airdate'], 'airs': s['airs'], 'description': e['description'], 'episode': e['episode'], 'imdb_id': s['imdb_id'], 'indexer': e['indexer'], 'indexer_id': s['indexer_id'], 'name': e['name'], 'network': s['network'], 'paused': s['paused'], 'quality': s['quality'], 'runtime': s['runtime'], 'season': e['season'], 'show_name': s['show_name'], 'showid': e['showid'], 'status': s['status'] }] for index, item in enumerate(results): results[index]['localtime'] = srDateTime.convert_to_setting( parse_date_time(item['airdate'], item['airs'], item['network'])) results.sort(ComingEpisodes.sorts[sort]) if not group: return results grouped_results = {category: [] for category in categories} for result in results: if result['paused'] and not paused: continue result['airs'] = str(result['airs']).replace('am', ' AM').replace( 'pm', ' PM').replace(' ', ' ') result['airdate'] = result['localtime'].toordinal() if result['airdate'] < today: category = 'missed' elif result['airdate'] >= next_week: category = 'later' elif result['airdate'] == today: category = 'today' else: category = 'soon' if len(categories) > 0 and category not in categories: continue if not result['network']: result['network'] = '' result['quality'] = get_quality_string(result['quality']) result['airs'] = srDateTime.srftime( result['localtime'], t_preset=timeFormat).lstrip('0').replace(' 0', ' ') result['weekday'] = 1 + datetime.date.fromordinal( result['airdate']).weekday() result['tvdbid'] = result['indexer_id'] result['airdate'] = srDateTime.srfdate(result['localtime'], d_preset=dateFormat) result['localtime'] = result['localtime'].toordinal() grouped_results[category].append(result) return grouped_results
def get_coming_episodes(categories, sort, group, paused=False): """ :param categories: The categories of coming episodes. See ``ComingEpisodes.categories`` :param sort: The sort to apply to the coming episodes. See ``ComingEpisodes.sorts`` :param group: ``True`` to group the coming episodes by category, ``False`` otherwise :param paused: ``True`` to include paused shows, ``False`` otherwise :return: The list of coming episodes """ def result(show, episode): return [{ 'airdate': episode['airdate'], 'airs': show.airs, 'description': episode['description'], 'episode': episode['episode'], 'imdb_id': show.imdbid, 'indexer': episode['indexer'], 'indexer_id': show.indexerid, 'name': episode['name'], 'network': show.network, 'paused': show.paused, 'quality': show.quality, 'runtime': show.runtime, 'season': episode['season'], 'show_name': show.name, 'showid': episode['showid'], 'status': show.status }] paused = sickrage.app.config.coming_eps_display_paused or paused if not isinstance(categories, list): categories = categories.split('|') if sort not in ComingEpisodes.sorts.keys(): sort = 'date' today = datetime.date.today().toordinal() next_week = (datetime.date.today() + datetime.timedelta(days=7)).toordinal() recently = ( datetime.date.today() - datetime.timedelta( days=sickrage.app.config.coming_eps_missed_range)).toordinal() qualities_list = Quality.DOWNLOADED + \ Quality.SNATCHED + \ Quality.SNATCHED_BEST + \ Quality.SNATCHED_PROPER + \ Quality.ARCHIVED + \ Quality.IGNORED results = [] for s in sickrage.app.showlist: for e in sickrage.app.main_db.get_many('tv_episodes', s.indexerid): if e['season'] != 0 and today <= e['airdate'] < next_week and e['status'] not in qualities_list: results += result(s, e) if e['season'] != 0 and e['showid'] not in [int(r['showid']) for r in results] \ and e['airdate'] >= next_week and e['status'] \ not in Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_BEST + Quality.SNATCHED_PROPER: results += result(s, e) if e['season'] != 0 and today > e['airdate'] >= recently \ and e['status'] in [WANTED, UNAIRED] and e['status'] not in qualities_list: results += result(s, e) for index, item in enumerate(results): results[index]['localtime'] = srDateTime( sickrage.app.tz_updater.parse_date_time(item['airdate'], item['airs'], item['network']), convert=True).dt results.sort(ComingEpisodes.sorts[sort]) if not group: return results grouped_results = {category: [] for category in categories} for result in results: if result['paused'] and not paused: continue result['airs'] = str(result['airs']).replace('am', ' AM').replace('pm', ' PM').replace(' ', ' ') result['airdate'] = result['localtime'].toordinal() if result['airdate'] < today: category = 'missed' elif result['airdate'] >= next_week: category = 'later' elif result['airdate'] == today: category = 'today' else: category = 'soon' if len(categories) > 0 and category not in categories: continue if not result['network']: result['network'] = '' result['quality'] = get_quality_string(result['quality']) result['airs'] = srDateTime(result['localtime']).srftime(t_preset=timeFormat).lstrip('0').replace(' 0', ' ') result['weekday'] = 1 + datetime.date.fromordinal(result['airdate']).weekday() result['tvdbid'] = result['indexer_id'] result['airdate'] = srDateTime(result['localtime']).srfdate(d_preset=dateFormat) result['localtime'] = result['localtime'].toordinal() grouped_results[category].append(result) return grouped_results