Fix add custom torrent RSS.

resolves SickGear/SickGear#781
This commit is contained in:
JackDandy 2016-09-26 00:46:36 +01:00
parent 512a67d0e5
commit 326f5529d0
6 changed files with 36 additions and 39 deletions

View file

@ -179,6 +179,7 @@
* Change handle when a torrent provider goes down and its urls are cleared * Change handle when a torrent provider goes down and its urls are cleared
* Add handler for when rar files can not be opened during post processing * Add handler for when rar files can not be opened during post processing
* Fix join clean up * Fix join clean up
* Fix add custom torrent RSS
### 0.11.15 (2016-09-13 19:50:00 UTC) ### 0.11.15 (2016-09-13 19:50:00 UTC)

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

View file

@ -110,7 +110,7 @@
<input type="checkbox" id="enable_$cur_name" class="provider_enabler" <%= html_checked if cur_provider.is_enabled() else '' %>/> <input type="checkbox" id="enable_$cur_name" class="provider_enabler" <%= html_checked if cur_provider.is_enabled() else '' %>/>
<a href="<%= anon_url(cur_url) %>" class="imgLink" rel="noreferrer" onclick="window.open(this.href,'_blank');return false;"><img src="$sbRoot/images/providers/$cur_provider.image_name()" alt="$tip" title="$tip" width="16" height="16" style="vertical-align:middle" /></a> <a href="<%= anon_url(cur_url) %>" class="imgLink" rel="noreferrer" onclick="window.open(this.href,'_blank');return false;"><img src="$sbRoot/images/providers/$cur_provider.image_name()" alt="$tip" title="$tip" width="16" height="16" style="vertical-align:middle" /></a>
<span style="vertical-align:middle">$cur_provider.name$state</span> <span style="vertical-align:middle">$cur_provider.name$state</span>
#if $cur_provider.is_public_access()# #if $cur_provider.is_public_access() and type($cur_provider).__name__ not in ['TorrentRssProvider']
<span style="font-size:10px;vertical-align:top;font-weight:normal">(PA)</span> <span style="font-size:10px;vertical-align:top;font-weight:normal">(PA)</span>
#end if# #end if#
#if not $cur_provider.supports_backlog#*#end if# #if not $cur_provider.supports_backlog#*#end if#
@ -531,7 +531,7 @@ name = '' if not client else get_client_instance(sickbeard.TORRENT_METHOD)().nam
</label> </label>
</div> </div>
#end if #end if
#if $hasattr($cur_torrent_provider, 'enable_recentsearch'): #if $hasattr($cur_torrent_provider, 'enable_recentsearch') and $cur_torrent_provider.supports_backlog:
<div class="field-pair"> <div class="field-pair">
<label for="${cur_torrent_provider.get_id()}_enable_recentsearch"> <label for="${cur_torrent_provider.get_id()}_enable_recentsearch">
<span class="component-title">Enable recent searches</span> <span class="component-title">Enable recent searches</span>
@ -578,6 +578,11 @@ name = '' if not client else get_client_instance(sickbeard.TORRENT_METHOD)().nam
</label> </label>
</div> </div>
#end if #end if
#if not $cur_torrent_provider.supports_backlog:
<div class="field-pair">
<span class="component-desc">The latest releases are the focus of this provider, no backlog searching</span>
</div>
#end if
</div> </div>
#end for #end for
@ -731,6 +736,7 @@ name = '' if not client else get_client_instance(sickbeard.TORRENT_METHOD)().nam
<span class="component-desc"> <span class="component-desc">
<input type="text" id="torrentrss_cookies" class="form-control input-sm input350" /> <input type="text" id="torrentrss_cookies" class="form-control input-sm input350" />
<p>eg. uid=xx;pass=yy</p> <p>eg. uid=xx;pass=yy</p>
<div class="clear-left"><p>enter [ <span class="grey-text">sg=0</span> ] if not required (a URL containing a key may not need cookies)</p></div>
</span> </span>
</label> </label>
</div> </div>

View file

@ -1072,7 +1072,8 @@ def initialize(consoleLogging=True):
torrent_prov.reject_m2ts = bool(check_setting_int(CFG, prov_id_uc, prov_id + '_reject_m2ts', 0)) torrent_prov.reject_m2ts = bool(check_setting_int(CFG, prov_id_uc, prov_id + '_reject_m2ts', 0))
if hasattr(torrent_prov, 'enable_recentsearch'): if hasattr(torrent_prov, 'enable_recentsearch'):
torrent_prov.enable_recentsearch = bool(check_setting_int(CFG, prov_id_uc, torrent_prov.enable_recentsearch = bool(check_setting_int(CFG, prov_id_uc,
prov_id + '_enable_recentsearch', 1)) prov_id + '_enable_recentsearch', 1)) or \
not getattr(torrent_prov, 'supports_backlog', True)
if hasattr(torrent_prov, 'enable_backlog'): if hasattr(torrent_prov, 'enable_backlog'):
torrent_prov.enable_backlog = bool(check_setting_int(CFG, prov_id_uc, prov_id + '_enable_backlog', 1)) torrent_prov.enable_backlog = bool(check_setting_int(CFG, prov_id_uc, prov_id + '_enable_backlog', 1))
if hasattr(torrent_prov, 'search_mode'): if hasattr(torrent_prov, 'search_mode'):

View file

@ -19,6 +19,7 @@ import re
from . import generic from . import generic
from sickbeard import logger, tvcache from sickbeard import logger, tvcache
from sickbeard.helpers import tryInt
from sickbeard.exceptions import ex from sickbeard.exceptions import ex
from sickbeard.rssfeeds import RSSFeeds from sickbeard.rssfeeds import RSSFeeds
from lib.bencode import bdecode from lib.bencode import bdecode
@ -28,32 +29,28 @@ class TorrentRssProvider(generic.TorrentProvider):
def __init__(self, name, url, cookies='', search_mode='eponly', search_fallback=False, def __init__(self, name, url, cookies='', search_mode='eponly', search_fallback=False,
enable_recentsearch=False, enable_backlog=False): enable_recentsearch=False, enable_backlog=False):
generic.TorrentProvider.__init__(self, name) self.enable_backlog = bool(tryInt(enable_backlog))
generic.TorrentProvider.__init__(self, name, supports_backlog=self.enable_backlog, cache_update_freq=15)
self.url = url.rstrip('/') self.url = url.rstrip('/')
self.url_base = self.url
self.cookies = cookies self.cookies = cookies
self.enable_recentsearch = enable_recentsearch self.enable_recentsearch = bool(tryInt(enable_recentsearch)) or not self.enable_backlog
self.enable_backlog = enable_backlog
self.search_mode = search_mode self.search_mode = search_mode
self.search_fallback = search_fallback self.search_fallback = bool(tryInt(search_fallback))
self.feeder = RSSFeeds(self) self.feeder = RSSFeeds(self)
self.cache = TorrentRssCache(self)
def image_name(self): def image_name(self):
return generic.GenericProvider.image_name(self, 'torrentrss') return generic.GenericProvider.image_name(self, 'torrentrss')
def config_str(self): def config_str(self):
return '%s|%s|%s|%d|%s|%d|%d|%d' % (self.name or '',
self.url or '', return '%s|%s|%s|%d|%s|%d|%d|%d' % (
self.cookies or '', self.name or '', self.url or '', self.cookies or '', self.enabled,
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)
def _title_and_url(self, item): def _title_and_url(self, item):
@ -63,15 +60,13 @@ class TorrentRssProvider(generic.TorrentProvider):
title = re.sub(r'\s+', '.', u'' + item.title) title = re.sub(r'\s+', '.', u'' + item.title)
attempt_list = [lambda: item.torrent_magneturi, attempt_list = [lambda: item.torrent_magneturi,
lambda: item.enclosures[0].href, lambda: item.enclosures[0].href,
lambda: item.link] lambda: item.link]
for cur_attempt in attempt_list: for cur_attempt in attempt_list:
try: try:
url = cur_attempt() url = cur_attempt()
except: except (StandardError, Exception):
continue continue
if title and url: if title and url:
@ -86,7 +81,7 @@ class TorrentRssProvider(generic.TorrentProvider):
return success, err_msg return success, err_msg
try: try:
items = self.cache_data() items = self._search_provider({'Validate': ['']})
for item in items: for item in items:
title, url = self._title_and_url(item) title, url = self._title_and_url(item)
@ -111,22 +106,14 @@ class TorrentRssProvider(generic.TorrentProvider):
except Exception as e: except Exception as e:
return False, 'Error when trying to load RSS: ' + ex(e) return False, 'Error when trying to load RSS: ' + ex(e)
def cache_data(self): def _search_provider(self, search_params, **kwargs):
logger.log(u'TorrentRssCache cache update URL: ' + self.url, logger.DEBUG) result = []
for mode in search_params.keys():
data = self.feeder.get_feed(self.url)
data = self.feeder.get_feed(self.url) result += (data and 'entries' in data) and data.entries or []
return [] if not (data and 'entries' in data) else data.entries self.log_result(mode, count=len(result), url=self.url)
return result
class TorrentRssCache(tvcache.TVCache):
def __init__(self, provider):
tvcache.TVCache.__init__(self, provider)
self.update_freq = 15
def _cache_data(self):
return self.provider.cache_data()

View file

@ -482,7 +482,8 @@ class MainHandler(WebHandler):
sql_results = list(set(sql_results)) sql_results = list(set(sql_results))
# make a dict out of the sql results # make a dict out of the sql results
sql_results = [dict(row) for row in sql_results] sql_results = [dict(row) for row in sql_results
if Quality.splitCompositeStatus(helpers.tryInt(row['status']))[0] not in qualities]
# multi dimension sort # multi dimension sort
sorts = { sorts = {
@ -4870,7 +4871,7 @@ class ConfigProviders(Config):
tempProvider = rsstorrent.TorrentRssProvider(name, url, cookies) tempProvider = rsstorrent.TorrentRssProvider(name, url, cookies)
if tempProvider.get_id() in providerDict: if tempProvider.get_id() in providerDict:
return json.dumps({'error': 'Exists as ' + providerDict[tempProvider.get_id()].name}) return json.dumps({'error': 'A provider exists as [%s]' % providerDict[tempProvider.get_id()].name})
else: else:
(succ, errMsg) = tempProvider.validate_feed() (succ, errMsg) = tempProvider.validate_feed()
if succ: if succ:
@ -5040,14 +5041,15 @@ class ConfigProviders(Config):
setattr(torrent_src, attr, key) setattr(torrent_src, attr, key)
attr = 'ratio' attr = 'ratio'
if hasattr(torrent_src, '_seed_' + attr): if hasattr(torrent_src, '_seed_' + attr) and src_id_prefix + attr in kwargs:
setattr(torrent_src, '_seed_' + attr, kwargs.get(src_id_prefix + attr, '').strip() or None) setattr(torrent_src, '_seed_' + attr, kwargs.get(src_id_prefix + attr, '').strip() or None)
for attr in [x for x in ['minseed', 'minleech'] if hasattr(torrent_src, x)]: for attr in [x for x in ['minseed', 'minleech'] if hasattr(torrent_src, x)]:
setattr(torrent_src, attr, config.to_int(str(kwargs.get(src_id_prefix + attr)).strip())) 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', for attr in [x for x in ['confirmed', 'freeleech', 'reject_m2ts', 'enable_recentsearch',
'enable_backlog', 'search_fallback'] if hasattr(torrent_src, x)]: 'enable_backlog', 'search_fallback']
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))) setattr(torrent_src, attr, config.checkbox_to_value(kwargs.get(src_id_prefix + attr)))
attr = 'seed_time' attr = 'seed_time'