def get(self, show_id, session): """ Get episodes by show ID """ args = episode_parser.parse_args() # Pagination and sorting params page = args['page'] per_page = args['per_page'] sort_order = args['order'] # Handle max size limit if per_page > 100: per_page = 100 descending = sort_order == 'desc' start = per_page * (page - 1) stop = start + per_page kwargs = { 'start': start, 'stop': stop, 'descending': descending, 'session': session } try: show = series.show_by_id(show_id, session=session) except NoResultFound: raise NotFoundError('show with ID %s not found' % show_id) total_items = series.show_episodes(show, count=True, session=session) if not total_items: return jsonify([]) episodes = [episode.to_dict() for episode in series.show_episodes(show, **kwargs)] total_pages = int(ceil(total_items / float(per_page))) if total_pages < page and total_pages != 0: raise NotFoundError('page %s does not exist' % page) # Actual results in page actual_size = min(per_page, len(episodes)) # Get pagination headers pagination = pagination_headers(total_pages, total_items, actual_size, request) # Created response rsp = jsonify(episodes) # Add link header to response rsp.headers.extend(pagination) # Add series ID header rsp.headers.extend({'Series-ID': show_id}) return rsp
def get(self, show_id, session): """ Get episodes by show ID """ args = episode_parser.parse_args() page = args['page'] page_size = args['page_size'] # Handle max size limit if page_size > 100: page_size = 100 order = args['order'] # In case the default 'desc' order was received if order == 'desc': order = True else: order = False start = page_size * (page - 1) stop = start + page_size kwargs = { 'start': start, 'stop': stop, 'descending': order, 'session': session } try: show = series.show_by_id(show_id, session=session) except NoResultFound: return { 'status': 'error', 'message': 'Show with ID %s not found' % show_id }, 404 count = series.show_episodes(show, count=True, session=session) episodes = [ get_episode_details(episode) for episode in series.show_episodes(show, **kwargs) ] pages = int(ceil(count / float(page_size))) if page > pages and pages != 0: return { 'status': 'error', 'message': 'page does not exist' % show_id }, 500 return jsonify({ 'show': show.name, 'show_id': show_id, 'number_of_episodes': len(episodes), 'episodes': episodes, 'total_number_of_episodes': count, 'page': page, 'total_number_of_pages': pages })
def get(self, show_id, session): """ Get episodes by show ID """ args = episode_parser.parse_args() page = args['page'] page_size = args['page_size'] # Handle max size limit if page_size > 100: page_size = 100 order = args['order'] # In case the default 'desc' order was received if order == 'desc': order = True else: order = False start = page_size * (page - 1) stop = start + page_size kwargs = { 'start': start, 'stop': stop, 'descending': order, 'session': session } try: show = series.show_by_id(show_id, session=session) except NoResultFound: return {'status': 'error', 'message': 'Show with ID %s not found' % show_id }, 404 count = series.show_episodes(show, count=True, session=session) episodes = [get_episode_details(episode) for episode in series.show_episodes(show, **kwargs)] pages = int(ceil(count / float(page_size))) if page > pages and pages != 0: return {'status': 'error', 'message': 'page does not exist' % show_id }, 500 return jsonify({'show': show.name, 'show_id': show_id, 'number_of_episodes': len(episodes), 'episodes': episodes, 'total_number_of_episodes': count, 'page': page, 'total_number_of_pages': pages})
def display_details(name): """Display detailed series information, ie. series show NAME""" with Session() as session: name = normalize_series_name(name) # Sort by length of name, so that partial matches always show shortest matching title matches = shows_by_name(name, session=session) if not matches: console('ERROR: Unknown series `%s`' % name) return # Pick the best matching series series = matches[0] console('Showing results for `%s`.' % series.name) if len(matches) > 1: console('WARNING: Multiple series match to `%s`.' % name) console('Be more specific to see the results of other matches:') for s in matches[1:]: console(' - %s' % s.name) console(' %-63s%-15s' % ('Identifier, Title', 'Quality')) console('-' * 79) episodes = show_episodes(series, session=session) for episode in episodes: if episode.identifier is None: console(' None <--- Broken!') else: console(' %s (%s) - %s' % (episode.identifier, episode.identified_by or 'N/A', episode.age)) for release in episode.releases: status = release.quality.name title = release.title if len(title) > 55: title = title[:55] + '...' if release.proper_count > 0: status += '-proper' if release.proper_count > 1: status += str(release.proper_count) if release.downloaded: console(' * %-60s%-15s' % (title, status)) else: console(' %-60s%-15s' % (title, status)) console('-' * 79) console(' * = downloaded') if not series.identified_by: console('') console(' Series plugin is still learning which episode numbering mode is ') console(' correct for this series (identified_by: auto).') console(' Few duplicate downloads can happen with different numbering schemes') console(' during this time.') else: console(' Series uses `%s` mode to identify episode numbering (identified_by).' % series.identified_by) console(' See option `identified_by` for more information.') if series.begin: console(' Begin episode for this series set to `%s`.' % series.begin.identifier)
def display_details(options): """Display detailed series information, ie. series show NAME""" name = options.series_name with Session() as session: name = normalize_series_name(name) # Sort by length of name, so that partial matches always show shortest matching title matches = shows_by_name(name, session=session) if not matches: console(colorize(ERROR_COLOR, 'ERROR: Unknown series `%s`' % name)) return # Pick the best matching series series = matches[0] table_title = colorize('white', series.name) if len(matches) > 1: warning = ( colorize('red', ' WARNING: ') + 'Multiple series match to `{}`.\n ' 'Be more specific to see the results of other matches:\n\n' ' {}'.format(name, ', '.join(s.name for s in matches[1:]))) if not options.table_type == 'porcelain': console(warning) header = [ 'Episode ID', 'Latest age', 'Release titles', 'Release Quality', 'Proper' ] table_data = [header] episodes = show_episodes(series, session=session) for episode in episodes: if episode.identifier is None: identifier = colorize(ERROR_COLOR, 'MISSING') age = '' else: identifier = episode.identifier age = episode.age ep_data = [identifier, age] release_titles = [] release_qualities = [] release_propers = [] for release in episode.releases: title = release.title quality = release.quality.name if not release.downloaded: title = colorize(UNDOWNLOADED_RELEASE_COLOR, title) quality = quality else: title = colorize(DOWNLOADED_RELEASE_COLOR, title) quality = quality release_titles.append(title) release_qualities.append(quality) release_propers.append( 'Yes' if release.proper_count > 0 else '') ep_data.append('\n'.join(release_titles)) ep_data.append('\n'.join(release_qualities)) ep_data.append('\n'.join(release_propers)) table_data.append(ep_data) footer = (' %s %s\n' % (colorize(DOWNLOADED_RELEASE_COLOR, 'Downloaded'), colorize(UNDOWNLOADED_RELEASE_COLOR, 'Un-downloaded'))) if not series.identified_by: footer += ( '\n' ' Series plugin is still learning which episode numbering mode is \n' ' correct for this series (identified_by: auto).\n' ' Few duplicate downloads can happen with different numbering schemes\n' ' during this time.') else: footer += ' \n Series uses `%s` mode to identify episode numbering (identified_by).' % series.identified_by footer += ' \n See option `identified_by` for more information.\n' if series.begin: footer += ' Begin episode for this series set to `%s`.' % series.begin.identifier table = TerminalTable(options.table_type, table_data, table_title, drop_columns=[4, 3, 1]) try: console(table.output) except TerminalTableError as e: console('ERROR: %s' % str(e)) return if not options.table_type == 'porcelain': console(footer)
def display_details(options): """Display detailed series information, ie. series show NAME""" name = options.series_name with Session() as session: name = normalize_series_name(name) # Sort by length of name, so that partial matches always show shortest matching title matches = shows_by_name(name, session=session) if not matches: console(colorize(ERROR_COLOR, 'ERROR: Unknown series `%s`' % name)) return # Pick the best matching series series = matches[0] table_title = colorize('white', series.name) if len(matches) > 1: warning = (colorize('red', ' WARNING: ') + 'Multiple series match to `{}`.\n ' 'Be more specific to see the results of other matches:\n\n' ' {}'.format(name, ', '.join(s.name for s in matches[1:]))) if not options.table_type == 'porcelain': console(warning) header = ['Episode ID', 'Latest age', 'Release titles', 'Release Quality', 'Proper'] table_data = [header] episodes = show_episodes(series, session=session) for episode in episodes: if episode.identifier is None: identifier = colorize(ERROR_COLOR, 'MISSING') age = '' else: identifier = episode.identifier age = episode.age ep_data = [identifier, age] release_titles = [] release_qualities = [] release_propers = [] for release in episode.releases: title = release.title quality = release.quality.name if not release.downloaded: title = colorize(UNDOWNLOADED_RELEASE_COLOR, title) quality = quality else: title = colorize(DOWNLOADED_RELEASE_COLOR, title) quality = quality release_titles.append(title) release_qualities.append(quality) release_propers.append('Yes' if release.proper_count > 0 else '') ep_data.append('\n'.join(release_titles)) ep_data.append('\n'.join(release_qualities)) ep_data.append('\n'.join(release_propers)) table_data.append(ep_data) footer = (' %s %s\n' % (colorize(DOWNLOADED_RELEASE_COLOR, 'Downloaded'), colorize(UNDOWNLOADED_RELEASE_COLOR, 'Un-downloaded'))) if not series.identified_by: footer += ('\n' ' Series plugin is still learning which episode numbering mode is \n' ' correct for this series (identified_by: auto).\n' ' Few duplicate downloads can happen with different numbering schemes\n' ' during this time.') else: footer += ' \n Series uses `%s` mode to identify episode numbering (identified_by).' % series.identified_by footer += ' \n See option `identified_by` for more information.\n' if series.begin: footer += ' Begin episode for this series set to `%s`.' % series.begin.identifier table = TerminalTable(options.table_type, table_data, table_title, drop_columns=[4, 3, 1]) try: console(table.output) except TerminalTableError as e: console('ERROR: %s' % str(e)) return if not options.table_type == 'porcelain': console(footer)