From 1ebb09226dfa18e3d74d9ff879d93467479a749a Mon Sep 17 00:00:00 2001 From: dkboy Date: Sun, 7 Jul 2013 14:23:15 +1200 Subject: [PATCH] Add Bitsoup provider --- .../core/providers/torrent/bitsoup/__init__.py | 42 +++++++++++ couchpotato/core/providers/torrent/bitsoup/main.py | 85 ++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 couchpotato/core/providers/torrent/bitsoup/__init__.py create mode 100644 couchpotato/core/providers/torrent/bitsoup/main.py diff --git a/couchpotato/core/providers/torrent/bitsoup/__init__.py b/couchpotato/core/providers/torrent/bitsoup/__init__.py new file mode 100644 index 0000000..097f378 --- /dev/null +++ b/couchpotato/core/providers/torrent/bitsoup/__init__.py @@ -0,0 +1,42 @@ +from .main import Bitsoup + +def start(): + return Bitsoup() + +config = [{ + 'name': 'bitsoup', + 'groups': [ + { + 'tab': 'searcher', + 'subtab': 'providers', + 'list': 'torrent_providers', + 'name': 'Bitsoup', + 'description': 'See Bitsoup', + 'wizard': True, + 'options': [ + { + 'name': 'enabled', + 'type': 'enabler', + 'default': False, + }, + { + 'name': 'username', + 'default': '', + }, + { + 'name': 'password', + 'default': '', + 'type': 'password', + }, + { + '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/bitsoup/main.py b/couchpotato/core/providers/torrent/bitsoup/main.py new file mode 100644 index 0000000..904b546 --- /dev/null +++ b/couchpotato/core/providers/torrent/bitsoup/main.py @@ -0,0 +1,85 @@ +from bs4 import BeautifulSoup +from couchpotato.core.helpers.encoding import simplifyString, 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 Bitsoup(TorrentProvider): + + urls = { + 'test': 'https://www.bitsoup.me/', + 'login' : 'https://www.bitsoup.me/takelogin.php', + 'login_check': 'https://www.bitsoup.me/my.php', + 'detail': 'https://www.bitsoup.me/details.php?id=%s', + 'search': 'https://www.bitsoup.me/browse.php?', + 'download': 'https://www.bitsoup.me/%s', + } + + http_time_between_calls = 1 #seconds + + def _searchOnTitle(self, title, movie, quality, results): + + q = '"%s %s"' % (simplifyString(title), movie['library']['year']) + arguments = tryUrlencode({ + 'search': q, + }) + url = "%s&%s" % (self.urls['search'], arguments) + + data = self.getHTMLData(url, opener = self.login_opener) + + if data: + html = BeautifulSoup(data) + + try: + resultsTable = html.find_all('table')[8] + entries = resultsTable.find_all('tr') + for result in entries[1:]: + + all_cells = result.find_all('td') + + torrent = all_cells[1].find('a') + download = all_cells[3].find('a') + + torrent_id = torrent['href'] + torrent_id = torrent_id.replace('details.php?id=', '') + torrent_id = torrent_id.replace('&hit=1', '') + + torrent_name = torrent.getText() + + torrent_size = self.parseSize(all_cells[7].getText()) + torrent_seeders = tryInt(all_cells[9].getText()) + torrent_leechers = tryInt(all_cells[10].getText()) + torrent_url = self.urls['download'] % download['href'] + torrent_description = torrent['href'] + + results.append({ + 'id': torrent_id, + 'name': torrent_name, + 'size': torrent_size, + 'seeders': torrent_seeders, + 'leechers': torrent_leechers, + 'url': torrent_url, + 'description': torrent_description, + }) + + 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'), + 'ssl': 'yes', + }) + + + def loginSuccess(self, output): + return 'logout.php' in output.lower() + + loginCheckSuccess = loginSuccess +