Skip to content

Commit

Permalink
making an Edit mass mess
Browse files Browse the repository at this point in the history
  • Loading branch information
BKSteve committed Mar 9, 2024
1 parent 1f7b792 commit aba310b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 84 deletions.
2 changes: 1 addition & 1 deletion sickchill/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def try_int(candidate, default_value=0) -> int:
return default_value


def try_float(candidate, default_value=0):
def try_float(candidate, default_value=0) -> float:
"""
Try to convert ``candidate`` to int, or return the ``default_value``.
:param candidate: The value to convert to int
Expand Down
123 changes: 66 additions & 57 deletions sickchill/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ def plotDetails(self):
return result["description"] if result else "Episode not found."

def sceneExceptions(self):
show = self.get_query_argument("show")
show = try_int(self.get_query_argument("show"))
exeptions_list = sickchill.oldbeard.scene_exceptions.get_all_scene_exceptions(show)
if not exeptions_list:
return _("No scene exceptions")
Expand All @@ -1071,36 +1071,46 @@ def sceneExceptions(self):
out.append("S" + str(season) + ": " + ", ".join(exceptions.names))
return "<br>".join(out)

def editShow(self):
show_id = self.get_query_argument("show", default=None)
location = self.get_body_argument("location", default=None)
quality_preset = self.get_body_argument("quality_preset", default=None)
anyQualities = self.get_body_arguments("anyQualities")
bestQualities = self.get_body_arguments("bestQualities")
season_folders = config.checkbox_to_value(self.get_body_argument("season_folders", default="False"))
direct_call = config.checkbox_to_value(self.get_body_argument("directCall", default="False"))
if show_id is None:
show_id = self.get_body_argument("show")
banner = self.get_body_argument("banner", default=None)
blacklist = self.get_body_argument("blacklist", default=None)
custom_name = self.get_body_argument("custom_name", default="")
defaultEpStatus = self.get_body_argument("defaultEpStatus", default=None)
dvdorder = config.checkbox_to_value(self.get_body_argument("dvdorder", default="False"))
exceptions_list = self.get_body_argument("exceptions_list", default=None)
fanart = self.get_body_argument("fanart", default=None)
indexerLang = self.get_body_argument("indexerLang", default=None)
poster = self.get_body_argument("poster", default=None)
rls_ignore_words = self.get_body_argument("rls_ignore_words", default=None)
rls_prefer_words = self.get_body_argument("rls_prefer_words", default=None)
rls_require_words = self.get_body_argument("rls_require_words", default=None)
whitelist = self.get_body_argument("whitelist", default=None)
paused = config.checkbox_to_value(self.get_body_argument("paused", default="False"))
air_by_date = config.checkbox_to_value(self.get_body_argument("air_by_date", default="False"))
scene = config.checkbox_to_value(self.get_body_argument("scene", default="False"))
sports = config.checkbox_to_value(self.get_body_argument("sports", default="False"))
anime = config.checkbox_to_value(self.get_body_argument("anime", default="False"))
subtitles = config.checkbox_to_value(self.get_body_argument("subtitles", default="False"))
subtitles_sc_metadata = config.checkbox_to_value(self.get_body_argument("subtitles_sc_metadata", default="False"))
def editShow(self, direct_call=False):
if direct_call is False:
show_id = self.get_query_argument("show", default=None)
location = self.get_body_argument("location", default=None)
any_qualities = self.get_body_arguments("anyQualities")
best_qualities = self.get_body_arguments("bestQualities")
season_folders = config.checkbox_to_value(self.get_body_argument("season_folders", default="False"))
if show_id is None:
show_id = self.get_body_argument("show")
blacklist = self.get_body_argument("blacklist", default=None)
default_ep_status = self.get_body_argument("defaultEpStatus", default=None)
dvdorder = config.checkbox_to_value(self.get_body_argument("dvdorder", default="False"))
exceptions_list = self.get_body_argument("exceptions_list", default=None)
rls_ignore_words = self.get_body_argument("rls_ignore_words", default=None)
rls_prefer_words = self.get_body_argument("rls_prefer_words", default=None)
rls_require_words = self.get_body_argument("rls_require_words", default=None)
whitelist = self.get_body_argument("whitelist", default=None)
paused = config.checkbox_to_value(self.get_body_argument("paused", default="False"))
air_by_date = config.checkbox_to_value(self.get_body_argument("air_by_date", default="False"))
scene = config.checkbox_to_value(self.get_body_argument("scene", default="False"))
sports = config.checkbox_to_value(self.get_body_argument("sports", default="False"))
anime = config.checkbox_to_value(self.get_body_argument("anime", default="False"))
subtitles = config.checkbox_to_value(self.get_body_argument("subtitles", default="False"))
else:
show_id = self.current_show
location = self.new_show_dir
any_qualities = self.any_qualities
best_qualities = self.best_qualities
exceptions_list = self.exceptions_list
default_ep_status = self.new_default_ep_status
season_folders = self.new_season_folders
paused = self.new_paused
sports = self.new_sports
subtitles = self.new_subtitles
rls_ignore_words = self.new_ignore_words
rls_prefer_words = self.new_prefer_words
rls_require_words = self.new_require_words
anime = self.new_anime
scene = self.new_scene
air_by_date = self.new_air_by_date

anidb_failed = False

Expand All @@ -1125,10 +1135,7 @@ def editShow(self):
"SELECT DISTINCT season FROM tv_episodes WHERE showid = ? AND season IS NOT NULL ORDER BY season DESC", [show_obj.indexerid]
)

if try_int(quality_preset, None):
bestQualities = []

if not (location or anyQualities or bestQualities or season_folders):
if not (location or any_qualities or best_qualities or season_folders):
t = PageTemplate(rh=self, filename="editShow.mako")
groups = []

Expand All @@ -1144,12 +1151,9 @@ def editShow(self):
ui.notifications.error(_("Unable to retrieve Fansub Groups from AniDB."))
logger.debug(f"Unable to retrieve Fansub Groups from AniDB. Error is {error}")

with show_obj.lock:
show = show_obj

if show_obj.is_anime:
return t.render(
show=show,
show=show_obj,
scene_exceptions=show_obj.exceptions,
seasonResults=seasonResults,
groups=groups,
Expand All @@ -1162,7 +1166,7 @@ def editShow(self):
)
else:
return t.render(
show=show,
show=show_obj,
scene_exceptions=show_obj.exceptions,
seasonResults=seasonResults,
title=_("Edit Show"),
Expand All @@ -1171,29 +1175,34 @@ def editShow(self):
action="editShow",
)

if indexerLang and indexerLang in show_obj.idxr.languages:
indexer_lang = indexerLang
else:
banner = self.get_body_argument("banner", default=None)
fanart = self.get_body_argument("fanart", default=None)
poster = self.get_body_argument("poster", default=None)
indexer_lang = self.get_body_argument("indexerLang", default=None)
custom_name = self.get_body_argument("custom_name", default="")
subtitles_sc_metadata = config.checkbox_to_value(self.get_body_argument("subtitles_sc_metadata", default="False"))

if not indexer_lang or indexer_lang not in show_obj.idxr.languages:
indexer_lang = show_obj.lang

# if we changed the language then kick off an update
do_update = indexer_lang != show_obj.lang
do_update_scene_numbering = scene != show_obj.scene or anime != show_obj.anime

if not anyQualities:
anyQualities = []
if not any_qualities:
any_qualities = []

if not bestQualities:
bestQualities = []
if not best_qualities:
best_qualities = []

if not exceptions_list:
exceptions_list = []

if not isinstance(anyQualities, list):
anyQualities = [anyQualities]
if not isinstance(any_qualities, list):
any_qualities = [any_qualities]

if not isinstance(bestQualities, list):
bestQualities = [bestQualities]
if not isinstance(best_qualities, list):
best_qualities = [best_qualities]

if isinstance(exceptions_list, list):
if exceptions_list:
Expand Down Expand Up @@ -1276,8 +1285,8 @@ def get_images(image):

errors = []
with show_obj.lock:
newQuality = Quality.combineQualities([int(q) for q in anyQualities], [int(q) for q in bestQualities])
show_obj.quality = newQuality
new_quality = Quality.combineQualities([int(q) for q in any_qualities], [int(q) for q in best_qualities])
show_obj.quality = new_quality

if bool(show_obj.season_folders) != season_folders:
show_obj.season_folders = season_folders
Expand All @@ -1292,7 +1301,7 @@ def get_images(image):
show_obj.subtitles = subtitles
show_obj.subtitles_sc_metadata = subtitles_sc_metadata
show_obj.air_by_date = air_by_date
show_obj.default_ep_status = int(defaultEpStatus)
show_obj.default_ep_status = default_ep_status
# words added to mass update so moved from direct_call to here.
show_obj.rls_ignore_words = rls_ignore_words.strip()
show_obj.rls_require_words = rls_require_words.strip()
Expand All @@ -1301,15 +1310,15 @@ def get_images(image):
if not direct_call:
show_obj.lang = indexer_lang
show_obj.dvdorder = dvdorder
location = self.get_argument("location", show_obj.get_location)
location = self.get_body_argument("location", show_obj.get_location)

location = os.path.normpath(location)

# noinspection PyProtectedMember
old_location = os.path.normpath(show_obj.get_location)
# if we change location clear the db of episodes, change it, write to db, and rescan
if old_location != location:
logger.debug(old_location + " != " + location)
logger.debug(f"Changing old location {old_location} to new location {location}")
if not (os.path.isdir(location) or settings.CREATE_MISSING_SHOW_DIRS or settings.ADD_SHOWS_WO_DIR):
errors.append(_("New location <tt>{location}</tt> does not exist").format(location=location))
else:
Expand Down Expand Up @@ -1354,7 +1363,7 @@ def get_images(image):
except CantUpdateShowException:
errors.append(_("Unable to force an update on scene numbering of the show."))

if direct_call:
if direct_call is True:
return errors

if errors:
Expand Down
51 changes: 25 additions & 26 deletions sickchill/views/manage/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,14 @@ def massEditSubmit(self):
else:
new_show_dir = show_object.get_location

new_paused = ("off", "on")[(paused == "enable", show_object.paused)[paused == "keep"]]
new_paused = (0, 1)[(paused == "enable", show_object.paused)[paused == "keep"]]
new_default_ep_status = (default_ep_status, show_object.default_ep_status)[default_ep_status == "keep"]
new_anime = ("off", "on")[(anime == "enable", show_object.anime)[anime == "keep"]]
new_sports = ("off", "on")[(sports == "enable", show_object.sports)[sports == "keep"]]
new_scene = ("off", "on")[(scene == "enable", show_object.scene)[scene == "keep"]]
new_air_by_date = ("off", "on")[(air_by_date == "enable", show_object.air_by_date)[air_by_date == "keep"]]
new_season_folders = ("off", "on")[(season_folders == "enable", show_object.season_folders)[season_folders == "keep"]]
new_subtitles = ("off", "on")[(subtitles == "enable", show_object.subtitles)[subtitles == "keep"]]
new_anime = (0, 1)[(anime == "enable", show_object.anime)[anime == "keep"]]
new_sports = (0, 1)[(sports == "enable", show_object.sports)[sports == "keep"]]
new_scene = (0, 1)[(scene == "enable", show_object.scene)[scene == "keep"]]
new_air_by_date = (0, 1)[(air_by_date == "enable", show_object.air_by_date)[air_by_date == "keep"]]
new_season_folders = (0, 1)[(season_folders == "enable", show_object.season_folders)[season_folders == "keep"]]
new_subtitles = (0, 1)[(subtitles == "enable", show_object.subtitles)[subtitles == "keep"]]

# new mass words update section
if ignore_words == "new":
Expand Down Expand Up @@ -591,25 +591,24 @@ def massEditSubmit(self):

exceptions_list = []

current_show_errors += self.editShow(
current_show,
new_show_dir,
any_qualities,
best_qualities,
exceptions_list,
defaultEpStatus=new_default_ep_status,
season_folders=new_season_folders,
paused=new_paused,
sports=new_sports,
subtitles=new_subtitles,
rls_ignore_words=new_ignore_words,
rls_prefer_words=new_prefer_words,
rls_require_words=new_require_words,
anime=new_anime,
scene=new_scene,
air_by_date=new_air_by_date,
directCall=True,
)
self.current_show = current_show
self.new_show_dir = new_show_dir
self.any_qualities = any_qualities
self.best_qualities = best_qualities
self.exceptions_list = exceptions_list
self.new_default_ep_status = new_default_ep_status
self.new_season_folders = new_season_folders
self.new_paused = new_paused
self.new_sports = new_sports
self.new_subtitles = new_subtitles
self.new_ignore_words = new_ignore_words
self.new_prefer_words = new_prefer_words
self.new_require_words = new_require_words
self.new_anime = new_anime
self.new_scene = new_scene
self.new_air_by_date = new_air_by_date

current_show_errors += self.editShow(direct_call=True)

if current_show_errors:
logger.exception(f"Errors: {current_show_errors}")
Expand Down

0 comments on commit aba310b

Please sign in to comment.