From e4adaef1aed5a620995c572a02ba0434e770a4cf Mon Sep 17 00:00:00 2001 From: DiMartinoXBMC Date: Mon, 8 Jun 2015 21:17:37 +0300 Subject: [PATCH] little piece mp4 fix --- Libtorrent.py | 42 +++++++++++++++++++++++++++------- Player.py | 11 ++++++++- addon.xml | 2 +- resources/searchers/RiperAM.py | 2 +- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/Libtorrent.py b/Libtorrent.py index 9fb2fd9..841881f 100644 --- a/Libtorrent.py +++ b/Libtorrent.py @@ -51,6 +51,30 @@ class Libtorrent: def __init__(self, storageDirectory='', torrentFile='', torrentFilesDirectory='torrents'): + '''dirname = os.path.join(xbmc.translatePath('special://home'), 'addons', 'plugin.video.torrenter', + 'resources') + sys.path.insert(0, dirname) + + try: + import resources.libtorrent as libtorrent + + print 'Imported libtorrent v' + libtorrent.version + ' from python_libtorrent.' + except Exception, e: + print 'Error importing python_libtorrent. Exception: ' + str(e) + + try: + from ctypes import * + cdll.LoadLibrary(os.path.join(dirname,'libtorrent.so')) + except Exception, e: + print 'Error importing by ctypes. Exception: ' + str(e) + + try: + print 'Imported libtorrent v' + libtorrent.version + ' from python_libtorrent.' + except Exception, e: + print 'Error importing python_libtorrent. Exception: ' + str(e) + + print 'Imported libtorrent v' + libtorrent.version + ' from ctypes.''''' + try: import libtorrent @@ -334,7 +358,7 @@ class Libtorrent: for i in range(self.torrentFileInfo.num_pieces()): self.torrentHandle.piece_priority(i, 0) - def continueSession(self, contentId=0, Offset=0, seeding=False): + def continueSession(self, contentId=0, Offset=0, seeding=False, isMP4=False): self.piece_length = self.torrentFileInfo.piece_length() selectedFileInfo = self.getContentList()[contentId] if not Offset: @@ -344,16 +368,18 @@ class Libtorrent: self.startPart = selectedFileInfo['offset'] / self.piece_length self.endPart = int((selectedFileInfo['offset'] + selectedFileInfo['size']) / self.piece_length) #print 'part ' + str(self.startPart)+ str(' ')+ str(self.endPart) + pieceMB=float(self.piece_length) / (1024 * 1024) + multiplier=int(10/pieceMB) + #print 'continueSession: pieceMB '+str(pieceMB)+' multiplier '+str(multiplier) for i in range(self.startPart, self.startPart + self.partOffset): if i <= self.endPart: self.torrentHandle.piece_priority(i, 7) - #print str(i) - self.torrentHandle.piece_priority(self.endPart - 1, 7) - self.torrentHandle.piece_priority(self.endPart, 7) - #thread.start_new_thread(self.checkProcess, ()) - #thread.start_new_thread(self.downloadProcess, (contentId,)) - #if seeding:# and None == self.magnetLink: - # thread.start_new_thread(self.addToSeeding, (contentId,)) + if isMP4 and i%multiplier==0: + self.torrentHandle.piece_priority(self.endPart - i/multiplier, 7) + #print str(i) + if multiplier>=i: + self.torrentHandle.piece_priority(self.endPart - i, 7) + #print str(i) def fetchParts(self): priorities = self.torrentHandle.piece_priorities() diff --git a/Player.py b/Player.py index 45294a7..73058a7 100644 --- a/Player.py +++ b/Player.py @@ -189,7 +189,16 @@ class TorrentPlayer(xbmc.Player): self.fullSize = self.torrent.getFileSize(self.contentId) Offset = calculate(self.fullSize) #print 'Offset: '+str(Offset) - self.torrent.continueSession(self.contentId, Offset=Offset) + + #mp4 fix + label = os.path.basename(self.torrent.getFilePath(self.contentId)) + isMP4=False + if '.' in label: + ext=label.split('.')[-1] + if ext.lower()=='mp4': + isMP4=True + #print 'setup_torrent: '+str((self.contentId, Offset, isMP4, label, ext)) + self.torrent.continueSession(self.contentId, Offset=Offset, isMP4=isMP4) def buffer(self): iterator = 0 diff --git a/addon.xml b/addon.xml index 16f3c33..8a1c439 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@  - + diff --git a/resources/searchers/RiperAM.py b/resources/searchers/RiperAM.py index c980b75..18e0e97 100644 --- a/resources/searchers/RiperAM.py +++ b/resources/searchers/RiperAM.py @@ -75,7 +75,7 @@ class RiperAM(SearcherABC.SearcherABC): if None != response and 0 < len(response): self.cookieJar.save(ignore_discard=True) self.check_login(response) - print response + #print response dat = re.compile( r'(.+?).+?Размер: (.+?).+?" title="Сидеров">(\d+?).+?title="Личеров">(\d+?)', re.DOTALL | re.I).findall(response)