def patch(self, series_slug): warnings, errors = [], [] do_update = False do_update_exceptions = False data = json_decode(self.request.body) series = find_show_by_slug(series_slug) if series is None: return self.send_error( 404, error= f"Unable to find the specified series using slug: {series_slug}" ) # if we changed the language then kick off an update if data.get('lang') is not None and data['lang'] != series.lang: do_update = True if data.get('paused') is not None: series.paused = checkbox_to_value(data['paused']) if data.get('anime') is not None: series.anime = checkbox_to_value(data['anime']) if data.get('scene') is not None: series.scene = checkbox_to_value(data['scene']) if data.get('searchFormat') is not None: series.search_format = SearchFormat[data['searchFormat']] if data.get('subtitles') is not None: series.subtitles = checkbox_to_value(data['subtitles']) if data.get('subUseSrMetadata') is not None: series.sub_use_sr_metadata = checkbox_to_value( data['subUseSrMetadata']) if data.get('defaultEpStatus') is not None: series.default_ep_status = int(data['defaultEpStatus']) if data.get('skipDownloaded') is not None: series.skip_downloaded = checkbox_to_value(data['skipDownloaded']) if data.get('sceneExceptions') is not None and set( data['sceneExceptions']) != set(series.scene_exceptions): do_update_exceptions = True if data.get('whitelist') is not None: shortwhitelist = short_group_names(data['whitelist']) series.release_groups.set_white_keywords(shortwhitelist) if data.get('blacklist') is not None: shortblacklist = short_group_names(data['blacklist']) series.release_groups.set_black_keywords(shortblacklist) if data.get('qualityPreset') is not None: try: new_quality = Qualities[data['qualityPreset']] except KeyError: new_quality = Quality.combine_qualities( [Qualities[x] for x in data['allowedQualities']], [Qualities[x] for x in data['preferredQualities']]) series.quality = new_quality if data.get('flattenFolders') is not None and bool( series.flatten_folders) != bool(data['flattenFolders']): series.flatten_folders = data['flattenFolders'] try: sickrage.app.show_queue.refresh_show(series.series_id, series.series_provider_id, True) except CantRefreshShowException as e: errors.append(_(f"Unable to refresh this show: {e}")) if data.get('language') is not None: series.lang = data['language'] if data.get('dvdOrder') is not None: series.dvd_order = checkbox_to_value(data['dvdOrder']) if data.get('rlsIgnoreWords') is not None: series.rls_ignore_words = data['rlsIgnoreWords'] if data.get('rlsRequireWords') is not None: series.rls_require_words = data['rlsRequireWords'] # series.search_delay = int(data['search_delay']) # if we change location clear the db of episodes, change it, write to db, and rescan if data.get('location') is not None and os.path.normpath( series.location) != os.path.normpath(data['location']): sickrage.app.log.debug( os.path.normpath(series.location) + " != " + os.path.normpath(data['location'])) if not os.path.isdir( data['location'] ) and not sickrage.app.config.general.create_missing_show_dirs: warnings.append( f"New location {data['location']} does not exist") # don't bother if we're going to update anyway elif not do_update: # change it try: series.location = data['location'] try: sickrage.app.show_queue.refresh_show( series.series_id, series.series_provider_id, True) except CantRefreshShowException as e: errors.append(_(f"Unable to refresh this show: {e}")) # grab updated info from TVDB # showObj.loadEpisodesFromSeriesProvider() # rescan the episodes in the new folder except NoNFOException: warnings.append( _(f"The folder at {data['location']} doesn't contain a tvshow.nfo - copy your files to that folder before you change the directory in SiCKRAGE." )) # force the update if do_update: try: sickrage.app.show_queue.update_show(series.series_id, series.series_provider_id, force=True) except CantUpdateShowException as e: errors.append(_(f"Unable to update show: {e}")) if do_update_exceptions: try: series.scene_exceptions = set( data['sceneExceptions'].split(',')) except CantUpdateShowException: warnings.append( _("Unable to force an update on scene exceptions of the show." )) # if do_update_scene_numbering: # try: # xem_refresh(series.series_id, series.series_provider_id, True) # except CantUpdateShowException: # warnings.append(_("Unable to force an update on scene numbering of the show.")) # commit changes to database series.save() return self.write_json(series.to_json(episodes=True, details=True))
async def post(self, *args, **kwargs): """ Receive tvdb id, dir, and other options and create a show from them. If extra show dirs are provided then it forwards back to newShow, if not it goes to /home. """ whichSeries = self.get_argument('whichSeries', None) rootDir = self.get_argument('rootDir', None) fullShowPath = self.get_argument('fullShowPath', None) providedName = self.get_argument('providedName', None) indexerLang = self.get_argument('indexerLang', None) defaultStatus = self.get_argument('defaultStatus', None) quality_preset = self.get_argument('quality_preset', None) anyQualities = self.get_arguments('anyQualities') bestQualities = self.get_arguments('bestQualities') flatten_folders = self.get_argument('flatten_folders', None) subtitles = self.get_argument('subtitles', None) sub_use_sr_metadata = self.get_argument('sub_use_sr_metadata', None) other_shows = self.get_arguments('other_shows') skipShow = self.get_argument('skipShow', None) providedIndexer = self.get_argument('providedIndexer', None) anime = self.get_argument('anime', None) scene = self.get_argument('scene', None) blacklist = self.get_argument('blacklist', None) whitelist = self.get_argument('whitelist', None) defaultStatusAfter = self.get_argument('defaultStatusAfter', None) skip_downloaded = self.get_argument('skip_downloaded', None) add_show_year = self.get_argument('add_show_year', None) indexerLang = indexerLang or sickrage.app.config.indexer_default_language # if we're skipping then behave accordingly if skipShow: return self.write(await self.finish_add_show(other_shows)) if not whichSeries: return self.redirect("/home/") # figure out what show we're adding and where series_pieces = whichSeries.split('|') if (whichSeries and rootDir or whichSeries and fullShowPath) and len(series_pieces) > 1: if len(series_pieces) < 6: sickrage.app.log.error( 'Unable to add show due to show selection. Not anough arguments: %s' % (repr(series_pieces))) sickrage.app.alerts.error( _('Unknown error. Unable to add show due to problem with show selection.' )) return self.redirect('/home/addShows/existingShows/') indexer = int(series_pieces[1]) indexer_id = int(series_pieces[3]) show_name = series_pieces[4] else: indexer = int(providedIndexer or sickrage.app.config.indexer_default) indexer_id = int(whichSeries) if fullShowPath: show_name = os.path.basename(os.path.normpath(fullShowPath)) else: show_name = providedName # use the whole path if it's given, or else append the show name to the root dir to get the full show path if fullShowPath: show_dir = os.path.normpath(fullShowPath) else: show_dir = os.path.join(rootDir, sanitize_file_name(show_name)) if add_show_year and not re.match(r'.*\(\d+\)$', show_dir) and re.search( r'\d{4}', series_pieces[5]): show_dir = "{} ({})".format( show_dir, re.search(r'\d{4}', series_pieces[5]).group(0)) # blanket policy - if the dir exists you should have used "add existing show" numbnuts if os.path.isdir(show_dir) and not fullShowPath: sickrage.app.alerts.error( _("Unable to add show"), _("Folder ") + show_dir + _(" exists already")) return self.redirect('/home/addShows/existingShows/') # don't create show dir if config says not to if sickrage.app.config.add_shows_wo_dir: sickrage.app.log.info("Skipping initial creation of " + show_dir + " due to SiCKRAGE configuation setting") else: dir_exists = make_dir(show_dir) if not dir_exists: sickrage.app.log.warning("Unable to create the folder " + show_dir + ", can't add the show") sickrage.app.alerts.error( _("Unable to add show"), _("Unable to create the folder " + show_dir + ", can't add the show")) # Don't redirect to default page because user wants to see the new show return self.redirect("/home/") else: chmod_as_parent(show_dir) # prepare the inputs for passing along scene = checkbox_to_value(scene) anime = checkbox_to_value(anime) flatten_folders = checkbox_to_value(flatten_folders) subtitles = checkbox_to_value(subtitles) sub_use_sr_metadata = checkbox_to_value(sub_use_sr_metadata) skip_downloaded = checkbox_to_value(skip_downloaded) if whitelist: whitelist = short_group_names(whitelist) if blacklist: blacklist = short_group_names(blacklist) newQuality = try_int(quality_preset, None) if not newQuality: newQuality = Quality.combine_qualities(map(int, anyQualities), map(int, bestQualities)) # add the show sickrage.app.show_queue.add_show( indexer=indexer, indexer_id=indexer_id, showDir=show_dir, default_status=int(defaultStatus), quality=newQuality, flatten_folders=flatten_folders, lang=indexerLang, subtitles=subtitles, sub_use_sr_metadata=sub_use_sr_metadata, anime=anime, scene=scene, paused=None, blacklist=blacklist, whitelist=whitelist, default_status_after=int(defaultStatusAfter), skip_downloaded=skip_downloaded) sickrage.app.alerts.message( _('Adding Show'), _('Adding the specified show into ') + show_dir) return self.write(await self.finish_add_show(other_shows))
def edit_show(show, any_qualities, best_qualities, exceptions_list, location=None, flatten_folders=None, paused=None, direct_call=None, air_by_date=None, sports=None, dvdorder=None, indexer_lang=None, subtitles=None, sub_use_sr_metadata=None, skip_downloaded=None, rls_ignore_words=None, rls_require_words=None, anime=None, blacklist=None, whitelist=None, scene=None, default_ep_status=None, quality_preset=None, search_delay=None, session=None): show_obj = find_show(int(show), session=session) if not show_obj: err_msg = _("Unable to find the specified show: ") + str(show) if direct_call: sickrage.app.alerts.error(_('Error'), err_msg) return False, err_msg show_obj.exceptions = get_scene_exceptions(show_obj.indexer_id) flatten_folders = not checkbox_to_value(flatten_folders) # UI inverts this value dvdorder = checkbox_to_value(dvdorder) skip_downloaded = checkbox_to_value(skip_downloaded) paused = checkbox_to_value(paused) air_by_date = checkbox_to_value(air_by_date) scene = checkbox_to_value(scene) sports = checkbox_to_value(sports) anime = checkbox_to_value(anime) subtitles = checkbox_to_value(subtitles) sub_use_sr_metadata = checkbox_to_value(sub_use_sr_metadata) if indexer_lang and indexer_lang in IndexerApi(show_obj.indexer).indexer().languages.keys(): indexer_lang = indexer_lang else: indexer_lang = show_obj.lang # if we changed the language then kick off an update if indexer_lang == show_obj.lang: do_update = False else: do_update = True if scene == show_obj.scene or anime == show_obj.anime: do_update_scene_numbering = False else: do_update_scene_numbering = True show_obj.paused = paused show_obj.scene = scene show_obj.anime = anime show_obj.sports = sports show_obj.subtitles = subtitles show_obj.sub_use_sr_metadata = sub_use_sr_metadata show_obj.air_by_date = air_by_date show_obj.default_ep_status = int(default_ep_status) show_obj.skip_downloaded = skip_downloaded # If directCall from mass_edit_update no scene exceptions handling or blackandwhite list handling if direct_call: do_update_exceptions = False else: if set(exceptions_list) == set(show_obj.exceptions): do_update_exceptions = False else: do_update_exceptions = True if anime: if whitelist: shortwhitelist = short_group_names(whitelist) show_obj.release_groups.set_white_keywords(shortwhitelist) else: show_obj.release_groups.set_white_keywords([]) if blacklist: shortblacklist = short_group_names(blacklist) show_obj.release_groups.set_black_keywords(shortblacklist) else: show_obj.release_groups.set_black_keywords([]) warnings, errors = [], [] new_quality = try_int(quality_preset, None) if not new_quality: new_quality = Quality.combine_qualities(list(map(int, any_qualities)), list(map(int, best_qualities))) show_obj.quality = new_quality # reversed for now if bool(show_obj.flatten_folders) != bool(flatten_folders): show_obj.flatten_folders = flatten_folders try: sickrage.app.show_queue.refresh_show(show_obj.indexer_id, True) except CantRefreshShowException as e: errors.append(_("Unable to refresh this show: {}").format(e)) if not direct_call: show_obj.lang = indexer_lang show_obj.dvdorder = dvdorder show_obj.rls_ignore_words = rls_ignore_words.strip() show_obj.rls_require_words = rls_require_words.strip() show_obj.search_delay = int(search_delay) # if we change location clear the db of episodes, change it, write to db, and rescan if os.path.normpath(show_obj.location) != os.path.normpath(location): sickrage.app.log.debug(os.path.normpath(show_obj.location) + " != " + os.path.normpath(location)) if not os.path.isdir(location) and not sickrage.app.config.create_missing_show_dirs: warnings.append("New location {} does not exist".format(location)) # don't bother if we're going to update anyway elif not do_update: # change it try: show_obj.location = location try: sickrage.app.show_queue.refresh_show(show_obj.indexer_id, True) except CantRefreshShowException as e: errors.append(_("Unable to refresh this show:{}").format(e)) # grab updated info from TVDB # showObj.loadEpisodesFromIndexer() # rescan the episodes in the new folder except NoNFOException: warnings.append( _("The folder at %s doesn't contain a tvshow.nfo - copy your files to that folder before " "you change the directory in SiCKRAGE.") % location) # force the update if do_update: try: sickrage.app.show_queue.update_show(show_obj.indexer_id, force=True) except CantUpdateShowException as e: errors.append(_("Unable to update show: {}").format(e)) if do_update_exceptions: try: update_scene_exceptions(show_obj.indexer_id, exceptions_list) except CantUpdateShowException: warnings.append(_("Unable to force an update on scene exceptions of the show.")) if do_update_scene_numbering: try: xem_refresh(show_obj.indexer_id, show_obj.indexer, True) except CantUpdateShowException: warnings.append(_("Unable to force an update on scene numbering of the show.")) if direct_call: return True if len(warnings) == 0 and len(errors) == 0 else False, json_encode({'warnings': warnings, 'errors': errors}) if len(warnings) > 0: sickrage.app.alerts.message( _('{num_warnings:d} warning{plural} while saving changes:').format(num_warnings=len(warnings), plural="" if len( warnings) == 1 else "s"), '<ul>' + '\n'.join(['<li>{0}</li>'.format(warning) for warning in warnings]) + "</ul>") if len(errors) > 0: sickrage.app.alerts.error( _('{num_errors:d} error{plural} while saving changes:').format(num_errors=len(errors), plural="" if len(errors) == 1 else "s"), '<ul>' + '\n'.join(['<li>{0}</li>'.format(error) for error in errors]) + "</ul>") return True, ""