Commit 8324c574 authored by echel0n's avatar echel0n

Added new release mapping %SY to allow appending the show year to episodes.

Added new show option to append show year to show folder if needed.
Added check for existing show year in show name, if found, do not append show year.
parent 954c6346
# Changelog
- * 7be7535 - 2019-02-23: Release v9.4.68
- * 879d546 - 2019-02-23: Added new release mapping %SY to allow appending the show year to episodes. Added new show option to append show year to show folder if needed. Added check for existing show year in show name, if found, do not append show year.
- * c3441ed - 2019-02-23: Release v9.4.68
- * 3f6df12 - 2019-02-23: Release v9.4.67
- * 83d1b88 - 2019-02-23: Moved RSS cache updates to separate background task that executes every 15 minutes. Parsed search results no longer grab their show id's from TheTVDB or Trackt since we only care about shows existing in library. Search results returned for shows not existing in library are discarded.
- * 9c78d0b - 2019-02-23: Release v9.4.66
......
......@@ -25,6 +25,7 @@ class Show(object):
self.genre = "Comedy"
self.indexerid = 00001
self.air_by_date = 0
self.startyear = 2011
self.sports = 0
self.anime = 0
self.scene = 0
......
......@@ -1120,6 +1120,7 @@ class TVEpisode(object):
'%SQN': Quality.sceneQualityStrings[epQual] + encoder,
'%SQ.N': dot(Quality.sceneQualityStrings[epQual] + encoder),
'%SQ_N': us(Quality.sceneQualityStrings[epQual] + encoder),
'%SY': str(self.show.startyear),
'%S': str(self.season),
'%0S': '%02d' % self.season,
'%E': str(self.episode),
......@@ -1223,7 +1224,7 @@ class TVEpisode(object):
season_ep_regex = r'''
(?P<pre_sep>[ _.-]*)
((?:s(?:eason|eries)?\s*)?%0?S(?![._]?N))
((?:s(?:eason|eries)?\s*)?%0?S(?![._]?N|Y))
(.*?)
(%0?E(?![._]?N))
(?P<post_sep>[ _.-]*)
......@@ -1273,8 +1274,7 @@ class TVEpisode(object):
# for limited extend we only append the last ep
if multi in (NAMING_LIMITED_EXTEND, NAMING_LIMITED_EXTEND_E_PREFIXED) and other_ep != \
self.relatedEps[
-1]:
self.relatedEps[-1]:
continue
elif multi == NAMING_DUPLICATE:
......@@ -1300,8 +1300,7 @@ class TVEpisode(object):
if self.season != 0: # dont set absolute numbers if we are on specials !
if anime_type == 1: # this crazy person wants both ! (note: +=)
ep_string += sep + "%(#)03d" % {
"#": curAbsolute_number}
ep_string += sep + "%(#)03d" % {"#": curAbsolute_number}
elif anime_type == 2: # total anime freak only need the absolute number ! (note: =)
ep_string = "%(#)03d" % {"#": curAbsolute_number}
......
......@@ -1894,8 +1894,8 @@ class CMD_ShowAddExisting(ApiCall):
super(CMD_ShowAddExisting, self).__init__(application, request, *args, **kwargs)
self.indexerid, args = self.check_params("indexerid", None, True, "", [], *args, **kwargs)
self.location, args = self.check_params("location", None, True, "string", [], *args, **kwargs)
self.initial, args = self.check_params("initial", None, False, "list",any_quality_list, *args, **kwargs)
self.archive, args = self.check_params("archive", None, False, "list",best_quality_list, *args, **kwargs)
self.initial, args = self.check_params("initial", None, False, "list", any_quality_list, *args, **kwargs)
self.archive, args = self.check_params("archive", None, False, "list", best_quality_list, *args, **kwargs)
self.skip_downloaded, args = self.check_params("skip_downloaded", None, False, "int", [], *args, **kwargs)
self.flatten_folders, args = self.check_params("flatten_folders",
bool(sickrage.app.config.flatten_folders_default), False,
......@@ -1974,6 +1974,9 @@ class CMD_ShowAddNew(ApiCall):
"skip_downloaded": {
"desc": "True if episodes should be archived when first match is downloaded, False otherwise"
},
"add_show_year": {
"desc": "True if show year should be appended to show folder, False otherwise"
},
}
}
......@@ -1982,8 +1985,8 @@ class CMD_ShowAddNew(ApiCall):
self.valid_languages = IndexerApi().indexer().languages
self.indexerid, args = self.check_params("indexerid", None, True, "int", [], *args, **kwargs)
self.location, args = self.check_params("location", None, False, "string", [], *args, **kwargs)
self.initial, args = self.check_params("initial", None, False, "list",any_quality_list, *args, **kwargs)
self.archive, args = self.check_params("archive", None, False, "list",best_quality_list, *args, **kwargs)
self.initial, args = self.check_params("initial", None, False, "list", any_quality_list, *args, **kwargs)
self.archive, args = self.check_params("archive", None, False, "list", best_quality_list, *args, **kwargs)
self.flatten_folders, args = self.check_params("flatten_folders",
bool(sickrage.app.config.flatten_folders_default), False,
"bool", [], *args, **kwargs)
......@@ -2002,11 +2005,12 @@ class CMD_ShowAddNew(ApiCall):
self.skip_downloaded, args = self.check_params("skip_downloaded",
bool(sickrage.app.config.skip_downloaded_default), False, "bool",
[], *args, **kwargs)
self.add_show_year, args = self.check_params("add_show_year", False, False, "bool", [], *args, **kwargs)
def run(self):
""" Add a new show to SiCKRAGE """
showObj = findCertainShow(int(self.indexerid))
if showObj:
show_obj = findCertainShow(int(self.indexerid))
if show_obj:
return _responds(RESULT_FAILURE, msg="An existing indexerid already exists in database")
if not self.location:
......@@ -2022,22 +2026,22 @@ class CMD_ShowAddNew(ApiCall):
return _responds(RESULT_FAILURE, msg="'" + self.location + "' is not a valid location")
# use default quality as a failsafe
newQuality = int(sickrage.app.config.quality_default)
iqualityID = []
aqualityID = []
new_quality = int(sickrage.app.config.quality_default)
iquality_id = []
aquality_id = []
if isinstance(self.initial, collections.Iterable):
for quality in self.initial:
iqualityID.append(_get_quality_map()[quality])
iquality_id.append(_get_quality_map()[quality])
if isinstance(self.archive, collections.Iterable):
for quality in self.archive:
aqualityID.append(_get_quality_map()[quality])
aquality_id.append(_get_quality_map()[quality])
if iqualityID or aqualityID:
newQuality = Quality.combineQualities(iqualityID, aqualityID)
if iquality_id or aquality_id:
new_quality = Quality.combineQualities(iquality_id, aquality_id)
# use default status as a failsafe
newStatus = sickrage.app.config.status_default
new_status = sickrage.app.config.status_default
if self.status:
# convert the string status to a int
for status in statusStrings.statusStrings:
......@@ -2051,7 +2055,7 @@ class CMD_ShowAddNew(ApiCall):
# only allow the status options we want
if int(self.status) not in (WANTED, SKIPPED, IGNORED):
return _responds(RESULT_FAILURE, msg="Status prohibited")
newStatus = self.status
new_status = self.status
# use default status as a failsafe
default_ep_status_after = sickrage.app.config.status_default_after
......@@ -2070,45 +2074,48 @@ class CMD_ShowAddNew(ApiCall):
return _responds(RESULT_FAILURE, msg="Status prohibited")
default_ep_status_after = self.future_status
indexerName = None
indexerResult = CMD_SiCKRAGESearchIndexers(self.application, self.request,
indexer_name = None
indexer_result = CMD_SiCKRAGESearchIndexers(self.application, self.request,
**{indexer_ids[self.indexer]: self.indexerid}).run()
if indexerResult['result'] == result_type_map[RESULT_SUCCESS]:
if not indexerResult['data']['results']:
if indexer_result['result'] == result_type_map[RESULT_SUCCESS]:
if not indexer_result['data']['results']:
return _responds(RESULT_FAILURE, msg="Empty results returned, check indexerid and try again")
if len(indexerResult['data']['results']) == 1 and 'name' in indexerResult['data']['results'][0]:
indexerName = indexerResult['data']['results'][0]['name']
if len(indexer_result['data']['results']) == 1 and 'name' in indexer_result['data']['results'][0]:
indexer_name = indexer_result['data']['results'][0]['name']
if not indexerName:
if not indexer_name:
return _responds(RESULT_FAILURE, msg="Unable to retrieve information from indexer")
# set indexer for found show so we can pass it along
indexer = indexerResult['data']['results'][0]['indexer']
indexer = indexer_result['data']['results'][0]['indexer']
first_aired = indexer_result['data']['results'][0]['first_aired']
# moved the logic check to the end in an attempt to eliminate empty directory being created from previous errors
showPath = os.path.join(self.location, sanitizeFileName(indexerName))
show_path = os.path.join(self.location, sanitizeFileName(indexer_name))
if self.add_show_year and not re.match(r'.*\(\d+\)$', show_path):
show_path = "{} ({})".format(show_path, re.search(r'\d{4}', first_aired).group(0))
# 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 " + showPath + " due to config.ini setting")
sickrage.app.log.info("Skipping initial creation of " + show_path + " due to config.ini setting")
else:
dir_exists = makeDir(showPath)
dir_exists = makeDir(show_path)
if not dir_exists:
sickrage.app.log.warning(
"Unable to create the folder " + showPath + ", can't add the show")
return _responds(RESULT_FAILURE, {"path": showPath},
"Unable to create the folder " + showPath + ", can't add the show")
"Unable to create the folder " + show_path + ", can't add the show")
return _responds(RESULT_FAILURE, {"path": show_path},
"Unable to create the folder " + show_path + ", can't add the show")
else:
chmod_as_parent(showPath)
chmod_as_parent(show_path)
sickrage.app.show_queue.addShow(
int(indexer), int(self.indexerid), showPath, default_status=newStatus, quality=newQuality,
int(indexer), int(self.indexerid), show_path, default_status=new_status, quality=new_quality,
flatten_folders=int(self.flatten_folders), lang=self.lang, subtitles=self.subtitles, anime=self.anime,
scene=self.scene, default_status_after=default_ep_status_after, skip_downloaded=self.skip_downloaded
)
return _responds(RESULT_SUCCESS, {"name": indexerName}, indexerName + " has been queued to be added")
return _responds(RESULT_SUCCESS, {"name": indexer_name}, indexer_name + " has been queued to be added")
class CMD_ShowCache(ApiCall):
......@@ -2499,8 +2506,8 @@ class CMD_ShowSetQuality(ApiCall):
super(CMD_ShowSetQuality, self).__init__(application, request, *args, **kwargs)
self.indexerid, args = self.check_params("indexerid", None, True, "int", [], *args, **kwargs)
# self.archive, args = self.check_params("archive", None, False, "list", _getQualityMap().values()[1:], *args, **kwargs)
self.initial, args = self.check_params("initial", None, False, "list",any_quality_list, *args, **kwargs)
self.archive, args = self.check_params("archive", None, False, "list",best_quality_list, *args, **kwargs)
self.initial, args = self.check_params("initial", None, False, "list", any_quality_list, *args, **kwargs)
self.archive, args = self.check_params("archive", None, False, "list", best_quality_list, *args, **kwargs)
def run(self):
""" Set the quality setting of a show. If no quality is provided, the default user setting is used. """
......
......@@ -2612,7 +2612,7 @@ class HomeAddShows(Home):
quality_preset=None, anyQualities=None, bestQualities=None, flatten_folders=None, subtitles=None,
subtitles_sr_metadata=None, fullShowPath=None, other_shows=None, skipShow=None, providedIndexer=None,
anime=None, scene=None, blacklist=None, whitelist=None, defaultStatusAfter=None,
skip_downloaded=None, providedName=None):
skip_downloaded=None, providedName=None, add_show_year=None):
"""
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.
......@@ -2672,6 +2672,8 @@ class HomeAddShows(Home):
show_dir = os.path.normpath(fullShowPath)
else:
show_dir = os.path.join(rootDir, sanitizeFileName(show_name))
if add_show_year and not re.match(r'.*\(\d+\)$', show_dir):
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:
......
......@@ -54,7 +54,7 @@
</div>
<div class="row field-pair">
<div class="col-lg-3 col-md-4 col-sm-5">
<label class="component-title">${_('Skip downloaded')}</label>
<label class="component-title">${_('Skip Downloaded')}</label>
</div>
<div class="col-lg-9 col-md-8 col-sm-7 component-desc">
<label>
......@@ -63,6 +63,17 @@
</label>
</div>
</div>
<div class="row field-pair">
<div class="col-lg-3 col-md-4 col-sm-5">
<label class="component-title">${_('Append Show Year to Show Folder')}</label>
</div>
<div class="col-lg-9 col-md-8 col-sm-7 component-desc">
<label>
<input type="checkbox" class="toggle color-primary is-material" name="add_show_year"
id="add_show_year" />
</label>
</div>
</div>
<div class="row field-pair">
<div class="col-lg-3 col-md-4 col-sm-5">
<label class="component-title">${_('Status for previously aired episodes')}</label>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment