uTorrent cleanup

Add trackers when adding via magnet_link
This commit is contained in:
Ruud
2012-11-11 20:45:50 +01:00
parent 904d1ea4f7
commit 813c078db0
2 changed files with 30 additions and 17 deletions
+14
View File
@@ -18,6 +18,20 @@ class Downloader(Plugin):
'http://torcache.net/torrent/%s.torrent', 'http://torcache.net/torrent/%s.torrent',
] ]
torrent_trackers = [
'http://tracker.publicbt.com/announce',
'udp://tracker.istole.it:80/announce',
'udp://fr33domtracker.h33t.com:3310/announce',
'http://tracker.istole.it/announce',
'http://tracker.ccc.de/announce',
'udp://tracker.publicbt.com:80/announce',
'udp://tracker.ccc.de:80/announce',
'http://exodus.desync.com/announce',
'http://exodus.desync.com:6969/announce',
'http://tracker.publichd.eu/announce',
'http://tracker.openbittorrent.com/announce',
]
def __init__(self): def __init__(self):
addEvent('download', self.download) addEvent('download', self.download)
addEvent('download.status', self.getAllDownloadStatus) addEvent('download.status', self.getAllDownloadStatus)
+14 -15
View File
@@ -1,18 +1,15 @@
from base64 import b64encode from bencode import bencode, bdecode
from hashlib import sha1
from couchpotato.core.downloaders.base import Downloader from couchpotato.core.downloaders.base import Downloader
from couchpotato.core.helpers.encoding import isInt from couchpotato.core.helpers.encoding import isInt
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from hashlib import sha1
from multipartpost import MultipartPostHandler from multipartpost import MultipartPostHandler
from bencode import bencode, bdecode import cookielib
import httplib import httplib
import json
import os.path
import re import re
import time
import urllib import urllib
import urllib2 import urllib2
import time
import cookielib
log = CPLog(__name__) log = CPLog(__name__)
@@ -21,7 +18,7 @@ log = CPLog(__name__)
class uTorrent(Downloader): class uTorrent(Downloader):
type = ['torrent', 'torrent_magnet'] type = ['torrent', 'torrent_magnet']
utAPI = None utorrent_api = None
def download(self, data, movie, manual = False, filedata = None): def download(self, data, movie, manual = False, filedata = None):
@@ -45,24 +42,26 @@ class uTorrent(Downloader):
return False return False
if data.get('type') == 'torrent_magnet': if data.get('type') == 'torrent_magnet':
torrent_hash = re.findall('urn:btih:([\w]{32,40})', data.get('url'))[0].upper() torrent_hash = re.findall('urn:btih:([\w]{32,40})', data.get('url'))[0].upper()
torrent_params['trackers'] = '%0D%0A%0D%0A'.join(self.torrent_trackers)
else: else:
info = bdecode(filedata)["info"] info = bdecode(filedata)["info"]
torrent_hash = sha1(bencode(info)).hexdigest().upper() torrent_hash = sha1(bencode(info)).hexdigest().upper()
torrent_filename = self.createFileName(data, filedata, movie) torrent_filename = self.createFileName(data, filedata, movie)
# Send request to uTorrent # Send request to uTorrent
try: try:
if not self.utAPI: if not self.utorrent_api:
self.utAPI = uTorrentAPI(host[0], port = host[1], username = self.conf('username'), password = self.conf('password')) self.utorrent_api = uTorrentAPI(host[0], port = host[1], username = self.conf('username'), password = self.conf('password'))
if data.get('type') == 'torrent_magnet': if data.get('type') == 'torrent_magnet':
self.utAPI.add_torrent_uri(data.get('url')) self.utorrent_api.add_torrent_uri(data.get('url'))
else: else:
self.utAPI.add_torrent_file(torrent_filename, filedata) self.utorrent_api.add_torrent_file(torrent_filename, filedata)
# Change settings of added torrents # Change settings of added torrents
self.utAPI.set_torrent(torrent_hash, torrent_params) self.utorrent_api.set_torrent(torrent_hash, torrent_params)
if self.conf('paused', default = 0): if self.conf('paused', default = 0):
self.utAPI.pause_torrent(torrent_hash) self.utorrent_api.pause_torrent(torrent_hash)
return True return True
except Exception, err: except Exception, err:
log.error('Failed to send torrent to uTorrent: %s', err) log.error('Failed to send torrent to uTorrent: %s', err)
@@ -116,7 +115,7 @@ class uTorrentAPI(object):
return False return False
def get_token(self): def get_token(self):
request = self.opener.open(self.url+"token.html") request = self.opener.open(self.url + "token.html")
token = re.findall("<div.*?>(.*?)</", request.read())[0] token = re.findall("<div.*?>(.*?)</", request.read())[0]
return token return token