From 02a91480255ced1791f3f1363077e53f2f741229 Mon Sep 17 00:00:00 2001 From: echel0n Date: Thu, 11 Dec 2014 11:22:06 -0800 Subject: [PATCH] Updated KAT provider urls. KAT Provider now uses feedcache to get its results via rss feeds. Fixed issues with Trakt.TV notifications and adding of trending shows --- .../default/home_trendingShows.tmpl | 2 +- sickbeard/notifiers/trakt.py | 6 +- sickbeard/providers/kat.py | 97 +++++++++---------- sickbeard/webserve.py | 9 +- 4 files changed, 51 insertions(+), 63 deletions(-) diff --git a/gui/slick/interfaces/default/home_trendingShows.tmpl b/gui/slick/interfaces/default/home_trendingShows.tmpl index ab0c02a9..ccdf1de4 100644 --- a/gui/slick/interfaces/default/home_trendingShows.tmpl +++ b/gui/slick/interfaces/default/home_trendingShows.tmpl @@ -149,7 +149,7 @@ $cur_show['ratings']['votes'] votes
- Add Show + Add Show
diff --git a/sickbeard/notifiers/trakt.py b/sickbeard/notifiers/trakt.py index 68ece6b9..37a1bbf0 100644 --- a/sickbeard/notifiers/trakt.py +++ b/sickbeard/notifiers/trakt.py @@ -121,12 +121,14 @@ class TraktNotifier: Returns: True if the request succeeded, False otherwise """ - trakt_api = TraktAPI(sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD) + trakt_api = TraktAPI(api, username, password) try: if trakt_api.validateAccount(): - return True + return "Test notice sent successfully to Trakt" except (traktException, traktAuthException, traktServerBusy) as e: logger.log(u"Could not connect to Trakt service: %s" % ex(e), logger.WARNING) + return "Test notice failed to Trakt: %s" % ex(e) + notifier = TraktNotifier diff --git a/sickbeard/providers/kat.py b/sickbeard/providers/kat.py index 7bb51c61..bbf0e4c7 100644 --- a/sickbeard/providers/kat.py +++ b/sickbeard/providers/kat.py @@ -61,8 +61,8 @@ class KATProvider(generic.TorrentProvider): self.cache = KATCache(self) - self.urls = ['http://kickass.to/', 'http://katproxy.com/', 'http://www.kickmirror.com/'] - self.url = 'https://kickass.to/' + self.urls = ['http://kickass.so/', 'http://katproxy.com/', 'http://www.kickmirror.com/'] + self.url = 'https://kickass.so/' def isEnabled(self): return self.enabled @@ -227,68 +227,50 @@ class KATProvider(generic.TorrentProvider): for mode in search_params.keys(): for search_string in search_params[mode]: + entries = [] for url in self.urls: - if mode != 'RSS': - searchURL = url + 'usearch/%s/?field=seeders&sorder=desc' % (urllib.quote(unidecode(search_string))) - logger.log(u"Search string: " + searchURL, logger.DEBUG) - else: - searchURL = url + 'tv/?field=time_add&sorder=desc' - logger.log(u"KAT cache update URL: " + searchURL, logger.DEBUG) + searchURL = url + 'usearch/%s/?field=seeders&sorder=desc&rss=1' % (urllib.quote(unidecode(search_string))) + logger.log(u"Search string: " + searchURL, logger.DEBUG) - html = self.getURL(searchURL) - if html: + entries = self.cache.getRSSFeed(url, items=['entries', 'feed'])['entries'] + if entries: self.url = url break - if not html: - continue - try: - with BS4Parser(html, features=["html5lib", "permissive"]) as soup: - torrent_table = soup.find('table', attrs={'class': 'data'}) - torrent_rows = torrent_table.find_all('tr') if torrent_table else [] - - #Continue only if one Release is found - if len(torrent_rows) < 2: - logger.log(u"The data returned from " + self.name + " does not contain any torrents", - logger.WARNING) + for item in entries or []: + try: + link = item['link'] + id = item['guid'] + title = item['title'] + url = item['torrent_magnetURI'] + verified = bool(item.get('torrent_verified', 0)) + seeders = int(item['torrent_seeds']) + leechers = int(item['torrent_peers']) + size = int(item['torrent_contentLength']) + except (AttributeError, TypeError): continue - for tr in torrent_rows[1:]: - try: - link = urlparse.urljoin(self.url, - (tr.find('div', {'class': 'torrentname'}).find_all('a')[1])['href']) - id = tr.get('id')[-7:] - title = (tr.find('div', {'class': 'torrentname'}).find_all('a')[1]).text \ - or (tr.find('div', {'class': 'torrentname'}).find_all('a')[2]).text - url = tr.find('a', 'imagnet')['href'] - verified = True if tr.find('a', 'iverify') else False - trusted = True if tr.find('img', {'alt': 'verified'}) else False - seeders = int(tr.find_all('td')[-2].text) - leechers = int(tr.find_all('td')[-1].text) - except (AttributeError, TypeError): - continue + if seeders < self.minseed or leechers < self.minleech: + continue - if mode != 'RSS' and (seeders < self.minseed or leechers < self.minleech): - continue + if self.confirmed and not verified: + logger.log( + u"KAT Provider found result " + title + " but that doesn't seem like a verified result so I'm ignoring it", + logger.DEBUG) + continue - if self.confirmed and not verified: - logger.log( - u"KAT Provider found result " + title + " but that doesn't seem like a verified result so I'm ignoring it", - logger.DEBUG) - continue + #Check number video files = episode in season and find the real Quality for full season torrent analyzing files in torrent + if mode == 'Season' and search_mode == 'sponly': + ep_number = int(epcount / len(set(allPossibleShowNames(self.show)))) + title = self._find_season_quality(title, link, ep_number) - #Check number video files = episode in season and find the real Quality for full season torrent analyzing files in torrent - if mode == 'Season' and search_mode == 'sponly': - ep_number = int(epcount / len(set(allPossibleShowNames(self.show)))) - title = self._find_season_quality(title, link, ep_number) + if not title or not url: + continue - if not title or not url: - continue + item = title, url, id, seeders, leechers - item = title, url, id, seeders, leechers - - items[mode].append(item) + items[mode].append(item) except Exception, e: logger.log(u"Failed to parsing " + self.name + " Traceback: " + traceback.format_exc(), @@ -356,7 +338,16 @@ class KATCache(tvcache.TVCache): self.minTime = 20 def _getRSSData(self): - search_params = {'RSS': ['rss']} - return {'entries': self.provider._doSearch(search_params)} + data = {'entries': None} + + for url in self.provider.urls: + searchURL = url + 'tv/?field=time_add&sorder=desc&rss=1' + logger.log(u"KAT cache update URL: " + searchURL, logger.DEBUG) + + data = self.getRSSFeed(url, items=['entries', 'feed'])['entries'] + if data: + break + + return data provider = KATProvider() diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 02a6b59f..508dcbf0 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -901,12 +901,7 @@ class Home(WebRoot): def testTrakt(self, api=None, username=None, password=None): self.set_header('Cache-Control', 'max-age=0,no-cache,no-store') - - result = notifiers.trakt_notifier.test_notify(api, username, password) - if result: - return "Test notice sent successfully to Trakt" - else: - return "Test notice failed to Trakt" + return notifiers.trakt_notifier.test_notify(api, username, password) def loadShowNotifyLists(self, *args, **kwargs): @@ -3148,7 +3143,7 @@ class Manage(WebRoot): if re.search('localhost', sickbeard.TORRENT_HOST): - if sickbeard.LOCALHOST_IP == '': + if not sickbeard.LOCALHOST_IP: t.webui_url = re.sub('localhost', helpers.get_lan_ip(), sickbeard.TORRENT_HOST) else: t.webui_url = re.sub('localhost', sickbeard.LOCALHOST_IP, sickbeard.TORRENT_HOST)