Add scheduled backlog switch.

This commit is contained in:
Prinz23 2017-01-01 20:24:41 +00:00 committed by JackDandy
parent 3417f454de
commit 87e608f277
9 changed files with 74 additions and 19 deletions

View file

@ -240,6 +240,17 @@
</label>
</div>
#end if
#if $hasattr($cur_newznab_provider, 'enable_scheduled_backlog') and $cur_newznab_provider.supports_backlog:
<div class="field-pair">
<label for="${cur_newznab_provider.get_id()}_enable_scheduled_backlog">
<span class="component-title">Enable scheduled backlog searches</span>
<span class="component-desc">
<input type="checkbox" name="${cur_newznab_provider.get_id()}_enable_scheduled_backlog" id="${cur_newznab_provider.get_id()}_enable_scheduled_backlog" <%= html_checked if cur_newznab_provider.enable_scheduled_backlog else '' %>/>
<p>perform scheduled backlog searches at provider</p>
</span>
</label>
</div>
#end if
#if $hasattr($cur_newznab_provider, 'search_mode') and $cur_newznab_provider.supports_backlog:
<div class="field-pair">
<span class="component-title">Episode search mode</span>
@ -319,6 +330,17 @@
</label>
</div>
#end if
#if $hasattr($cur_nzb_provider, 'enable_scheduled_backlog') and $cur_nzb_provider.supports_backlog:
<div class="field-pair">
<label for="${cur_nzb_provider.get_id()}_enable_scheduled_backlog">
<span class="component-title">Enable scheduled backlog searches</span>
<span class="component-desc">
<input type="checkbox" name="${cur_nzb_provider.get_id()}_enable_scheduled_backlog" id="${cur_nzb_provider.get_id()}_enable_scheduled_backlog" <%= html_checked if cur_nzb_provider.enable_scheduled_backlog else '' %>/>
<p>enable provider to perform scheduled backlog searches</p>
</span>
</label>
</div>
#end if
#if $hasattr($cur_nzb_provider, 'search_mode') and $cur_nzb_provider.supports_backlog:
<div class="field-pair">
<span class="component-title">Episode search mode</span>
@ -575,6 +597,17 @@ name = '' if not client else get_client_instance(sickbeard.TORRENT_METHOD)().nam
</label>
</div>
#end if
#if $hasattr($cur_torrent_provider, 'enable_scheduled_backlog') and $cur_torrent_provider.supports_backlog:
<div class="field-pair">
<label for="${cur_torrent_provider.get_id()}_enable_scheduled_backlog">
<span class="component-title">Enable scheduled backlog searches</span>
<span class="component-desc">
<input type="checkbox" name="${cur_torrent_provider.get_id()}_enable_scheduled_backlog" id="${cur_torrent_provider.get_id()}_enable_scheduled_backlog" <%= html_checked if cur_torrent_provider.enable_scheduled_backlog else '' %>/>
<p>enable provider to perform scheduled backlog searches</p>
</span>
</label>
</div>
#end if
#if $hasattr($cur_torrent_provider, 'search_mode') and $cur_torrent_provider.supports_backlog:
<div class="field-pair">
<span class="component-title">Episode search mode</span>

View file

@ -1145,6 +1145,8 @@ def initialize(console_logging=True):
not getattr(torrent_prov, 'supports_backlog')
if hasattr(torrent_prov, 'enable_backlog'):
torrent_prov.enable_backlog = bool(check_setting_int(CFG, prov_id_uc, prov_id + '_enable_backlog', 1))
if hasattr(torrent_prov, 'enable_scheduled_backlog'):
torrent_prov.enable_scheduled_backlog = bool(check_setting_int(CFG, prov_id_uc, prov_id + '_enable_scheduled_backlog', 1))
if hasattr(torrent_prov, 'search_mode'):
torrent_prov.search_mode = check_setting_str(CFG, prov_id_uc, prov_id + '_search_mode', 'eponly')
if hasattr(torrent_prov, 'search_fallback'):
@ -1172,6 +1174,8 @@ def initialize(console_logging=True):
not getattr(nzb_prov, 'supports_backlog')
if hasattr(nzb_prov, 'enable_backlog'):
nzb_prov.enable_backlog = bool(check_setting_int(CFG, prov_id_uc, prov_id + '_enable_backlog', 1))
if hasattr(nzb_prov, 'enable_scheduled_backlog'):
nzb_prov.enable_scheduled_backlog = bool(check_setting_int(CFG, prov_id_uc, prov_id + '_enable_scheduled_backlog', 1))
if not os.path.isfile(CONFIG_FILE):
logger.log(u'Unable to find \'%s\', all settings will be default!' % CONFIG_FILE, logger.DEBUG)
@ -1562,7 +1566,7 @@ def save_config():
('api_key', None), ('passkey', None), ('digest', None), ('hash', None), ('username', ''), ('uid', ''),
('minseed', 1), ('minleech', 1), ('confirmed', 1), ('freeleech', 1), ('reject_m2ts', 1),
('enable_recentsearch', 1), ('enable_backlog', 1), ('search_mode', None), ('search_fallback', 1),
('seed_time', None)] if hasattr(src, k)]:
('seed_time', None), ('enable_scheduled_backlog', 1)] if hasattr(src, k)]:
new_config[src_id_uc][setting] = value
if hasattr(src, '_seed_ratio'):
@ -1579,7 +1583,8 @@ def save_config():
for attr in [x for x in ['api_key', 'username', 'search_mode'] if hasattr(src, x)]:
new_config[src_id_uc]['%s_%s' % (src_id, attr)] = getattr(src, attr)
for attr in [x for x in ['enable_recentsearch', 'enable_backlog', 'search_fallback'] if hasattr(src, x)]:
for attr in [x for x in ['enable_recentsearch', 'enable_backlog', 'search_fallback',
'enable_scheduled_backlog'] if hasattr(src, x)]:
new_config[src_id_uc]['%s_%s' % (src_id, attr)] = helpers.tryInt(getattr(src, attr, None))
new_config['SABnzbd'] = {}

View file

@ -144,6 +144,7 @@ def getNewznabProviderList(data):
providerDict[curDefault.name].search_fallback = curDefault.search_fallback
providerDict[curDefault.name].enable_recentsearch = curDefault.enable_recentsearch
providerDict[curDefault.name].enable_backlog = curDefault.enable_backlog
providerDict[curDefault.name].enable_scheduled_backlog = curDefault.enable_scheduled_backlog
return filter(lambda x: x, providerList)
@ -156,10 +157,14 @@ def makeNewznabProvider(configString):
search_fallback = 0
enable_recentsearch = 0
enable_backlog = 0
enable_scheduled_backlog = 1
try:
values = configString.split('|')
if len(values) == 9:
if len(values) == 10:
name, url, key, cat_ids, enabled, search_mode, search_fallback, enable_recentsearch, enable_backlog, \
enable_scheduled_backlog = values
elif len(values) == 9:
name, url, key, cat_ids, enabled, search_mode, search_fallback, enable_recentsearch, enable_backlog = values
else:
name = values[0]
@ -175,7 +180,7 @@ def makeNewznabProvider(configString):
newProvider = newznab.NewznabProvider(name, url, key=key, cat_ids=cat_ids, search_mode=search_mode,
search_fallback=search_fallback, enable_recentsearch=enable_recentsearch,
enable_backlog=enable_backlog)
enable_backlog=enable_backlog, enable_scheduled_backlog=enable_scheduled_backlog)
newProvider.enabled = enabled == '1'
return newProvider
@ -204,10 +209,14 @@ def makeTorrentRssProvider(configString):
search_fallback = 0
enable_recentsearch = 0
enable_backlog = 0
enable_scheduled_backlog = 1
try:
values = configString.split('|')
if len(values) == 8:
if len(values) == 9:
name, url, cookies, enabled, search_mode, search_fallback, enable_recentsearch, enable_backlog, \
enable_scheduled_backlog = values
elif len(values) == 8:
name, url, cookies, enabled, search_mode, search_fallback, enable_recentsearch, enable_backlog = values
else:
name = values[0]
@ -224,7 +233,7 @@ def makeTorrentRssProvider(configString):
return
newProvider = torrentRss.TorrentRssProvider(name, url, cookies, search_mode, search_fallback, enable_recentsearch,
enable_backlog)
enable_backlog, enable_scheduled_backlog)
newProvider.enabled = enabled == '1'
return newProvider

View file

@ -70,6 +70,7 @@ class GenericProvider:
self.enabled = False
self.enable_recentsearch = False
self.enable_backlog = False
self.enable_scheduled_backlog = True
self.categories = None
self.cache = tvcache.TVCache(self)

View file

@ -34,6 +34,7 @@ from sickbeard.indexers.indexer_config import *
from io import BytesIO
from lib.dateutil import parser
from sickbeard.network_timezones import sb_timezone
from sickbeard.helpers import tryInt
try:
from lxml import etree
@ -90,7 +91,7 @@ class NewznabConstants:
class NewznabProvider(generic.NZBProvider):
def __init__(self, name, url, key='', cat_ids=None, search_mode=None,
search_fallback=False, enable_recentsearch=False, enable_backlog=False):
search_fallback=False, enable_recentsearch=False, enable_backlog=False, enable_scheduled_backlog=False):
generic.NZBProvider.__init__(self, name, True, False)
self.url = url
@ -100,7 +101,8 @@ class NewznabProvider(generic.NZBProvider):
self.search_mode = search_mode or 'eponly'
self.search_fallback = search_fallback
self.enable_recentsearch = enable_recentsearch
self.enable_backlog = enable_backlog
self.enable_backlog = bool(tryInt(enable_backlog))
self.enable_scheduled_backlog = bool(tryInt(enable_scheduled_backlog))
self.needs_auth = '0' != self.key.strip() # '0' in the key setting indicates that api_key is not needed
self.default = False
self._caps = {}
@ -295,9 +297,10 @@ class NewznabProvider(generic.NZBProvider):
return True
def config_str(self):
return '%s|%s|%s|%s|%i|%s|%i|%i|%i' \
return '%s|%s|%s|%s|%i|%s|%i|%i|%i|%i' \
% (self.name or '', self.url or '', self.maybe_apikey() or '', self.cat_ids or '', self.enabled,
self.search_mode or '', self.search_fallback, self.enable_recentsearch, self.enable_backlog)
self.search_mode or '', self.search_fallback, self.enable_recentsearch, self.enable_backlog,
self.enable_scheduled_backlog)
def _season_strings(self, ep_obj):

View file

@ -28,8 +28,9 @@ from lib.bencode import bdecode
class TorrentRssProvider(generic.TorrentProvider):
def __init__(self, name, url, cookies='', search_mode='eponly', search_fallback=False,
enable_recentsearch=False, enable_backlog=False):
enable_recentsearch=False, enable_backlog=False, enable_scheduled_backlog=False):
self.enable_backlog = bool(tryInt(enable_backlog))
self.enable_scheduled_backlog = bool(tryInt(enable_scheduled_backlog))
generic.TorrentProvider.__init__(self, name, supports_backlog=self.enable_backlog, cache_update_freq=15)
self.url = url.rstrip('/')
@ -48,9 +49,10 @@ class TorrentRssProvider(generic.TorrentProvider):
def config_str(self):
return '%s|%s|%s|%d|%s|%d|%d|%d' % (
return '%s|%s|%s|%d|%s|%d|%d|%d|%d' % (
self.name or '', self.url or '', self.cookies or '', self.enabled,
self.search_mode or '', self.search_fallback, self.enable_recentsearch, self.enable_backlog)
self.search_mode or '', self.search_fallback, self.enable_recentsearch, self.enable_backlog,
self.enable_scheduled_backlog)
def _title_and_url(self, item):

View file

@ -465,7 +465,7 @@ def search_for_needed_episodes(episodes):
return found_results.values()
def search_providers(show, episodes, manual_search=False, torrent_only=False, try_other_searches=False):
def search_providers(show, episodes, manual_search=False, torrent_only=False, try_other_searches=False, scheduled=False):
found_results = {}
final_results = []
@ -474,7 +474,8 @@ def search_providers(show, episodes, manual_search=False, torrent_only=False, tr
orig_thread_name = threading.currentThread().name
provider_list = [x for x in sickbeard.providers.sortedProviderList() if x.is_active() and x.enable_backlog and
(not torrent_only or x.providerType == GenericProvider.TORRENT)]
(not torrent_only or x.providerType == GenericProvider.TORRENT) and
(not scheduled or x.enable_scheduled_backlog)]
for cur_provider in provider_list:
if cur_provider.anime_only and not show.is_anime:
logger.log(u'%s is not an anime, skipping' % show.name, logger.DEBUG)

View file

@ -429,7 +429,8 @@ class BacklogQueueItem(generic_queue.QueueItem):
logger.log(u'Beginning backlog search for: [%s]' % self.show.name)
search_result = search.search_providers(
self.show, self.segment, False,
try_other_searches=(not self.standard_backlog or not self.limited_backlog))
try_other_searches=(not self.standard_backlog or not self.limited_backlog),
scheduled=self.standard_backlog)
if search_result:
for result in search_result:

View file

@ -5247,7 +5247,7 @@ class ConfigProviders(Config):
if cur_id + '_' + attr in kwargs:
setattr(nzb_src, attr, str(kwargs.get(cur_id + '_' + attr)).strip())
for attr in ['search_fallback', 'enable_recentsearch', 'enable_backlog']:
for attr in ['search_fallback', 'enable_recentsearch', 'enable_backlog', 'enable_scheduled_backlog']:
setattr(nzb_src, attr, config.checkbox_to_value(kwargs.get(cur_id + '_' + attr)))
else:
@ -5350,7 +5350,7 @@ class ConfigProviders(Config):
setattr(torrent_src, attr, config.to_int(str(kwargs.get(src_id_prefix + attr)).strip()))
for attr in [x for x in ['confirmed', 'freeleech', 'reject_m2ts', 'enable_recentsearch',
'enable_backlog', 'search_fallback']
'enable_backlog', 'search_fallback', 'enable_scheduled_backlog']
if hasattr(torrent_src, x) and src_id_prefix + attr in kwargs]:
setattr(torrent_src, attr, config.checkbox_to_value(kwargs.get(src_id_prefix + attr)))
@ -5392,7 +5392,7 @@ class ConfigProviders(Config):
setattr(nzb_src, attr, config.checkbox_to_value(kwargs.get(src_id_prefix + attr)) or
not getattr(nzb_src, 'supports_backlog', True))
for attr in [x for x in ['search_fallback', 'enable_backlog'] if hasattr(nzb_src, x)]:
for attr in [x for x in ['search_fallback', 'enable_backlog', 'enable_scheduled_backlog'] if hasattr(nzb_src, x)]:
setattr(nzb_src, attr, config.checkbox_to_value(kwargs.get(src_id_prefix + attr)))
sickbeard.NEWZNAB_DATA = '!!!'.join([x.config_str() for x in sickbeard.newznabProviderList])