diff --git a/couchpotato/core/providers/nzb/ftdworld/main.py b/couchpotato/core/providers/nzb/ftdworld/main.py index 81ac8edd..9a3a9f33 100644 --- a/couchpotato/core/providers/nzb/ftdworld/main.py +++ b/couchpotato/core/providers/nzb/ftdworld/main.py @@ -1,12 +1,10 @@ -from bs4 import BeautifulSoup from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode from couchpotato.core.helpers.variable import tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.nzb.base import NZBProvider from couchpotato.environment import Env from dateutil.parser import parse -import re -import time +import traceback log = CPLog(__name__) @@ -14,7 +12,7 @@ log = CPLog(__name__) class FTDWorld(NZBProvider): urls = { - 'search': 'http://ftdworld.net/category.php?%s', + 'search': 'http://ftdworld.net/api/index.php?%s', 'detail': 'http://ftdworld.net/spotinfo.php?id=%s', 'download': 'http://ftdworld.net/cgi-bin/nzbdown.pl?fileID=%s', 'login': 'http://ftdworld.net/index.php', @@ -25,7 +23,7 @@ class FTDWorld(NZBProvider): cat_ids = [ ([4, 11], ['dvdr']), ([1], ['cam', 'ts', 'dvdrip', 'tc', 'r5', 'scr', 'brrip']), - ([10, 13, 14], ['bd50', '720p', '1080p']), + ([7, 10, 13, 14], ['bd50', '720p', '1080p']), ] cat_backup_id = 1 @@ -43,38 +41,29 @@ class FTDWorld(NZBProvider): 'ctype': ','.join([str(x) for x in self.getCatId(quality['identifier'])]), }) - data = self.getHTMLData(self.urls['search'] % params, opener = self.login_opener) + data = self.getJsonData(self.urls['search'] % params, opener = self.login_opener) if data: try: - html = BeautifulSoup(data) - main_table = html.find('table', attrs = {'id':'ftdresult'}) - - if not main_table: + if data.get('numRes') == 0: return - items = main_table.find_all('tr', attrs = {'class': re.compile('tcontent')}) - - for item in items: - tds = item.find_all('td') - nzb_id = tryInt(item.attrs['data-spot']) - - up = item.find('img', attrs = {'src': re.compile('up.png')}) - down = item.find('img', attrs = {'src': re.compile('down.png')}) + for item in data.get('data'): + nzb_id = tryInt(item.get('id')) results.append({ 'id': nzb_id, - 'name': toUnicode(item.find('a', attrs = {'href': re.compile('./spotinfo')}).text.strip()), - 'age': self.calculateAge(int(time.mktime(parse(tds[2].text).timetuple()))), + 'name': toUnicode(item.get('Title')), + 'age': self.calculateAge(tryInt(item.get('Created'))), 'url': self.urls['download'] % nzb_id, 'download': self.loginDownload, 'detail_url': self.urls['detail'] % nzb_id, - 'score': (tryInt(up.attrs['title'].split(' ')[0]) * 3) - (tryInt(down.attrs['title'].split(' ')[0]) * 3) if up else 0, + 'score': (tryInt(item.get('webPlus', 0)) - tryInt(item.get('webMin', 0))) * 3, }) except: - log.error('Failed to parse HTML response from FTDWorld') + log.error('Failed to parse HTML response from FTDWorld: %s', traceback.format_exc()) def getLoginParams(self): return tryUrlencode({