1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-12 11:02:21 -05:00

Fixed issues with newznab/torrent provider searches.

Fixed issues with browser launches at startup.
Fixed issues with feedparser and feedcache relating to provider searches.
This commit is contained in:
echel0n 2014-12-11 10:06:50 -08:00
parent 78bfc40757
commit 3d7e460079
15 changed files with 56 additions and 59 deletions

View File

@ -343,7 +343,7 @@ class SickRage(object):
logger.ERROR) logger.ERROR)
if sickbeard.LAUNCH_BROWSER and not self.runAsDaemon: if sickbeard.LAUNCH_BROWSER and not self.runAsDaemon:
logger.log(u"Launching browser and exiting", logger.ERROR) logger.log(u"Launching browser and exiting", logger.ERROR)
sickbeard.launchBrowser(self.startPort) sickbeard.launchBrowser('https' if sickbeard.ENABLE_HTTPS else 'http', self.startPort, sickbeard.WEB_ROOT)
os._exit(1) os._exit(1)
if self.consoleLogging: if self.consoleLogging:
@ -368,7 +368,7 @@ class SickRage(object):
# Launch browser # Launch browser
if sickbeard.LAUNCH_BROWSER and not (self.noLaunch or self.runAsDaemon): if sickbeard.LAUNCH_BROWSER and not (self.noLaunch or self.runAsDaemon):
sickbeard.launchBrowser(self.startPort) sickbeard.launchBrowser('https' if sickbeard.ENABLE_HTTPS else 'http', self.startPort, sickbeard.WEB_ROOT)
# main loop # main loop
while (True): while (True):

View File

@ -1840,13 +1840,12 @@ def save_config():
new_config.write() new_config.write()
def launchBrowser(startPort=None): def launchBrowser(protocol='http', startPort=None, web_root='/'):
if not startPort: if not startPort:
startPort = WEB_PORT startPort = WEB_PORT
if ENABLE_HTTPS:
browserURL = 'https://localhost:%d/' % (startPort) browserURL = '%s://localhost:%d%s' % (protocol, startPort, web_root)
else:
browserURL = 'http://localhost:%d/' % (startPort)
try: try:
webbrowser.open(browserURL, 2, 1) webbrowser.open(browserURL, 2, 1)
except: except:

View File

@ -176,6 +176,8 @@ class Quality:
""" """
Return The quality from the scene episode File Return The quality from the scene episode File
""" """
if not name:
return Quality.UNKNOWN
name = os.path.basename(name) name = os.path.basename(name)

View File

@ -79,7 +79,7 @@ class Animezb(generic.NZBProvider):
logger.log(u"Search url: " + search_url, logger.DEBUG) logger.log(u"Search url: " + search_url, logger.DEBUG)
results = [] results = []
for curItem in self.cache.getRSSFeed(search_url, items=['entries']) or []: for curItem in self.cache.getRSSFeed(search_url, items=['entries'])['entries'] or []:
(title, url) = self._get_title_and_url(curItem) (title, url) = self._get_title_and_url(curItem)
if title and url: if title and url:

View File

@ -123,7 +123,7 @@ class EZRSSProvider(generic.TorrentProvider):
logger.log(u"Search string: " + search_url, logger.DEBUG) logger.log(u"Search string: " + search_url, logger.DEBUG)
results = [] results = []
for curItem in self.cache.getRSSFeed(search_url, items=['entries']) or []: for curItem in self.cache.getRSSFeed(search_url, items=['entries'])['entries'] or []:
(title, url) = self._get_title_and_url(curItem) (title, url) = self._get_title_and_url(curItem)

View File

@ -74,7 +74,7 @@ class Fanzub(generic.NZBProvider):
logger.log(u"Search url: " + search_url, logger.DEBUG) logger.log(u"Search url: " + search_url, logger.DEBUG)
results = [] results = []
for curItem in self.cache.getRSSFeed(search_url, items=['entries']) or []: for curItem in self.cache.getRSSFeed(search_url, items=['entries'])['entries'] or []:
(title, url) = self._get_title_and_url(curItem) (title, url) = self._get_title_and_url(curItem)
if title and url: if title and url:

View File

@ -214,7 +214,7 @@ class GenericProvider:
Returns a Quality value obtained from the node's data Returns a Quality value obtained from the node's data
""" """
(title, url) = self._get_title_and_url(item) # @UnusedVariable (title, url) = self._get_title_and_url(item)
quality = Quality.sceneQuality(title, anime) quality = Quality.sceneQuality(title, anime)
return quality return quality
@ -236,18 +236,11 @@ class GenericProvider:
Returns: A tuple containing two strings representing title and URL respectively Returns: A tuple containing two strings representing title and URL respectively
""" """
title = None title = item.get('title')
url = None
if 'title' in item:
title = item.title
if title: if title:
title = title.replace(' ', '.') title = title.replace(' ', '.')
if 'link' in item: url = item.get('link')
url = item.link
if url: if url:
url = url.replace('&', '&') url = url.replace('&', '&')

View File

@ -297,7 +297,7 @@ class NewznabProvider(generic.NZBProvider):
if not self._checkAuthFromData(data): if not self._checkAuthFromData(data):
break break
for item in data.entries or []: for item in data.get('entries', []):
(title, url) = self._get_title_and_url(item) (title, url) = self._get_title_and_url(item)
@ -311,8 +311,8 @@ class NewznabProvider(generic.NZBProvider):
# get total and offset attribs # get total and offset attribs
try: try:
if total == 0: if total == 0:
total = int(data.feed.newznab_response['total'] or 0) total = int(data['feed']['newznab_response']['total'] or 0)
offset = int(data.feed.newznab_response['offset'] or 0) offset = int(data['feed']['newznab_response']['offset'] or 0)
except AttributeError: except AttributeError:
break break
@ -377,13 +377,20 @@ class NewznabProvider(generic.NZBProvider):
(title, url) = self._get_title_and_url(item) (title, url) = self._get_title_and_url(item)
if item.has_key('published_parsed') and item['published_parsed']: try:
result_date = item.published_parsed result_date = datetime.datetime(*item['published_parsed'][0:6])
if result_date: except AttributeError:
result_date = datetime.datetime(*result_date[0:6]) try:
else: result_date = datetime.datetime(*item['updated_parsed'][0:6])
logger.log(u"Unable to figure out the date for entry " + title + ", skipping it") except AttributeError:
continue try:
result_date = datetime.datetime(*item['created_parsed'][0:6])
except AttributeError:
try:
result_date = datetime.datetime(*item['date'][0:6])
except AttributeError:
logger.log(u"Unable to figure out the date for entry " + title + ", skipping it")
continue
if not search_date or result_date > search_date: if not search_date or result_date > search_date:
search_result = classes.Proper(title, url, result_date, self.show) search_result = classes.Proper(title, url, result_date, self.show)
@ -425,12 +432,8 @@ class NewznabCache(tvcache.TVCache):
def _parseItem(self, item): def _parseItem(self, item):
(title, url) = self._get_title_and_url(item) (title, url) = self._get_title_and_url(item)
attrs = item.newznab_attr
if not isinstance(attrs, list):
attrs = [item.newznab_attr]
tvrageid = 0 tvrageid = 0
for attr in attrs: for attr in item.get('newznab_attr', []):
if attr['name'] == 'tvrageid': if attr['name'] == 'tvrageid':
tvrageid = int(attr['value'] or 0) tvrageid = int(attr['value'] or 0)
break break

View File

@ -51,7 +51,7 @@ class NyaaProvider(generic.TorrentProvider):
return 'nyaatorrents.png' return 'nyaatorrents.png'
def getQuality(self, item, anime=False): def getQuality(self, item, anime=False):
title = item.title title = item.get('title')
quality = Quality.sceneQuality(title, anime) quality = Quality.sceneQuality(title, anime)
return quality return quality
@ -80,7 +80,7 @@ class NyaaProvider(generic.TorrentProvider):
logger.log(u"Search string: " + searchURL, logger.DEBUG) logger.log(u"Search string: " + searchURL, logger.DEBUG)
results = [] results = []
for curItem in self.cache.getRSSFeed(searchURL, items=['entries']) or []: for curItem in self.cache.getRSSFeed(searchURL, items=['entries'])['entries'] or []:
(title, url) = self._get_title_and_url(curItem) (title, url) = self._get_title_and_url(curItem)
if title and url: if title and url:

View File

@ -163,12 +163,12 @@ class OmgwtfnzbsCache(tvcache.TVCache):
Returns: A tuple containing two strings representing title and URL respectively Returns: A tuple containing two strings representing title and URL respectively
""" """
title = item.title if item.title else None title = item.get('title')
if title: if title:
title = u'' + title title = u'' + title
title = title.replace(' ', '.') title = title.replace(' ', '.')
url = item.link if item.link else None url = item.get('link')
if url: if url:
url = url.replace('&', '&') url = url.replace('&', '&')

View File

@ -74,20 +74,18 @@ class TorrentRssProvider(generic.TorrentProvider):
def _get_title_and_url(self, item): def _get_title_and_url(self, item):
title, url = None, None title = item.get('title')
title = item.title
if title: if title:
title = u'' + title title = u'' + title
title = title.replace(' ', '.') title = title.replace(' ', '.')
attempt_list = [lambda: item.torrent_magneturi, attempt_list = [lambda: item.get('torrent_magneturi'),
lambda: item.enclosures[0].href, lambda: item.enclosures[0].href,
lambda: item.link] lambda: item.get('link')]
url = None
for cur_attempt in attempt_list: for cur_attempt in attempt_list:
try: try:
url = cur_attempt() url = cur_attempt()
@ -95,9 +93,9 @@ class TorrentRssProvider(generic.TorrentProvider):
continue continue
if title and url: if title and url:
return (title, url) break
return (title, url) return title, url
def validateRSS(self): def validateRSS(self):

View File

@ -60,13 +60,15 @@ class TvTorrentsProvider(generic.TorrentProvider):
return True return True
def _checkAuthFromData(self, data): def _checkAuthFromData(self, data):
if not (data.entries and data.feed): if not (data.get('entries') and data.get('feed')):
return self._checkAuth() return self._checkAuth()
try:title = data['feed']['title'] try:
except:return False title = data['feed']['title']
except:
return False
if "User can't be found" in title or "Invalid Hash" in title: if title and ("User can't be found" in title or "Invalid Hash" in title):
logger.log(u"Incorrect authentication credentials for " + self.name + " : " + str(title), logger.log(u"Incorrect authentication credentials for " + self.name + " : " + str(title),
logger.DEBUG) logger.DEBUG)
raise AuthException( raise AuthException(

View File

@ -67,7 +67,7 @@ class WombleCache(tvcache.TVCache):
myDB.mass_action(cl) myDB.mass_action(cl)
def _checkAuth(self, data): def _checkAuth(self, data):
return data if data.feed.title != 'Invalid Link' else None return data if data.get('feed') and data['feed']['title'] != 'Invalid Link' else None
provider = WombleProvider() provider = WombleProvider()

View File

@ -15,6 +15,7 @@ from sickbeard.exceptions import ex
from feedcache.cache import Cache from feedcache.cache import Cache
from sqliteshelf import SQLiteShelf from sqliteshelf import SQLiteShelf
class RSSFeeds: class RSSFeeds:
def __init__(self, db_name): def __init__(self, db_name):
try: try:
@ -47,8 +48,10 @@ class RSSFeeds:
resp = fc.fetch(url, False, False, request_headers) resp = fc.fetch(url, False, False, request_headers)
for item in items: for item in items:
try:data[item] = resp[item] try:
except:continue data[item] = resp[item]
except:
continue
finally: finally:
self.rssDB.close() self.rssDB.close()

View File

@ -122,7 +122,7 @@ class TVCache():
self.setLastUpdate() self.setLastUpdate()
cl = [] cl = []
for item in data['entries']: for item in data.get('entries', []):
ci = self._parseItem(item) ci = self._parseItem(item)
if ci is not None: if ci is not None:
cl.append(ci) cl.append(ci)
@ -281,10 +281,7 @@ class TVCache():
def searchCache(self, episode, manualSearch=False): def searchCache(self, episode, manualSearch=False):
neededEps = self.findNeededEpisodes(episode, manualSearch) neededEps = self.findNeededEpisodes(episode, manualSearch)
if len(neededEps) > 0: return neededEps[episode] if len(neededEps) > 0 else []
return neededEps[episode]
else:
return []
def listPropers(self, date=None, delimiter="."): def listPropers(self, date=None, delimiter="."):
myDB = self._getDB() myDB = self._getDB()