From 3d7e460079825dee69a4ebe1db8034f93eac4ead Mon Sep 17 00:00:00 2001 From: echel0n Date: Thu, 11 Dec 2014 10:06:50 -0800 Subject: [PATCH] Fixed issues with newznab/torrent provider searches. Fixed issues with browser launches at startup. Fixed issues with feedparser and feedcache relating to provider searches. --- SickBeard.py | 4 ++-- sickbeard/__init__.py | 9 ++++---- sickbeard/common.py | 2 ++ sickbeard/providers/animezb.py | 2 +- sickbeard/providers/ezrss.py | 2 +- sickbeard/providers/fanzub.py | 2 +- sickbeard/providers/generic.py | 13 +++--------- sickbeard/providers/newznab.py | 33 ++++++++++++++++------------- sickbeard/providers/nyaatorrents.py | 4 ++-- sickbeard/providers/omgwtfnzbs.py | 4 ++-- sickbeard/providers/rsstorrent.py | 14 ++++++------ sickbeard/providers/tvtorrents.py | 10 +++++---- sickbeard/providers/womble.py | 2 +- sickbeard/rssfeeds.py | 7 ++++-- sickbeard/tvcache.py | 7 ++---- 15 files changed, 56 insertions(+), 59 deletions(-) diff --git a/SickBeard.py b/SickBeard.py index 4af8d574..68596c44 100755 --- a/SickBeard.py +++ b/SickBeard.py @@ -343,7 +343,7 @@ class SickRage(object): logger.ERROR) if sickbeard.LAUNCH_BROWSER and not self.runAsDaemon: 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) if self.consoleLogging: @@ -368,7 +368,7 @@ class SickRage(object): # Launch browser 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 while (True): diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index 8d433b5b..fd8f4169 100755 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -1840,13 +1840,12 @@ def save_config(): new_config.write() -def launchBrowser(startPort=None): +def launchBrowser(protocol='http', startPort=None, web_root='/'): if not startPort: startPort = WEB_PORT - if ENABLE_HTTPS: - browserURL = 'https://localhost:%d/' % (startPort) - else: - browserURL = 'http://localhost:%d/' % (startPort) + + browserURL = '%s://localhost:%d%s' % (protocol, startPort, web_root) + try: webbrowser.open(browserURL, 2, 1) except: diff --git a/sickbeard/common.py b/sickbeard/common.py index d646617f..24a31cc8 100644 --- a/sickbeard/common.py +++ b/sickbeard/common.py @@ -176,6 +176,8 @@ class Quality: """ Return The quality from the scene episode File """ + if not name: + return Quality.UNKNOWN name = os.path.basename(name) diff --git a/sickbeard/providers/animezb.py b/sickbeard/providers/animezb.py index 121943cc..72c435a4 100644 --- a/sickbeard/providers/animezb.py +++ b/sickbeard/providers/animezb.py @@ -79,7 +79,7 @@ class Animezb(generic.NZBProvider): logger.log(u"Search url: " + search_url, logger.DEBUG) 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) if title and url: diff --git a/sickbeard/providers/ezrss.py b/sickbeard/providers/ezrss.py index 86c88d7b..38a2d56c 100644 --- a/sickbeard/providers/ezrss.py +++ b/sickbeard/providers/ezrss.py @@ -123,7 +123,7 @@ class EZRSSProvider(generic.TorrentProvider): logger.log(u"Search string: " + search_url, logger.DEBUG) 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) diff --git a/sickbeard/providers/fanzub.py b/sickbeard/providers/fanzub.py index dcdcfe27..b1fa3e1d 100644 --- a/sickbeard/providers/fanzub.py +++ b/sickbeard/providers/fanzub.py @@ -74,7 +74,7 @@ class Fanzub(generic.NZBProvider): logger.log(u"Search url: " + search_url, logger.DEBUG) 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) if title and url: diff --git a/sickbeard/providers/generic.py b/sickbeard/providers/generic.py index 0ff7ed03..676cb1ef 100644 --- a/sickbeard/providers/generic.py +++ b/sickbeard/providers/generic.py @@ -214,7 +214,7 @@ class GenericProvider: 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) return quality @@ -236,18 +236,11 @@ class GenericProvider: Returns: A tuple containing two strings representing title and URL respectively """ - title = None - url = None - - if 'title' in item: - title = item.title - + title = item.get('title') if title: title = title.replace(' ', '.') - if 'link' in item: - url = item.link - + url = item.get('link') if url: url = url.replace('&', '&') diff --git a/sickbeard/providers/newznab.py b/sickbeard/providers/newznab.py index 86cd424f..6e2a33cc 100755 --- a/sickbeard/providers/newznab.py +++ b/sickbeard/providers/newznab.py @@ -297,7 +297,7 @@ class NewznabProvider(generic.NZBProvider): if not self._checkAuthFromData(data): break - for item in data.entries or []: + for item in data.get('entries', []): (title, url) = self._get_title_and_url(item) @@ -311,8 +311,8 @@ class NewznabProvider(generic.NZBProvider): # get total and offset attribs try: if total == 0: - total = int(data.feed.newznab_response['total'] or 0) - offset = int(data.feed.newznab_response['offset'] or 0) + total = int(data['feed']['newznab_response']['total'] or 0) + offset = int(data['feed']['newznab_response']['offset'] or 0) except AttributeError: break @@ -377,13 +377,20 @@ class NewznabProvider(generic.NZBProvider): (title, url) = self._get_title_and_url(item) - if item.has_key('published_parsed') and item['published_parsed']: - result_date = item.published_parsed - if result_date: - result_date = datetime.datetime(*result_date[0:6]) - else: - logger.log(u"Unable to figure out the date for entry " + title + ", skipping it") - continue + try: + result_date = datetime.datetime(*item['published_parsed'][0:6]) + except AttributeError: + try: + result_date = datetime.datetime(*item['updated_parsed'][0:6]) + except AttributeError: + 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: search_result = classes.Proper(title, url, result_date, self.show) @@ -425,12 +432,8 @@ class NewznabCache(tvcache.TVCache): def _parseItem(self, item): (title, url) = self._get_title_and_url(item) - attrs = item.newznab_attr - if not isinstance(attrs, list): - attrs = [item.newznab_attr] - tvrageid = 0 - for attr in attrs: + for attr in item.get('newznab_attr', []): if attr['name'] == 'tvrageid': tvrageid = int(attr['value'] or 0) break diff --git a/sickbeard/providers/nyaatorrents.py b/sickbeard/providers/nyaatorrents.py index 41ee3783..1b10393b 100644 --- a/sickbeard/providers/nyaatorrents.py +++ b/sickbeard/providers/nyaatorrents.py @@ -51,7 +51,7 @@ class NyaaProvider(generic.TorrentProvider): return 'nyaatorrents.png' def getQuality(self, item, anime=False): - title = item.title + title = item.get('title') quality = Quality.sceneQuality(title, anime) return quality @@ -80,7 +80,7 @@ class NyaaProvider(generic.TorrentProvider): logger.log(u"Search string: " + searchURL, logger.DEBUG) 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) if title and url: diff --git a/sickbeard/providers/omgwtfnzbs.py b/sickbeard/providers/omgwtfnzbs.py index b0c5cca9..179c498b 100644 --- a/sickbeard/providers/omgwtfnzbs.py +++ b/sickbeard/providers/omgwtfnzbs.py @@ -163,12 +163,12 @@ class OmgwtfnzbsCache(tvcache.TVCache): 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: title = u'' + title title = title.replace(' ', '.') - url = item.link if item.link else None + url = item.get('link') if url: url = url.replace('&', '&') diff --git a/sickbeard/providers/rsstorrent.py b/sickbeard/providers/rsstorrent.py index 6d19ead4..73159128 100644 --- a/sickbeard/providers/rsstorrent.py +++ b/sickbeard/providers/rsstorrent.py @@ -74,20 +74,18 @@ class TorrentRssProvider(generic.TorrentProvider): def _get_title_and_url(self, item): - title, url = None, None - - title = item.title - + title = item.get('title') if title: title = u'' + title title = title.replace(' ', '.') - attempt_list = [lambda: item.torrent_magneturi, + attempt_list = [lambda: item.get('torrent_magneturi'), lambda: item.enclosures[0].href, - lambda: item.link] + lambda: item.get('link')] + url = None for cur_attempt in attempt_list: try: url = cur_attempt() @@ -95,9 +93,9 @@ class TorrentRssProvider(generic.TorrentProvider): continue if title and url: - return (title, url) + break - return (title, url) + return title, url def validateRSS(self): diff --git a/sickbeard/providers/tvtorrents.py b/sickbeard/providers/tvtorrents.py index af0628e6..6981341d 100644 --- a/sickbeard/providers/tvtorrents.py +++ b/sickbeard/providers/tvtorrents.py @@ -60,13 +60,15 @@ class TvTorrentsProvider(generic.TorrentProvider): return True def _checkAuthFromData(self, data): - if not (data.entries and data.feed): + if not (data.get('entries') and data.get('feed')): return self._checkAuth() - try:title = data['feed']['title'] - except:return False + try: + 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.DEBUG) raise AuthException( diff --git a/sickbeard/providers/womble.py b/sickbeard/providers/womble.py index 505713cc..d525f21e 100644 --- a/sickbeard/providers/womble.py +++ b/sickbeard/providers/womble.py @@ -67,7 +67,7 @@ class WombleCache(tvcache.TVCache): myDB.mass_action(cl) 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() diff --git a/sickbeard/rssfeeds.py b/sickbeard/rssfeeds.py index 73a4f729..a8848627 100644 --- a/sickbeard/rssfeeds.py +++ b/sickbeard/rssfeeds.py @@ -15,6 +15,7 @@ from sickbeard.exceptions import ex from feedcache.cache import Cache from sqliteshelf import SQLiteShelf + class RSSFeeds: def __init__(self, db_name): try: @@ -47,8 +48,10 @@ class RSSFeeds: resp = fc.fetch(url, False, False, request_headers) for item in items: - try:data[item] = resp[item] - except:continue + try: + data[item] = resp[item] + except: + continue finally: self.rssDB.close() diff --git a/sickbeard/tvcache.py b/sickbeard/tvcache.py index f9fc6842..a9ee35a5 100644 --- a/sickbeard/tvcache.py +++ b/sickbeard/tvcache.py @@ -122,7 +122,7 @@ class TVCache(): self.setLastUpdate() cl = [] - for item in data['entries']: + for item in data.get('entries', []): ci = self._parseItem(item) if ci is not None: cl.append(ci) @@ -281,10 +281,7 @@ class TVCache(): def searchCache(self, episode, manualSearch=False): neededEps = self.findNeededEpisodes(episode, manualSearch) - if len(neededEps) > 0: - return neededEps[episode] - else: - return [] + return neededEps[episode] if len(neededEps) > 0 else [] def listPropers(self, date=None, delimiter="."): myDB = self._getDB()