From b58caf8854128ad2b8f1330161de9da0ce9cc254 Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Sun, 20 Dec 2015 11:51:06 +0300 Subject: [PATCH] torr client fix --- .idea/workspace.xml | 352 +++++++++++++++++++++++--------------------- Anteoloader.py | 26 ++-- SearcherABC.py | 11 +- functions.py | 2 +- 4 files changed, 207 insertions(+), 184 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 8b822c1..8c141bd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,6 +4,8 @@ + + @@ -37,7 +39,7 @@ - + @@ -183,37 +185,40 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -300,11 +305,11 @@ - + - - + + @@ -334,33 +339,34 @@ - + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -369,7 +375,7 @@ - + @@ -402,6 +408,7 @@ + @@ -456,9 +463,6 @@ - @@ -542,6 +549,7 @@ + @@ -638,7 +646,6 @@ - @@ -820,12 +827,6 @@ - - + + - + - - + + @@ -1184,32 +1191,11 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -1329,13 +1315,6 @@ - - - - - - - @@ -1470,14 +1449,6 @@ - - - - - - - - @@ -1549,10 +1520,17 @@ + + + + + + + - + @@ -1585,6 +1563,7 @@ + @@ -1599,7 +1578,7 @@ - + @@ -1741,10 +1720,71 @@ - + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1773,58 +1813,42 @@ - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Anteoloader.py b/Anteoloader.py index 4a6dd8f..49b887a 100644 --- a/Anteoloader.py +++ b/Anteoloader.py @@ -102,10 +102,10 @@ class AnteoLoader: sys.exit(1) #pre settings - if os.path.exists(torrentFile): - self.torrentFile = file_url(torrentFile) - elif re.match("^magnet\:.+$", torrentFile): + if re.match("^magnet\:.+$", torrentFile): self.magnetLink = torrentFile + else: + self.torrentFile = torrentFile def __exit__(self): log('on __exit__') @@ -134,10 +134,12 @@ class AnteoLoader: keep_incomplete = True dht_routers = ["router.bittorrent.com:6881","router.utorrent.com:6881"] - self.engine = Engine(uri=self.torrentFile, download_path=self.storageDirectory, + user_agent = 'uTorrent/2200(24683)' + self.engine = Engine(uri=file_url(self.torrentFile), download_path=self.storageDirectory, connections_limit=connections_limit, encryption=encryption, keep_complete=keep_complete, keep_incomplete=keep_incomplete, - dht_routers=dht_routers, use_random_port=use_random_port, listen_port=listen_port) + dht_routers=dht_routers, use_random_port=use_random_port, listen_port=listen_port, + user_agent=user_agent) def localize(self, string): try: @@ -202,8 +204,8 @@ class AnteoLoader: if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath) torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent') xbmcvfs.copy(torrentUrl, torrentFile) - if xbmcvfs.exists(torrentFile): - self.torrentFile = file_url(torrentFile) + if os.path.exists(torrentFile): + self.torrentFile = torrentFile return self.torrentFile def md5(self, string): @@ -218,7 +220,7 @@ class AnteoLoader: from Libtorrent import Libtorrent torrent = Libtorrent(self.storageDirectory, self.magnetLink) torrent.magnetToTorrent(self.magnetLink) - self.torrentFile = file_url(torrent.torrentFile) + self.torrentFile = torrent.torrentFile class AnteoPlayer(xbmc.Player): __plugin__ = sys.modules["__main__"].__plugin__ @@ -294,8 +296,7 @@ class AnteoPlayer(xbmc.Player): self.on_playback_resumed = [] self.on_playback_paused = [] self.on_playback_stopped = [] - if os.path.exists(self.torrentUrl): - self.torrentUrl = file_url(self.torrentUrl) + self.torrentUrl = self.torrentUrl def setup_engine(self): #uri=None, binaries_path=None, platform=None, download_path=".", @@ -335,13 +336,14 @@ class AnteoPlayer(xbmc.Player): keep_files = True dht_routers = ["router.bittorrent.com:6881","router.utorrent.com:6881"] + user_agent = 'uTorrent/2200(24683)' self.pre_buffer_bytes = int(self.__settings__.getSetting("pre_buffer_bytes"))*1024*1024 - self.engine = Engine(uri=self.torrentUrl, download_path=self.userStorageDirectory, + self.engine = Engine(uri=file_url(self.torrentUrl), download_path=self.userStorageDirectory, connections_limit=connections_limit, download_kbps=download_limit, upload_kbps=upload_limit, encryption=encryption, keep_complete=keep_complete, keep_incomplete=keep_incomplete, dht_routers=dht_routers, use_random_port=use_random_port, listen_port=listen_port, - keep_files=keep_files) + keep_files=keep_files, user_agent=user_agent) def buffer(self): self.pre_buffer_bytes = 30*1024*1024 #30 MB diff --git a/SearcherABC.py b/SearcherABC.py index f38b8a5..d6dc548 100644 --- a/SearcherABC.py +++ b/SearcherABC.py @@ -97,7 +97,7 @@ class SearcherABC: try: if os.path.exists(cookie): self.cookieJar.load(ignore_discard=True) except: - self.log('[load_cookie]: os.remove(cookie)') + self.log(self.__plugin__+' [load_cookie]: os.remove(cookie)') os.remove(cookie) self.cookieJar = cookielib.MozillaCookieJar(cookie) @@ -105,11 +105,8 @@ class SearcherABC: cookie=os.path.join(self.tempdir(),self.__class__.__name__+'.txt') self.cookieJar = cookielib.MozillaCookieJar(cookie) if os.path.exists(cookie): - try: - self.cookieJar.clear('.'+domain) - self.log('[SearcherABC] '+self.__plugin__+': Cookie Deleted!') - except: - self.log('[SearcherABC] '+self.__plugin__+': Cookie clear failed!') + os.remove(cookie) + self.log(self.__plugin__+' [clear_cookie]: cookie cleared') def makeRequest(self, url, data={}, headers={}): self.load_cookie() @@ -233,7 +230,7 @@ class SearcherABC: temp_dir = tempfile.gettempdir() except: temp_dir = self.tempdir() - localFileName = temp_dir + os.path.sep + self.md5(url) + localFileName = temp_dir + os.path.sep + self.md5(url) + ".torrent" localFile = open(localFileName, 'wb+') localFile.write(content) diff --git a/functions.py b/functions.py index adc12da..a3791f0 100644 --- a/functions.py +++ b/functions.py @@ -1851,7 +1851,7 @@ def ensure_str(string, encoding='utf-8'): def file_url(torrentFile): import urlparse - if not re.match("^file\:.+$", torrentFile): + if not re.match("^file\:.+$", torrentFile) and os.path.exists(torrentFile): torrentFile = urlparse.urljoin('file:', urllib.pathname2url(ensure_str(torrentFile))) return torrentFile