initial couchtarter provider (torrent newznab)

initial ground work based on newznab provider
needs UI changes: http://i.imgur.com/4MiJUH5.png (need to add ratio and
seed hours also)

untested code
This commit is contained in:
Joel Kåberg
2013-11-21 19:55:36 +01:00
parent cec88319fe
commit e1a311de40
2 changed files with 174 additions and 0 deletions
@@ -0,0 +1,53 @@
from .main import Couchtarter
def start():
return Couchtarter()
config = [{
'name': 'couchtart',
'groups': [
{
'tab': 'searcher',
'list': 'torrent_providers',
'name': 'couchtart',
'order': 10,
'description': 'Cocuhtart providers.',
'wizard': True,
'options': [
{
'name': 'enabled',
'type': 'enabler',
'default': True,
},
{
'name': 'use',
'default': '0,0,0,0,0,0'
},
{
'name': 'host',
'default': '',
'description': 'The url path of your Couchtart provider.',
},
{
'name': 'extra_score',
'advanced': True,
'label': 'Extra Score',
'default': '0',
'description': 'Starting score for each release found via this provider.',
},
{
'name': 'username',
'default': '',
},
{
'name': 'pass_key',
'default': ',',
'label': 'Pass Key',
'description': 'Can be found on your profile page',
'type': 'combined',
'combine': ['use', 'host', 'username', 'pass_key', 'extra_score'],
},
],
},
],
}]
@@ -0,0 +1,121 @@
from couchpotato.core.helpers.encoding import tryUrlencode, toUnicode
from couchpotato.core.helpers.variable import splitString, tryInt
from couchpotato.core.logger import CPLog
from couchpotato.core.providers.base import ResultList
from couchpotato.core.providers.torrent.base import TorrentProvider
from couchpotato.environment import Env
import traceback
log = CPLog(__name__)
class Couchtarter(TorrentProvider):
limits_reached = {}
http_time_between_calls = 1 # Seconds
def search(self, movie, quality):
hosts = self.getHosts()
results = ResultList(self, movie, quality, imdb_results = True)
for host in hosts:
if self.isDisabled(host):
continue
self._searchOnHost(host, movie, quality, results)
return results
def _searchOnHost(self, host, movie, quality, results):
arguments = tryUrlencode({
'user': host['username'],
'passkey': host['pass_key'],
'imdbid': movie['library']['identifier'].replace('tt', '')
})
url = '%s&%s' % (host['host'], arguments)
torrents = self.getJsonData(url, cache_timeout = 1800)
if torrents:
try:
if torrents.get('Error'):
if 'Incorrect parameters.' in torrents['Error']:
log.error('Wrong parameters passed to: %s', host['host'])
elif 'Death by authorization.' in torrents['Error']:
log.error('Wrong username or pass key for: %s', host['host'])
else:
log.error('Unknown error for: %s', host['host'])
return #(can I disable this host somehow? and notify user?)
elif torrents.get('Results'):
if 'None found' in torrents['Results']:
return
else:
for torrent in torrents['Results']:
print torrent['ReleaseName']
print torrent['Size']
print torrent['DownloadURL']
#results.append({
# 'id': tryInt(result['TorrentID']),
# 'name': toUnicode(result['ReleaseName']),
# 'size': tryInt(self.parseSize(result['Size'])),
# 'url': result['DownloadURL'],
# 'detail_url': result['DetailURL'],
# 'resoultion': result['Resolution'],
# 'score': host['extra_score'],
# 'get_more_info': result['IMDbID']
#})
except:
log.error('Failed getting results from %s: %s', (host['host'], traceback.format_exc()))
def getHosts(self):
uses = splitString(str(self.conf('use')), clean = False)
hosts = splitString(self.conf('host'), clean = False)
usernames = splitString(self.conf('username'), clean = False)
pass_keys = splitString(self.conf('pass_key'), clean = False)
extra_score = splitString(self.conf('extra_score'), clean = False)
list = []
for nr in range(len(hosts)):
try: key = pass_keys[nr]
except: key = ''
try: host = hosts[nr]
except: host = ''
list.append({
'use': uses[nr],
'host': host,
'pass_key': key,
'extra_score': tryInt(extra_score[nr]) if len(extra_score) > nr else 0
})
return list
def belongsTo(self, url, provider = None, host = None):
hosts = self.getHosts()
for host in hosts:
result = super(Couchtater, self).belongsTo(url, host = host['host'], provider = provider)
if result:
return result
def isDisabled(self, host = None):
return not self.isEnabled(host)
def isEnabled(self, host = None):
# Return true if at least one is enabled and no host is given
if host is None:
for host in self.getHosts():
if self.isEnabled(host):
return True
return False
return TorrentProvider.isEnabled(self) and host['host'] and host['pass_key'] and int(host['use'])