From 6acc125d4fa1ceba97842218664622bee21401eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Sat, 16 Nov 2013 02:57:06 +0100 Subject: [PATCH 1/3] bithdtv provider thanks to @lansinghd , https://github.com/RuudBurger/CouchPotatoServer/pull/2460 --- .../providers/torrent/bithdtv/__init__.py | 56 +++++++++++++ .../core/providers/torrent/bithdtv/main.py | 81 +++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 couchpotato/core/providers/torrent/bithdtv/__init__.py create mode 100644 couchpotato/core/providers/torrent/bithdtv/main.py diff --git a/couchpotato/core/providers/torrent/bithdtv/__init__.py b/couchpotato/core/providers/torrent/bithdtv/__init__.py new file mode 100644 index 00000000..bc94e6bf --- /dev/null +++ b/couchpotato/core/providers/torrent/bithdtv/__init__.py @@ -0,0 +1,56 @@ +from .main import BiTHDTV + +def start(): + return BiTHDTV() + +config = [{ + 'name': 'BiT-HDTV', + 'groups': [ + { + 'tab': 'searcher', + 'subtab': 'providers', + 'list': 'torrent_providers', + 'name': 'BiT-HDTV', + 'description': 'See BiT-HDTV', + 'wizard': True, + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': False, + }, + { + 'name': 'username', + 'default': '', + }, + { + 'name': 'password', + 'default': '', + 'type': 'password', + }, + { + 'name': 'seed_ratio', + 'label': 'Seed ratio', + 'type': 'float', + 'default': 1, + 'description': 'Will not be (re)moved until this seed ratio is met.', + }, + { + 'name': 'seed_time', + 'label': 'Seed time', + 'type': 'int', + 'default': 40, + 'description': 'Will not be (re)moved until this seed time (in hours) is met.', + }, + { + 'name': 'extra_score', + 'advanced': True, + 'label': 'Extra Score', + 'type': 'int', + 'default': 20, + 'description': 'Starting score for each release found via this provider.', + } + ], + }, + ], +}] diff --git a/couchpotato/core/providers/torrent/bithdtv/main.py b/couchpotato/core/providers/torrent/bithdtv/main.py new file mode 100644 index 00000000..d07e11f0 --- /dev/null +++ b/couchpotato/core/providers/torrent/bithdtv/main.py @@ -0,0 +1,81 @@ +from datetime import datetime +from bs4 import BeautifulSoup +from couchpotato.core.helpers.encoding import tryUrlencode +from couchpotato.core.helpers.variable import tryInt +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.torrent.base import TorrentProvider +import traceback + +log = CPLog(__name__) + + +class BiTHDTV(TorrentProvider): + + urls = { + 'test' : 'http://www.bit-hdtv.com/', + 'login' : 'http://www.bit-hdtv.com/takelogin.php', + 'detail' : 'http://www.bit-hdtv.com/details.php?id=%s', + 'search' : 'http://www.bit-hdtv.com/torrents.php?search=%s&cat=%s&sub=%s', + } + + # Searches for movies only - BiT-HDTV's subcategory and resolution search filters appear to be broken + cat_id_movies = 7 + cat_ids = [ + ([16], ['720p', '1080p', 'brrip']), + ([17], ['cam', 'r5', 'scr', 'dvdrip', 'dvdr']), + ([19], ['ts', 'tc']), + ] + + http_time_between_calls = 1 #seconds + cat_backup_id = None + + def _searchOnTitle(self, title, movie, quality, results): + + url = self.urls['search'] % (tryUrlencode('%s %s' % (title.replace(':', ''), movie['library']['year'])), self.cat_id_movies, self.getCatId(quality['identifier'])[0]) + data = self.getHTMLData(url, opener = self.login_opener) + + if data: + + # Remove BiT-HDTV's output garbage so outdated BS4 versions successfully parse the HTML + split_data = data.partition('-->') + if '## SELECT COUNT(' in split_data[0]: + data = split_data[2] + + html = BeautifulSoup(data) + + try: + result_table = html.find('table', attrs = {'width' : '750', 'class' : ''}) + if not result_table: + return + + entries = result_table.find_all('tr') + + for result in entries[1:]: + cells = result.find_all('td') + link = cells[2].find('a') + torrent_id = link['href'].replace('/details.php?id=', '') + torrent_age = datetime.now() - datetime.strptime(cells[5].get_text(), '%Y-%m-%d %H:%M:%S') + + results.append({ + 'id': torrent_id, + 'name': link.contents[0].get_text(), + 'url': cells[0].find('a')['href'], + 'detail_url': self.urls['detail'] % torrent_id, + 'size': self.parseSize(cells[6].get_text()), + 'age': torrent_age.days, + 'seeders': tryInt(cells[8].string), + 'leechers': tryInt(cells[9].string), + }) + + except: + log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc())) + + def getLoginParams(self): + return tryUrlencode({ + 'username': self.conf('username'), + 'password': self.conf('password'), + 'login': 'submit', + }) + + def loginSuccess(self, output): + return 'logout.php' in output.lower() From a2c5074d6616edea12718be5d6ec93ace04a177f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Sat, 16 Nov 2013 02:58:29 +0100 Subject: [PATCH 2/3] fixed bithdtv provider --- .../providers/torrent/bithdtv/__init__.py | 3 +- .../core/providers/torrent/bithdtv/main.py | 47 +++++++++++-------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/couchpotato/core/providers/torrent/bithdtv/__init__.py b/couchpotato/core/providers/torrent/bithdtv/__init__.py index bc94e6bf..7803419d 100644 --- a/couchpotato/core/providers/torrent/bithdtv/__init__.py +++ b/couchpotato/core/providers/torrent/bithdtv/__init__.py @@ -8,7 +8,6 @@ config = [{ 'groups': [ { 'tab': 'searcher', - 'subtab': 'providers', 'list': 'torrent_providers', 'name': 'BiT-HDTV', 'description': 'See BiT-HDTV', @@ -53,4 +52,4 @@ config = [{ ], }, ], -}] +}] \ No newline at end of file diff --git a/couchpotato/core/providers/torrent/bithdtv/main.py b/couchpotato/core/providers/torrent/bithdtv/main.py index d07e11f0..6faa20c7 100644 --- a/couchpotato/core/providers/torrent/bithdtv/main.py +++ b/couchpotato/core/providers/torrent/bithdtv/main.py @@ -1,4 +1,3 @@ -from datetime import datetime from bs4 import BeautifulSoup from couchpotato.core.helpers.encoding import tryUrlencode from couchpotato.core.helpers.variable import tryInt @@ -8,34 +7,33 @@ import traceback log = CPLog(__name__) - class BiTHDTV(TorrentProvider): urls = { 'test' : 'http://www.bit-hdtv.com/', 'login' : 'http://www.bit-hdtv.com/takelogin.php', + 'login_check': 'http://www.bit-hdtv.com/messages.php', 'detail' : 'http://www.bit-hdtv.com/details.php?id=%s', - 'search' : 'http://www.bit-hdtv.com/torrents.php?search=%s&cat=%s&sub=%s', + 'search' : 'http://www.bit-hdtv.com/torrents.php?', } # Searches for movies only - BiT-HDTV's subcategory and resolution search filters appear to be broken cat_id_movies = 7 - cat_ids = [ - ([16], ['720p', '1080p', 'brrip']), - ([17], ['cam', 'r5', 'scr', 'dvdrip', 'dvdr']), - ([19], ['ts', 'tc']), - ] http_time_between_calls = 1 #seconds - cat_backup_id = None def _searchOnTitle(self, title, movie, quality, results): - url = self.urls['search'] % (tryUrlencode('%s %s' % (title.replace(':', ''), movie['library']['year'])), self.cat_id_movies, self.getCatId(quality['identifier'])[0]) + arguments = tryUrlencode({ + 'search': '%s %s' % (title.replace(':', ''), movie['library']['year']), + 'cat': self.cat_id_movies + }) + + url = "%s&%s" % (self.urls['search'], arguments) + data = self.getHTMLData(url, opener = self.login_opener) if data: - # Remove BiT-HDTV's output garbage so outdated BS4 versions successfully parse the HTML split_data = data.partition('-->') if '## SELECT COUNT(' in split_data[0]: @@ -44,17 +42,16 @@ class BiTHDTV(TorrentProvider): html = BeautifulSoup(data) try: - result_table = html.find('table', attrs = {'width' : '750', 'class' : ''}) - if not result_table: + result_table = html.find('table', attrs = {'width' : '750', 'class' : ''}) + if result_table is None: return - entries = result_table.find_all('tr') - + entries = result_table.find_all('tr') for result in entries[1:]: + cells = result.find_all('td') link = cells[2].find('a') torrent_id = link['href'].replace('/details.php?id=', '') - torrent_age = datetime.now() - datetime.strptime(cells[5].get_text(), '%Y-%m-%d %H:%M:%S') results.append({ 'id': torrent_id, @@ -62,20 +59,30 @@ class BiTHDTV(TorrentProvider): 'url': cells[0].find('a')['href'], 'detail_url': self.urls['detail'] % torrent_id, 'size': self.parseSize(cells[6].get_text()), - 'age': torrent_age.days, 'seeders': tryInt(cells[8].string), 'leechers': tryInt(cells[9].string), + 'get_more_info': self.getMoreInfo, }) - except: - log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc())) + except: + log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc())) def getLoginParams(self): return tryUrlencode({ 'username': self.conf('username'), 'password': self.conf('password'), - 'login': 'submit', }) + def getMoreInfo(self, item): + full_description = self.getCache('bithdtv.%s' % item['id'], item['detail_url'], cache_timeout = 25920000) + html = BeautifulSoup(full_description) + nfo_pre = html.find('table', attrs = {'class':'detail'}) + description = toUnicode(nfo_pre.text) if nfo_pre else '' + + item['description'] = description + return item + def loginSuccess(self, output): return 'logout.php' in output.lower() + + loginCheckSuccess = loginSuccess From 8996dd34c25dd7f424db938f86bae957732e5eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20K=C3=A5berg?= Date: Sat, 16 Nov 2013 12:01:29 +0100 Subject: [PATCH 3/3] fix ident in bithdtv --- couchpotato/core/providers/torrent/bithdtv/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/providers/torrent/bithdtv/main.py b/couchpotato/core/providers/torrent/bithdtv/main.py index 6faa20c7..117eee99 100644 --- a/couchpotato/core/providers/torrent/bithdtv/main.py +++ b/couchpotato/core/providers/torrent/bithdtv/main.py @@ -64,8 +64,8 @@ class BiTHDTV(TorrentProvider): 'get_more_info': self.getMoreInfo, }) - except: - log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc())) + except: + log.error('Failed getting results from %s: %s', (self.getName(), traceback.format_exc())) def getLoginParams(self): return tryUrlencode({