def put(self, show_id, season_id, rel_id, session): """ Resets a downloaded release status """ try: series.show_by_id(show_id, session=session) except NoResultFound: raise NotFoundError('show with ID %s not found' % show_id) try: series.season_by_id(season_id, session) except NoResultFound: raise NotFoundError('season with ID %s not found' % season_id) try: release = series.season_release_by_id(rel_id, session) except NoResultFound: raise NotFoundError('release with ID %s not found' % rel_id) if not series.season_in_show(show_id, season_id): raise BadRequest('season with id %s does not belong to show %s' % (season_id, show_id)) if not series.release_in_season(season_id, rel_id): raise BadRequest('release id %s does not belong to episode %s' % (rel_id, season_id)) if not release.downloaded: raise BadRequest('release with id %s is not set as downloaded' % rel_id) release.downloaded = False rsp = jsonify(release.to_dict()) rsp.headers.extend({ 'Series-ID': show_id, 'Season-ID': season_id }) return rsp
def get(self, show_id, season_id, rel_id, session): """ Get season release by show ID, season ID and release ID """ try: series.show_by_id(show_id, session=session) except NoResultFound: raise NotFoundError('show with ID %s not found' % show_id) try: series.season_by_id(season_id, session) except NoResultFound: raise NotFoundError('season with ID %s not found' % season_id) try: release = series.season_release_by_id(rel_id, session) except NoResultFound: raise NotFoundError('release with ID %s not found' % rel_id) if not series.season_in_show(show_id, season_id): raise BadRequest('season with id %s does not belong to show %s' % (season_id, show_id)) if not series.release_in_season(season_id, rel_id): raise BadRequest('release id %s does not belong to season %s' % (rel_id, season_id)) rsp = jsonify(release.to_dict()) rsp.headers.extend({ 'Series-ID': show_id, 'Season-ID': season_id }) return rsp
def delete(self, show_id, season_id, session): """ Deletes all season releases by show ID and season ID """ try: series.show_by_id(show_id, session=session) except NoResultFound: raise NotFoundError('show with ID %s not found' % show_id) try: season = series.season_by_id(season_id, session) except NoResultFound: raise NotFoundError('seasons with ID %s not found' % season_id) if not series.season_in_show(show_id, season_id): raise BadRequest('season with id %s does not belong to show %s' % (season_id, show_id)) args = release_delete_parser.parse_args() downloaded = args.get('downloaded') is True if args.get('downloaded') is not None else None release_items = [] for release in season.releases: if downloaded and release.downloaded or downloaded is False and not release.downloaded or not downloaded: release_items.append(release) for release in release_items: if args.get('forget'): fire_event('forget', release.title) series.delete_season_release_by_id(release.id) return success_response('successfully deleted all releases for season %s from show %s' % (season_id, show_id))
def delete(self, show_id, season_id, rel_id, session): """ Delete episode release by show ID, season ID and release ID """ try: series.show_by_id(show_id, session=session) except NoResultFound: raise NotFoundError('show with ID %s not found' % show_id) try: series.season_by_id(season_id, session) except NoResultFound: raise NotFoundError('season with ID %s not found' % season_id) try: release = series.season_release_by_id(rel_id, session) except NoResultFound: raise NotFoundError('release with ID %s not found' % rel_id) if not series.season_in_show(show_id, season_id): raise BadRequest('season with id %s does not belong to show %s' % (season_id, show_id)) if not series.release_in_season(season_id, rel_id): raise BadRequest('release id %s does not belong to season %s' % (rel_id, season_id)) args = delete_parser.parse_args() if args.get('forget'): fire_event('forget', release.title) series.delete_season_release_by_id(rel_id) return success_response('successfully deleted release %d from season %d' % (rel_id, season_id))
def delete(self, show_id, season_id, session): """ Forgets season by show ID and season ID """ try: show = series.show_by_id(show_id, session=session) except NoResultFound: raise NotFoundError('show with ID %s not found' % show_id) try: season = series.season_by_id(season_id, session) except NoResultFound: raise NotFoundError('season with ID %s not found' % season_id) if not series.season_in_show(show_id, season_id): raise BadRequest('season with id %s does not belong to show %s' % (season_id, show_id)) args = delete_parser.parse_args() series.remove_series_entity(show.name, season.identifier, args.get('forget')) return success_response('successfully removed season %s from show %s' % (season_id, show_id))
def get(self, show_id, season_id, session): """ Get season by show ID and season ID""" try: series.show_by_id(show_id, session=session) except NoResultFound: raise NotFoundError('show with ID %s not found' % show_id) try: season = series.season_by_id(season_id, session) except NoResultFound: raise NotFoundError('season with ID %s not found' % season_id) if not series.season_in_show(show_id, season_id): raise BadRequest('season with id %s does not belong to show %s' % (season_id, show_id)) rsp = jsonify(season.to_dict()) # Add Series-ID header rsp.headers.extend({'Series-ID': show_id}) return rsp
def put(self, show_id, season_id, session): """ Marks all downloaded season releases as not downloaded """ try: series.show_by_id(show_id, session=session) except NoResultFound: raise NotFoundError('show with ID %s not found' % show_id) try: season = series.season_by_id(season_id, session) except NoResultFound: raise NotFoundError('season with ID %s not found' % season_id) if not series.season_in_show(show_id, season_id): raise BadRequest('season with id %s does not belong to show %s' % (season_id, show_id)) for release in season.releases: if release.downloaded: release.downloaded = False return success_response('successfully reset download status for all releases for season %s from show %s' % (season_id, show_id))
def get(self, show_id, season_id, session): """ Get all season releases by show ID and season ID """ try: series.show_by_id(show_id, session=session) except NoResultFound: raise NotFoundError('show with ID %s not found' % show_id) try: season = series.season_by_id(season_id, session) except NoResultFound: raise NotFoundError('season with ID %s not found' % season_id) if not series.season_in_show(show_id, season_id): raise BadRequest('seasons with id %s does not belong to show %s' % (season_id, show_id)) args = release_list_parser.parse_args() # Filter params downloaded = args.get('downloaded') # Pagination and sorting params page = args['page'] per_page = args['per_page'] sort_by = args['sort_by'] sort_order = args['order'] descending = sort_order == 'desc' # Handle max size limit if per_page > 100: per_page = 100 start = per_page * (page - 1) stop = start + per_page kwargs = { 'downloaded': downloaded, 'start': start, 'stop': stop, 'sort_by': sort_by, 'descending': descending, 'season': season, 'session': session } # Total number of releases total_items = series.get_season_releases(count=True, **kwargs) # Release items release_items = [release.to_dict() for release in series.get_season_releases(**kwargs)] # Total number of pages 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(release_items)) # Get pagination headers pagination = pagination_headers(total_pages, total_items, actual_size, request) # Created response rsp = jsonify(release_items) # Add link header to response rsp.headers.extend(pagination) # Add Series-ID and Episode-ID headers rsp.headers.extend({'Series-ID': show_id, 'Season-ID': season_id}) return rsp