From 37f021feb6d507f06114a6d47525e06c131dada0 Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 28 Sep 2014 17:20:42 +0800 Subject: [PATCH] Custom naming for anime --- .../default/config_postProcessing.tmpl | 287 ++++++++++++++---- gui/slick/js/configPostProcessing.js | 151 +++++++-- sickbeard/__init__.py | 11 +- sickbeard/naming.py | 2 + sickbeard/tv.py | 4 + sickbeard/webserve.py | 16 +- 6 files changed, 396 insertions(+), 75 deletions(-) diff --git a/gui/slick/interfaces/default/config_postProcessing.tmpl b/gui/slick/interfaces/default/config_postProcessing.tmpl index 8d83983a..0e7c91f7 100644 --- a/gui/slick/interfaces/default/config_postProcessing.tmpl +++ b/gui/slick/interfaces/default/config_postProcessing.tmpl @@ -477,59 +477,7 @@
-
-

Single-EP Anime Sample:

-
-   -
-
-
- -
-

Multi-EP Anime sample:

-
-   -
-
-
- -
- - - -
-
- - - -
- -
- - - -
- -
+ +
+ + +
+ +
+
+ +
+ +
+
+ +
+ + +
+ +
+ +
+ +
+

Single-EP Anime Sample:

+
+   +
+
+
+ +
+

Multi-EP Anime sample:

+
+   +
+
+
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+

diff --git a/gui/slick/js/configPostProcessing.js b/gui/slick/js/configPostProcessing.js index 0061ba86..9946d3d9 100644 --- a/gui/slick/js/configPostProcessing.js +++ b/gui/slick/js/configPostProcessing.js @@ -51,26 +51,6 @@ $(document).ready(function () { } }); - $.get(sbRoot + '/config/postProcessing/testNaming', {pattern: pattern, anime_type: anime_type}, - function (data) { - if (data) { - $('#naming_example_anime').text(data + '.ext'); - $('#naming_example_anime_div').show(); - } else { - $('#naming_example_anime_div').hide(); - } - }); - - $.get(sbRoot + '/config/postProcessing/testNaming', {pattern: pattern, multi: multi, anime_type: anime_type}, - function (data) { - if (data) { - $('#naming_example_multi_anime').text(data + '.ext'); - $('#naming_example_multi_anime_div').show(); - } else { - $('#naming_example_multi_anime_div').hide(); - } - }); - $.get(sbRoot + '/config/postProcessing/isNamingValid', {pattern: pattern, multi: multi, anime_type: anime_type}, function (data) { if (data == "invalid") { @@ -181,6 +161,99 @@ $(document).ready(function () { } + function fill_sports_examples() { + var pattern = $('#naming_sports_pattern').val(); + + $.get(sbRoot + '/config/postProcessing/testNaming', {pattern: pattern, sports: 'True'}, + function (data) { + if (data) { + $('#naming_sports_example').text(data + '.ext'); + $('#naming_sports_example_div').show(); + } else { + $('#naming_sports_example_div').hide(); + } + }); + + $.get(sbRoot + '/config/postProcessing/isNamingValid', {pattern: pattern, sports: 'True'}, + function (data) { + if (data == "invalid") { + $('#naming_sports_pattern').qtip('option', { + 'content.text': 'This pattern is invalid.', + 'style.classes': 'qtip-rounded qtip-shadow qtip-red' + }); + $('#naming_sports_pattern').qtip('toggle', true); + $('#naming_sports_pattern').css('background-color', '#FFDDDD'); + } else if (data == "seasonfolders") { + $('#naming_sports_pattern').qtip('option', { + 'content.text': 'This pattern would be invalid without the folders, using it will force "Flatten" off for all shows.', + 'style.classes': 'qtip-rounded qtip-shadow qtip-red' + }); + $('#naming_sports_pattern').qtip('toggle', true); + $('#naming_sports_pattern').css('background-color', '#FFFFDD'); + } else { + $('#naming_sports_pattern').qtip('option', { + 'content.text': 'This pattern is valid.', + 'style.classes': 'qtip-rounded qtip-shadow qtip-green' + }); + $('#naming_sports_pattern').qtip('toggle', false); + $('#naming_sports_pattern').css('background-color', '#FFFFFF'); + } + }); + + } + + function fill_anime_examples() { + var pattern = $('#naming_anime_pattern').val(); + var multi = $('#naming_anime_multi_ep :selected').val(); + var anime_type = $('input[name="naming_anime"]:checked').val(); + + $.get(sbRoot + '/config/postProcessing/testNaming', {pattern: pattern, anime_type: anime_type}, + function (data) { + if (data) { + $('#naming_example_anime').text(data + '.ext'); + $('#naming_example_anime_div').show(); + } else { + $('#naming_example_anime_div').hide(); + } + }); + + $.get(sbRoot + '/config/postProcessing/testNaming', {pattern: pattern, multi: multi, anime_type: anime_type}, + function (data) { + if (data) { + $('#naming_example_multi_anime').text(data + '.ext'); + $('#naming_example_multi_anime_div').show(); + } else { + $('#naming_example_multi_anime_div').hide(); + } + }); + + $.get(sbRoot + '/config/postProcessing/isNamingValid', {pattern: pattern, multi: multi, anime_type: anime_type}, + function (data) { + if (data == "invalid") { + $('#naming_pattern').qtip('option', { + 'content.text': 'This pattern is invalid.', + 'style.classes': 'qtip-rounded qtip-shadow qtip-red' + }); + $('#naming_pattern').qtip('toggle', true); + $('#naming_pattern').css('background-color', '#FFDDDD'); + } else if (data == "seasonfolders") { + $('#naming_pattern').qtip('option', { + 'content.text': 'This pattern would be invalid without the folders, using it will force "Flatten" off for all shows.', + 'style.classes': 'qtip-rounded qtip-shadow qtip-red' + }); + $('#naming_pattern').qtip('toggle', true); + $('#naming_pattern').css('background-color', '#FFFFDD'); + } else { + $('#naming_pattern').qtip('option', { + 'content.text': 'This pattern is valid.', + 'style.classes': 'qtip-rounded qtip-shadow qtip-green' + }); + $('#naming_pattern').qtip('toggle', false); + $('#naming_pattern').css('background-color', '#FFFFFF'); + } + }); + } + function setup_naming() { // if it is a custom selection then show the text box if ($('#name_presets :selected').val() == "Custom...") { @@ -214,6 +287,17 @@ $(document).ready(function () { fill_sports_examples(); } + function setup_anime_naming() { + // if it is a custom selection then show the text box + if ($('#name_anime_presets :selected').val() == "Custom...") { + $('#naming_anime_custom').show(); + } else { + $('#naming_anime_custom').hide(); + $('#naming_anime_pattern').val($('#name_anime_presets :selected').attr('id')); + } + fill_anime_examples(); + } + $('#unpack').change(function () { if(this.checked) { israr_supported(); @@ -242,8 +326,16 @@ $(document).ready(function () { setup_sports_naming(); }); + $('#name_anime_presets').change(function () { + setup_anime_naming(); + }); + + $('#naming_custom_anime').change(function () { + setup_anime_naming(); + }); + $('input[name="naming_anime"]').click(function(){ - setup_naming(); + setup_anime_naming(); }); $('#naming_multi_ep').change(fill_examples); @@ -254,6 +346,14 @@ $(document).ready(function () { }, 500); }); + $('#naming_anime_multi_ep').change(fill_anime_examples); + $('#naming_anime_pattern').focusout(fill_anime_examples); + $('#naming_anime_pattern').keyup(function () { + typewatch(function () { + fill_anime_examples(); + }, 500); + }); + $('#naming_abd_pattern').focusout(fill_examples); $('#naming_abd_pattern').keyup(function () { typewatch(function () { @@ -268,6 +368,13 @@ $(document).ready(function () { }, 500); }); + $('#naming_anime_pattern').focusout(fill_examples); + $('#naming_anime_pattern').keyup(function () { + typewatch(function () { + fill_anime_examples(); + }, 500); + }); + $('#show_naming_key').click(function () { $('#naming_key').toggle(); }); @@ -285,6 +392,8 @@ $(document).ready(function () { setup_naming(); setup_abd_naming(); setup_sports_naming(); + setup_anime_naming(); + // -- start of metadata options div toggle code -- $('#metadataType').on('change keyup', function () { diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index e7ba0094..ffb7439c 100755 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -168,11 +168,14 @@ ANIME_DEFAULT = False PROVIDER_ORDER = [] NAMING_MULTI_EP = False +NAMING_ANIME_MULTI_EP = False NAMING_PATTERN = None NAMING_ABD_PATTERN = None NAMING_CUSTOM_ABD = False NAMING_SPORTS_PATTERN = None NAMING_CUSTOM_SPORTS = False +NAMING_ANIME_PATTERN = None +NAMING_CUSTOM_ANIME = False NAMING_FORCE_FOLDERS = False NAMING_STRIP_YEAR = False NAMING_ANIME = None @@ -476,7 +479,7 @@ def initialize(consoleLogging=True): versionCheckScheduler, VERSION_NOTIFY, AUTO_UPDATE, NOTIFY_ON_UPDATE, PROCESS_AUTOMATICALLY, UNPACK, CPU_PRESET, \ KEEP_PROCESSED_DIR, PROCESS_METHOD, TV_DOWNLOAD_DIR, MIN_DAILYSEARCH_FREQUENCY, DEFAULT_UPDATE_FREQUENCY, MIN_UPDATE_FREQUENCY, UPDATE_FREQUENCY, \ showQueueScheduler, searchQueueScheduler, ROOT_DIRS, CACHE_DIR, ACTUAL_CACHE_DIR, TIMEZONE_DISPLAY, \ - NAMING_PATTERN, NAMING_MULTI_EP, NAMING_FORCE_FOLDERS, NAMING_ABD_PATTERN, NAMING_CUSTOM_ABD, NAMING_SPORTS_PATTERN, NAMING_CUSTOM_SPORTS, NAMING_STRIP_YEAR, \ + NAMING_PATTERN, NAMING_MULTI_EP, NAMING_ANIME_MULTI_EP, NAMING_FORCE_FOLDERS, NAMING_ABD_PATTERN, NAMING_CUSTOM_ABD, NAMING_SPORTS_PATTERN, NAMING_CUSTOM_SPORTS, NAMING_ANIME_PATTERN, NAMING_CUSTOM_ANIME, NAMING_STRIP_YEAR, \ RENAME_EPISODES, AIRDATE_EPISODES, properFinderScheduler, PROVIDER_ORDER, autoPostProcesserScheduler, \ WOMBLE, OMGWTFNZBS, OMGWTFNZBS_USERNAME, OMGWTFNZBS_APIKEY, providerList, newznabProviderList, torrentRssProviderList, \ EXTRA_SCRIPTS, USE_TWITTER, TWITTER_USERNAME, TWITTER_PASSWORD, TWITTER_PREFIX, DAILYSEARCH_FREQUENCY, \ @@ -627,9 +630,12 @@ def initialize(consoleLogging=True): NAMING_ABD_PATTERN = check_setting_str(CFG, 'General', 'naming_abd_pattern', '%SN - %A.D - %EN') NAMING_CUSTOM_ABD = bool(check_setting_int(CFG, 'General', 'naming_custom_abd', 0)) NAMING_SPORTS_PATTERN = check_setting_str(CFG, 'General', 'naming_sports_pattern', '%SN - %A-D - %EN') + NAMING_ANIME_PATTERN = check_setting_str(CFG, 'General', 'naming_anime_pattern', 'Season %0S/%SN - S%0SE%0E - %EN') NAMING_ANIME = check_setting_int(CFG, 'General', 'naming_anime', 3) NAMING_CUSTOM_SPORTS = bool(check_setting_int(CFG, 'General', 'naming_custom_sports', 0)) + NAMING_CUSTOM_ANIME = bool(check_setting_int(CFG, 'General', 'naming_custom_anime', 0)) NAMING_MULTI_EP = check_setting_int(CFG, 'General', 'naming_multi_ep', 1) + NAMING_ANIME_MULTI_EP = check_setting_int(CFG, 'General', 'naming_anime_multi_ep', 1) NAMING_FORCE_FOLDERS = naming.check_force_season_folders() NAMING_STRIP_YEAR = bool(check_setting_int(CFG, 'General', 'naming_strip_year', 0)) @@ -1396,7 +1402,10 @@ def save_config(): new_config['General']['naming_abd_pattern'] = NAMING_ABD_PATTERN new_config['General']['naming_custom_sports'] = int(NAMING_CUSTOM_SPORTS) new_config['General']['naming_sports_pattern'] = NAMING_SPORTS_PATTERN + new_config['General']['naming_custom_sports'] = int(NAMING_CUSTOM_ANIME) + new_config['General']['naming_sports_pattern'] = NAMING_ANIME_PATTERN new_config['General']['naming_multi_ep'] = int(NAMING_MULTI_EP) + new_config['General']['naming_anime_multi_ep'] = int(NAMING_ANIME_MULTI_EP) new_config['General']['naming_anime'] = int(NAMING_ANIME) new_config['General']['launch_browser'] = int(LAUNCH_BROWSER) new_config['General']['update_shows_on_start'] = int(UPDATE_SHOWS_ON_START) diff --git a/sickbeard/naming.py b/sickbeard/naming.py index 75d2e842..026b9688 100644 --- a/sickbeard/naming.py +++ b/sickbeard/naming.py @@ -35,6 +35,8 @@ name_presets = ('%SN - %Sx%0E - %EN', 'Season %0S/%S.N.S%0SE%0E.%Q.N-%RG' ) +name_anime_presets = name_presets + name_abd_presets = ('%SN - %A-D - %EN', '%S.N.%A.D.%E.N.%Q.N', '%Y/%0M/%S.N.%A.D.%E.N-%RG' diff --git a/sickbeard/tv.py b/sickbeard/tv.py index 9e6590f6..b720ac43 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -2341,6 +2341,8 @@ class TVEpisode(object): pattern = sickbeard.NAMING_ABD_PATTERN elif self.show.sports and sickbeard.NAMING_CUSTOM_SPORTS and not self.relatedEps: pattern = sickbeard.NAMING_SPORTS_PATTERN + elif self.show.anime and sickbeard.NAMING_CUSTOM_ANIME: + pattern = sickbeard.NAMING_ANIME_PATTERN else: pattern = sickbeard.NAMING_PATTERN @@ -2363,6 +2365,8 @@ class TVEpisode(object): pattern = sickbeard.NAMING_ABD_PATTERN elif self.show.sports and sickbeard.NAMING_CUSTOM_SPORTS and not self.relatedEps: pattern = sickbeard.NAMING_SPORTS_PATTERN + elif self.show.anime and sickbeard.NAMING_CUSTOM_ANIME: + pattern = sickbeard.NAMING_ANIME_PATTERN else: pattern = sickbeard.NAMING_PATTERN diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 6a481d07..bd6d9ce7 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -1714,7 +1714,9 @@ class ConfigPostProcessing(MainHandler): naming_anime=None, naming_abd_pattern=None, naming_strip_year=None, use_failed_downloads=None, delete_failed=None, extra_scripts=None, skip_removed_files=None, - naming_custom_sports=None, naming_sports_pattern=None, autopostprocesser_frequency=None): + naming_custom_sports=None, naming_sports_pattern=None, + naming_custom_anime=None, naming_anime_pattern=None, naming_anime_multi_ep=None, + autopostprocesser_frequency=None): results = [] @@ -1747,6 +1749,7 @@ class ConfigPostProcessing(MainHandler): sickbeard.POSTPONE_IF_SYNC_FILES = config.checkbox_to_value(postpone_if_sync_files) sickbeard.NAMING_CUSTOM_ABD = config.checkbox_to_value(naming_custom_abd) sickbeard.NAMING_CUSTOM_SPORTS = config.checkbox_to_value(naming_custom_sports) + sickbeard.NAMING_CUSTOM_ANIME = config.checkbox_to_value(naming_custom_anime) sickbeard.NAMING_STRIP_YEAR = config.checkbox_to_value(naming_strip_year) sickbeard.USE_FAILED_DOWNLOADS = config.checkbox_to_value(use_failed_downloads) sickbeard.DELETE_FAILED = config.checkbox_to_value(delete_failed) @@ -1780,6 +1783,17 @@ class ConfigPostProcessing(MainHandler): else: results.append("You tried saving an invalid naming config, not saving your naming settings") + if self.isNamingValid(naming_anime_pattern, naming_anime_multi_ep, anime_type=naming_anime) != "invalid": + sickbeard.NAMING_ANIME_PATTERN = naming_anime_pattern + sickbeard.NAMING_ANIME_MULTI_EP = int(naming_anime_multi_ep) + sickbeard.NAMING_ANIME = int(naming_anime) + sickbeard.NAMING_FORCE_FOLDERS = naming.check_force_season_folders() + else: + if int(naming_anime) in [1, 2]: + results.append("You tried saving an invalid anime naming config, not saving your naming settings") + else: + results.append("You tried saving an invalid naming config, not saving your naming settings") + if self.isNamingValid(naming_abd_pattern, None, abd=True) != "invalid": sickbeard.NAMING_ABD_PATTERN = naming_abd_pattern else: