Browse Source

Add optional nzbget processing just based on status send via pp script.

pull/1289/head
Prinz23 5 years ago
committed by JackDandy
parent
commit
37983644cf
  1. 7
      gui/slick/interfaces/default/config_search.tmpl
  2. 5
      sickbeard/__init__.py
  3. 114
      sickbeard/postProcessor.py
  4. 16
      sickbeard/processTV.py
  5. 64
      sickbeard/webserve.py

7
gui/slick/interfaces/default/config_search.tmpl

@ -341,6 +341,13 @@
</div>
<div id="nzbget-settings">
#if $sickbeard.NZBGET_SKIP_PM
<div class="field-pair">
<span class="component-desc" style="margin:0;width:100%">
<div class="clear-left"><p><span class="grey-text"><span class="red-text">Important!</span> NZBGet script calls will not process media. Set</span> nzbget_skip_process_media = 0 <span class="grey-text">in <code>config.ini</code> for full process</span></p></div>
</span>
</div>
#end if
<div class="field-pair">
<label for="nzbget_use_https">
<span class="component-title">Connect using HTTPS</span>

5
sickbeard/__init__.py

@ -285,6 +285,7 @@ NZBGET_USE_HTTPS = False
NZBGET_PRIORITY = 100
NZBGET_SCRIPT_VERSION = None
NZBGET_MAP = None
NZBGET_SKIP_PM = False
SAB_USERNAME = None
SAB_PASSWORD = None
@ -654,7 +655,7 @@ def init_stage_1(console_logging):
# Search Settings/NZB search
global USE_NZBS, NZB_METHOD, NZB_DIR, SAB_HOST, SAB_USERNAME, SAB_PASSWORD, SAB_APIKEY, SAB_CATEGORY, \
NZBGET_USE_HTTPS, NZBGET_HOST, NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_PRIORITY, \
NZBGET_SCRIPT_VERSION, NZBGET_MAP
NZBGET_SCRIPT_VERSION, NZBGET_MAP, NZBGET_SKIP_PM
# Search Settings/Torrent search
global USE_TORRENTS, TORRENT_METHOD, TORRENT_DIR, TORRENT_HOST, TORRENT_USERNAME, TORRENT_PASSWORD, \
TORRENT_LABEL, TORRENT_LABEL_VAR, TORRENT_PATH, TORRENT_SEED_TIME, TORRENT_PAUSED, \
@ -984,6 +985,7 @@ def init_stage_1(console_logging):
if None is NZBGET_PRIORITY:
NZBGET_PRIORITY = check_setting_int(CFG, 'NZBget', 'nzbget_priority', 100)
NZBGET_MAP = check_setting_str(CFG, 'NZBGet', 'nzbget_map', '')
NZBGET_SKIP_PM = bool(check_setting_int(CFG, 'NZBGet', 'nzbget_skip_process_media', 0))
try:
ng_script_file = ek.ek(os.path.join, ek.ek(os.path.dirname, ek.ek(os.path.dirname, __file__)),
@ -1902,6 +1904,7 @@ def save_config():
('use_https', int(NZBGET_USE_HTTPS)),
('priority', NZBGET_PRIORITY),
('map', NZBGET_MAP),
('nzbget_skip_process_media', int(NZBGET_SKIP_PM)),
]),
('SABnzbd', [
('username', SAB_USERNAME), ('password', helpers.encrypt(SAB_PASSWORD, ENCRYPTION_VERSION)),

114
sickbeard/postProcessor.py

@ -611,7 +611,7 @@ class PostProcessor(object):
logger.log(u' or Parse result(air_date): ' + str(parse_result.air_date), logger.DEBUG)
logger.log(u'Parse result(release_group): ' + str(parse_result.release_group), logger.DEBUG)
def _find_info(self):
def _find_info(self, history_only=False):
"""
For a given file try to find the show_obj, season, and episode.
:return: tuple of tv show object, season number, list of episode numbers, quality or None, None, [], None
@ -622,7 +622,7 @@ class PostProcessor(object):
episode_numbers = []
# try to look up the nzb in history
try_list = [self._history_lookup,
try_list = [self._history_lookup] + ([
# try to analyze the nzb name
lambda: self._analyze_name(self.nzb_name),
@ -640,7 +640,9 @@ class PostProcessor(object):
lambda: self._analyze_name(self.folder_name + u' ' + self.file_name),
# try to analyze file name with previously parsed show_obj
lambda: self._analyze_name(self.file_name, show_obj=show_obj, rel_grp=rel_grp)]
lambda: self._analyze_name(self.file_name, show_obj=show_obj, rel_grp=rel_grp)],
[])[history_only]
# attempt every possible method to get our info
for cur_try in try_list:
@ -719,7 +721,7 @@ class PostProcessor(object):
If the episode(s) can be found then a TVEpisode object with the correct related eps will
be instantiated and returned. If the episode can't be found then None will be returned.
:param show_obj:
:type show_obj: sickbeard.tv.TVShow
:param season_number:
@ -995,6 +997,63 @@ class PostProcessor(object):
u' would be better to examine the files', logger.DEBUG)
return False
def _change_ep_objs(self, show_obj, season_number, episode_numbers, quality):
sql_l = []
ep_obj = self._get_ep_obj(show_obj, season_number, episode_numbers)
# if we're processing an episode of type anime, get the anime version
anime_version = (-1, self.anime_version)[ep_obj.show_obj.is_anime and None is not self.anime_version]
for cur_ep_obj in [ep_obj] + ep_obj.related_ep_obj:
with cur_ep_obj.lock:
if self.release_name:
self._log(u'Found release name ' + self.release_name, logger.DEBUG)
cur_ep_obj.release_name = self.release_name or ''
any_qualities, best_qualities = common.Quality.splitQuality(cur_ep_obj.show_obj.quality)
cur_status, cur_quality = common.Quality.splitCompositeStatus(cur_ep_obj.status)
cur_ep_obj.status = common.Quality.compositeStatus(
**({'status': common.DOWNLOADED, 'quality': quality},
{'status': common.ARCHIVED, 'quality': quality})
[cur_ep_obj.status in common.Quality.SNATCHED_BEST or
(cur_ep_obj.show_obj.upgrade_once and
(quality in best_qualities and
(quality not in any_qualities or (cur_status in
(common.SNATCHED, common.SNATCHED_BEST,
common.SNATCHED_PROPER, common.DOWNLOADED) and
cur_quality != quality))))])
cur_ep_obj.release_group = self.release_group or ''
cur_ep_obj.is_proper = self.is_proper
cur_ep_obj.version = anime_version
cur_ep_obj.subtitles = []
cur_ep_obj.subtitles_searchcount = 0
cur_ep_obj.subtitles_lastsearch = '0001-01-01 00:00:00'
sql = cur_ep_obj.get_sql()
if None is not sql:
sql_l.append(sql)
if 0 < len(sql_l):
my_db = db.DBConnection()
my_db.mass_action(sql_l)
def process_minimal(self):
self._log('Processing without any files...')
(show_obj, season_number, episode_numbers, quality) = self._find_info(history_only=True)
if show_obj and season_number and episode_numbers and quality and quality not in (None, common.Quality.UNKNOWN):
self._change_ep_objs(show_obj, season_number, episode_numbers, quality)
self._log('Successfully processed.', logger.MESSAGE)
else:
self._log('Can\'t figure out what show/episode to process', logger.WARNING)
raise exceptions_helper.PostProcessingFailed()
def process(self):
"""
Post-process a given file
@ -1075,51 +1134,7 @@ class PostProcessor(object):
# get metadata for the show (but not episode because it hasn't been fully processed)
ep_obj.show_obj.write_metadata(True)
# if we're processing an episode of type anime, get the anime version
anime_version = (-1, self.anime_version)[ep_obj.show_obj.is_anime and None is not self.anime_version]
# update the ep info before we rename so the quality & release name go into the name properly
sql_l = []
for cur_ep_obj in [ep_obj] + ep_obj.related_ep_obj:
with cur_ep_obj.lock:
if self.release_name:
self._log(u'Found release name ' + self.release_name, logger.DEBUG)
cur_ep_obj.release_name = self.release_name or ''
any_qualities, best_qualities = common.Quality.splitQuality(cur_ep_obj.show_obj.quality)
cur_status, cur_quality = common.Quality.splitCompositeStatus(cur_ep_obj.status)
cur_ep_obj.status = common.Quality.compositeStatus(
**({'status': common.DOWNLOADED, 'quality': new_ep_quality},
{'status': common.ARCHIVED, 'quality': new_ep_quality})
[ep_obj.status in common.Quality.SNATCHED_BEST or
(cur_ep_obj.show_obj.upgrade_once and
(new_ep_quality in best_qualities and
(new_ep_quality not in any_qualities or (cur_status in
(common.SNATCHED, common.SNATCHED_BEST, common.SNATCHED_PROPER, common.DOWNLOADED) and
cur_quality != new_ep_quality))))])
cur_ep_obj.release_group = self.release_group or ''
cur_ep_obj.is_proper = self.is_proper
cur_ep_obj.version = anime_version
cur_ep_obj.subtitles = []
cur_ep_obj.subtitles_searchcount = 0
cur_ep_obj.subtitles_lastsearch = '0001-01-01 00:00:00'
sql = cur_ep_obj.get_sql()
if None is not sql:
sql_l.append(sql)
if 0 < len(sql_l):
my_db = db.DBConnection()
my_db.mass_action(sql_l)
self._change_ep_objs(show_obj, season_number, episode_numbers, new_ep_quality)
# Just want to keep this consistent for failed handling right now
release_name = show_name_helpers.determineReleaseName(self.folder_path, self.nzb_name)
@ -1226,6 +1241,7 @@ class PostProcessor(object):
ep_obj.create_meta_files()
# log it to history
anime_version = (-1, self.anime_version)[ep_obj.show_obj.is_anime and None is not self.anime_version]
history.log_download(ep_obj, self.file_path, new_ep_quality, self.release_group, anime_version)
# send notifications

16
sickbeard/processTV.py

@ -50,7 +50,8 @@ import lib.rarfile.rarfile as rarfile
# noinspection PyUnreachableCode
if False:
from typing import AnyStr, Dict, List, Optional, Tuple
from typing import Any, AnyStr, Dict, List, Optional, Tuple
from .tv import TVShow
# noinspection PyArgumentList
@ -1148,6 +1149,14 @@ class ProcessTVShow(object):
self._log_helper(u'%s failed: (%s, %s): %s'
% (task, str(nzb_name), dir_name, process_fail_message), logger.WARNING)
def process_minimal(self, nzb_name, show_obj, failed, webhandler):
if failed:
self._process_failed('', nzb_name=nzb_name, show_obj=show_obj)
else:
processor = postProcessor.PostProcessor('', nzb_name=nzb_name, webhandler=webhandler, show_obj=show_obj)
processor.process_minimal()
self._buffer(processor.log.strip('\n'))
# backward compatibility prevents the case of this function name from being updated to PEP8
def processDir(dir_name, nzb_name=None, process_method=None, force=False, force_replace=None,
@ -1185,3 +1194,8 @@ def processDir(dir_name, nzb_name=None, process_method=None, force=False, force_
# backward compatibility prevents the case of this function name from being updated to PEP8
return ProcessTVShow(webhandler, is_basedir, skip_failure_processing=skip_failure_processing).process_dir(
dir_name, nzb_name, process_method, force, force_replace, failed, pp_type, cleanup, show_obj)
def process_minimal(nzb_name, show_obj, failed, webhandler):
# type: (AnyStr, TVShow, bool, Any) -> None
ProcessTVShow(webhandler).process_minimal(nzb_name, show_obj, failed, webhandler)

64
sickbeard/webserve.py

@ -1360,7 +1360,7 @@ class Home(MainHandler):
:param tvid_prodid:
:type tvid_prodid:
:param season:
:type season:
:type season:
:param episode:
:type episode:
:param absolute:
@ -1780,7 +1780,7 @@ class Home(MainHandler):
r = notifiers.NotifierFactory().get('TELEGRAM').test_notify(
send_icon=bool(config.checkbox_to_value(send_icon)), access_token=access_token, chatid=chatid)
return json.dumps(r)
def test_email(self, host=None, port=None, smtp_from=None, use_tls=None, user=None, pwd=None, to=None):
self.set_header('Cache-Control', 'max-age=0,no-cache,no-store')
@ -1993,8 +1993,8 @@ class Home(MainHandler):
last_found = ('', ' since %s' % SGDatetime.fromordinal(
show_obj.last_found_on_indexer).sbfdate())[1 < show_obj.last_found_on_indexer]
show_message = (
'The master ID of this show has been <span class="addQTip" title="many reasons exist, including: ' +
'<br>show flagged as a duplicate, removed completely... etc">abandoned</span>%s, ' % last_found +
'The master ID of this show has been <span class="addQTip" title="many reasons exist, including: ' +
'<br>show flagged as a duplicate, removed completely... etc">abandoned</span>%s, ' % last_found +
'<a href="%s/home/edit-show?tvid_prodid=%s&tvsrc=0&srcid=%s#core-component-group3">replace it here</a>'
% (sickbeard.WEB_ROOT, tvid_prodid, show_obj.prodid)
+ ('', '<br>%s' % show_message)[0 < len(show_message)])
@ -3281,30 +3281,36 @@ class HomeProcessMedia(Home):
logger.log('Calling SickGear-NG.py script %s is not current version %s, please update.' %
(kwargs.get('pp_version', '0'), sickbeard.NZBGET_SCRIPT_VERSION), logger.ERROR)
if isinstance(dir_name, string_types):
dir_name = decode_str(dir_name)
if nzbget_call and isinstance(sickbeard.NZBGET_MAP, string_types) and sickbeard.NZBGET_MAP:
m = sickbeard.NZBGET_MAP.split('=')
dir_name, not_used = helpers.path_mapper(m[0], m[1], dir_name)
result = processTV.processDir(dir_name if dir_name else None,
None if not nzb_name else decode_str(nzb_name),
process_method=process_method, pp_type=process_type,
cleanup=kwargs.get('cleanup') in ('on', '1'),
force=force in ('on', '1'),
force_replace=force_replace in ('on', '1'),
failed='0' != failed,
webhandler=None if '0' == stream else self.send_message,
show_obj=show_obj, is_basedir=is_basedir in ('on', '1'),
skip_failure_processing=skip_failure_processing)
if '0' == stream:
regexp = re.compile(r'(?i)<br(?:[\s/]+)>', flags=re.UNICODE)
result = regexp.sub('\n', result)
if None is not quiet and 1 == int(quiet):
regexp = re.compile(u'(?i)<a[^>]+>([^<]+)<[/]a>', flags=re.UNICODE)
return u'%s' % regexp.sub(r'\1', result)
return self._generic_message('Postprocessing results', u'<pre>%s</pre>' % result)
if sickbeard.NZBGET_SKIP_PM and nzbget_call and nzbget_dupekey and nzb_name and show_obj:
processTV.process_minimal(nzb_name, show_obj,
failed in (1, '1', True, 'True', 'true'),
webhandler=None if '0' == stream else self.send_message)
else:
if isinstance(dir_name, string_types):
dir_name = decode_str(dir_name)
if nzbget_call and isinstance(sickbeard.NZBGET_MAP, string_types) and sickbeard.NZBGET_MAP:
m = sickbeard.NZBGET_MAP.split('=')
dir_name, not_used = helpers.path_mapper(m[0], m[1], dir_name)
result = processTV.processDir(dir_name if dir_name else None,
None if not nzb_name else decode_str(nzb_name),
process_method=process_method, pp_type=process_type,
cleanup=kwargs.get('cleanup') in ('on', '1'),
force=force in ('on', '1'),
force_replace=force_replace in ('on', '1'),
failed='0' != failed,
webhandler=None if '0' == stream else self.send_message,
show_obj=show_obj, is_basedir=is_basedir in ('on', '1'),
skip_failure_processing=skip_failure_processing)
if '0' == stream:
regexp = re.compile(r'(?i)<br(?:[\s/]+)>', flags=re.UNICODE)
result = regexp.sub('\n', result)
if None is not quiet and 1 == int(quiet):
regexp = re.compile(u'(?i)<a[^>]+>([^<]+)<[/]a>', flags=re.UNICODE)
return u'%s' % regexp.sub(r'\1', result)
return self._generic_message('Postprocessing results', u'<pre>%s</pre>' % result)
def processEpisode(self, dir_name=None, nzb_name=None, process_type=None, **kwargs):
""" legacy function name, stubbed but can _not_ be removed as this
@ -6551,7 +6557,7 @@ class ConfigSearch(Config):
sab_username=None, sab_password=None, sab_apikey=None, sab_category=None, sab_host=None,
nzbget_username=None, nzbget_password=None, nzbget_category=None, nzbget_host=None,
nzbget_use_https=None, nzbget_priority=None, nzbget_parent_map=None,
torrent_username=None, torrent_password=None, torrent_label=None, torrent_label_var=None,
torrent_username=None, torrent_password=None, torrent_label=None, torrent_label_var=None,
torrent_verify_cert=None, torrent_path=None, torrent_seed_time=None, torrent_paused=None,
torrent_high_bandwidth=None, torrent_host=None):

Loading…
Cancel
Save