diff --git a/Core.py b/Core.py
index 3e9d2ce..c8686b3 100644
--- a/Core.py
+++ b/Core.py
@@ -39,7 +39,6 @@ class Core:
__settings__ = sys.modules["__main__"].__settings__
ROOT = sys.modules["__main__"].__root__ #.decode('utf-8').encode(sys.getfilesystemencoding())
userStorageDirectory = file_encode(__settings__.getSetting("storage"))
- USERAGENT = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0"
torrentFilesDirectory = 'torrents'
debug = __settings__.getSetting('debug') == 'true'
torrent_player=__settings__.getSetting("torrent_player")
@@ -1052,7 +1051,6 @@ class Core:
self.sectionMenu()
def uTorrentBrowser(self, params={}):
-
menu, dirs = [], []
contextMenustring = 'XBMC.RunPlugin(%s)' % ('%s?action=%s&url=%s') % (sys.argv[0], 'uTorrentBrowser', '%s')
get = params.get
@@ -1231,11 +1229,13 @@ class Core:
url = unquote(get("url"),None)
tdir = unquote(get("url2"),None)
- #url="D:\\[rutracker.org].t4563731.torrent"
-
if not url:
action = xbmcgui.Dialog()
url = action.browse(1, self.localize('Choose .torrent in video library'), 'video', '.torrent')
+ xbmc.executebuiltin(
+ 'XBMC.ActivateWindow(%s)' % 'Videos,plugin://plugin.video.torrenter/?action=%s&url=%s'
+ % ('torrentPlayer', url))
+ return
if url:
self.__settings__.setSetting("lastTorrentUrl", url)
torrent = Downloader.Torrent(self.userStorageDirectory, torrentFilesDirectory=self.torrentFilesDirectory)
@@ -1243,11 +1243,8 @@ class Core:
torrentFilesDirectory=self.torrentFilesDirectory)
self.__settings__.setSetting("lastTorrent", torrent.saveTorrent(url))
contentList = []
- #filename='Suzumiya Haruhi no Yuuutsu - 05 [DVDrip 1280x720 x264 FLAC].mkv'
- #print str(torrent.getSubsIds(filename))
for filedict in torrent.getContentList():
fileTitle = filedict.get('title')
- #print fileTitle
if filedict.get('size'):
fileTitle += ' [%d MB]' % (filedict.get('size') / 1024 / 1024)
contentList.append((self.unescape(fileTitle), str(filedict.get('ind'))))
@@ -1740,6 +1737,9 @@ class Core:
url = searcherObject.getTorrentFile(classMatch.group(2))
torrent = Downloader.Torrent(self.userStorageDirectory, torrentFilesDirectory=self.torrentFilesDirectory)
torrent.initSession()
+ encryption = self.__settings__.getSetting('encryption') == 'true'
+ if encryption:
+ torrent.encryptSession()
url=torrent.saveTorrent(url)
self.__settings__.setSetting("lastTorrent", url)
if 0 < int(self.__settings__.getSetting("upload_limit")):
@@ -1747,7 +1747,7 @@ class Core:
if 0 < int(self.__settings__.getSetting("download_limit")):
torrent.setDownloadLimit(
int(self.__settings__.getSetting("download_limit")) * 1000000 / 8) #MBits/second
- torrent.downloadProcess(ind)
+ torrent.downloadProcess(ind, encryption)
showMessage(self.localize('Download Status'), self.localize('Added!'))
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]), succeeded=True)
diff --git a/Downloader.py b/Downloader.py
index 038b495..1469c07 100644
--- a/Downloader.py
+++ b/Downloader.py
@@ -103,6 +103,9 @@ class Torrent():
def initSession(self):
return self.player.initSession()
+ def encryptSession(self):
+ return self.player.encryptSession()
+
def startSession(self):
return self.player.startSession()
diff --git a/Libtorrent.py b/Libtorrent.py
index 6a40174..2507524 100644
--- a/Libtorrent.py
+++ b/Libtorrent.py
@@ -24,7 +24,6 @@ import os
import urllib2
import hashlib
import re
-# import sys
from StringIO import StringIO
import gzip
@@ -51,80 +50,9 @@ 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
-
- print 'Imported libtorrent v' + libtorrent.version + ' from system'
- except Exception, e:
- print 'Error importing from system. Exception: ' + str(e)
-
- if platform.system() != 'Windows':
- if sys.maxsize > 2 ** 32:
- system = 'linux_x86_64'
- else:
- system = 'linux_x86'
- else:
- system = 'windows'
-
- dirname = os.path.join(xbmc.translatePath('special://home'), 'addons', 'script.module.libtorrent',
- 'python_libtorrent', system)
- sys.path.insert(0, dirname)
- try:
- import libtorrent
-
- print 'Imported libtorrent v' + libtorrent.version + ' from python_libtorrent.' + system
- except Exception, e:
- print 'Error importing python_libtorrent.' + system + '. Exception: ' + str(e)
- pass
+ '''
#from ctypes import *
- #cdll.LoadLibrary(dirname + '/libtorrent-rasterbar.so.7')
-
- self.platform = get_platform()
-
- print '[Libtorrent] self.platform: ' + str(self.platform)
-
- try:
- import libtorrent
-
- print 'Imported libtorrent v' + libtorrent.version + ' from system'
- except Exception, e:
- print 'Error importing from system. Exception: ' + str(e)
-
- try:
- dirname = os.path.join(xbmc.translatePath('special://home'), 'addons', 'script.module.libtorrent',
- 'python_libtorrent', self.platform['system'])
- sys.path.insert(0, dirname)
- import libtorrent
-
- print 'Imported libtorrent v' + libtorrent.version + ' from python_libtorrent.' + self.platform[
- 'system']
- except Exception, e:
- print 'Error importing python_libtorrent.' + self.platform['system'] + '. Exception: ' + str(e)
- pass'''
+ #cdll.LoadLibrary(dirname + '/libtorrent-rasterbar.so.7')'''
self.platform = get_platform()
try:
@@ -290,17 +218,11 @@ class Libtorrent:
def getContentList(self):
filelist = []
- try:
- for contentId, contentFile in enumerate(self.torrentFileInfo.files()):
- stringdata = {"title": contentFile.path, "size": contentFile.size, "ind": int(contentId),
- 'offset': contentFile.offset}
- filelist.append(stringdata)
- return filelist
- except:
- xbmcgui.Dialog().ok(Localization.localize('Python-Libtorrent Not Found'),
- Localization.localize(self.platform["message"][0]),
- Localization.localize(self.platform["message"][1]))
- return
+ for contentId, contentFile in enumerate(self.torrentFileInfo.files()):
+ stringdata = {"title": contentFile.path, "size": contentFile.size, "ind": int(contentId),
+ 'offset': contentFile.offset}
+ filelist.append(stringdata)
+ return filelist
def getSubsIds(self, filename):
subs = []
@@ -323,7 +245,10 @@ class Libtorrent:
hasher.update(string.encode('utf-8', 'ignore'))
return hasher.hexdigest()
- def downloadProcess(self, contentId):
+ def downloadProcess(self, contentId, encrytion=True):
+ self.initSession()
+ if encrytion:
+ self.encryptSession()
self.startSession()
self.paused = False
db = DownloadDB()
@@ -386,15 +311,38 @@ class Libtorrent:
except:
pass
self.session = self.lt.session()
+ self.session.set_alert_mask(self.lt.alert.category_t.error_notification | self.lt.alert.category_t.status_notification | self.lt.alert.category_t.storage_notification)
self.session.start_dht()
self.session.add_dht_router("router.bittorrent.com", 6881)
self.session.add_dht_router("router.utorrent.com", 6881)
self.session.add_dht_router("router.bitcomet.com", 6881)
+ self.session.start_lsd()
+ self.session.start_upnp()
+ self.session.start_natpmp()
self.session.listen_on(6881, 6891)
- self.session.set_alert_mask(self.lt.alert.category_t.storage_notification)
+
+ # Session settings
+ session_settings = self.session.settings()
+ session_settings.announce_to_all_tiers = True
+ session_settings.announce_to_all_trackers = True
+ session_settings.connection_speed = 100
+ session_settings.peer_connect_timeout = 2
+ session_settings.rate_limit_ip_overhead = True
+ session_settings.request_timeout = 5
+ session_settings.torrent_connect_boost = 100
+
+ self.session.set_settings(session_settings)
+
+ def encryptSession(self):
+ # Encryption settings
+ encryption_settings = self.lt.pe_settings()
+ encryption_settings.out_enc_policy = self.lt.enc_policy(self.lt.enc_policy.forced)
+ encryption_settings.in_enc_policy = self.lt.enc_policy(self.lt.enc_policy.forced)
+ encryption_settings.allowed_enc_level = self.lt.enc_level.both
+ encryption_settings.prefer_rc4 = True
+ self.session.set_pe_settings(encryption_settings)
def startSession(self):
- self.initSession()
if None == self.magnetLink:
self.torrentHandle = self.session.add_torrent({'ti': self.torrentFileInfo,
'save_path': self.storageDirectory,
@@ -447,6 +395,10 @@ class Libtorrent:
if self.threadComplete == True:
print 'checkThread KIIIIIIIIIIILLLLLLLLLLLLLLL'
self.session.remove_torrent(self.torrentHandle)
+ self.session.stop_natpmp()
+ self.session.stop_upnp()
+ self.session.stop_lsd()
+ self.session.stop_dht()
def debug(self):
try:
diff --git a/Player.py b/Player.py
index 39d7b95..5dea7e8 100644
--- a/Player.py
+++ b/Player.py
@@ -176,6 +176,9 @@ class TorrentPlayer(xbmc.Player):
self.on_playback_stopped = []
def setup_torrent(self):
+ self.torrent.initSession()
+ if self.__settings__.getSetting('encryption') == 'true':
+ self.torrent.encryptSession()
self.torrent.startSession()
upload_limit = self.__settings__.getSetting("upload_limit") if self.__settings__.getSetting(
"upload_limit") != "" else 0
@@ -355,13 +358,18 @@ class TorrentPlayer(xbmc.Player):
event.remove(callback)
def loop(self):
+ debug_counter=0
with closing(
OverlayText(w=OVERLAY_WIDTH, h=OVERLAY_HEIGHT, alignment=XBFONT_CENTER_X | XBFONT_CENTER_Y)) as overlay:
with nested(self.attach(overlay.show, self.on_playback_paused),
self.attach(overlay.hide, self.on_playback_resumed, self.on_playback_stopped)):
while not xbmc.abortRequested and self.isPlaying() and not self.torrent.threadComplete:
self.torrent.checkThread()
- self.torrent.debug()
+ if self.iterator == 100 and debug_counter < 100:
+ debug_counter += 1
+ else:
+ self.torrent.debug()
+ debug_counter=0
status = self.torrent.torrentHandle.status()
overlay.text = "\n".join(self._get_status_lines(status))
# downloadedSize = torrent.torrentHandle.file_progress()[contentId]
diff --git a/changelog.txt b/changelog.txt
index e9e7be5..a484e6a 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,4 +1,8 @@
-[B]Version 2.2.8[/B]
+[B]Version 2.2.9[/B]
+[+] .torrent Проигрыватель: Теперь .torrent не теряется при обновлении окна Kodi
+[+] Проигрыватель: Улучшенная настройка сессии из cherrytorrent
+
+[B]Version 2.2.8[/B]
[+] Добавлен Украинский язык (by kharts)
[+] Торрент-клиент: Добавлены иконки торрент-клиентов (by kharts)
diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml
index 44c51df..81e033c 100644
--- a/resources/language/English/strings.xml
+++ b/resources/language/English/strings.xml
@@ -38,6 +38,7 @@
Download via Python-Libtorrent
Sort search results by seeds
Custom search option phrase
+ Encryption
Interface
P2P Network
Advanced
diff --git a/resources/language/Russian/strings.xml b/resources/language/Russian/strings.xml
index ae9f45f..023e6a3 100644
--- a/resources/language/Russian/strings.xml
+++ b/resources/language/Russian/strings.xml
@@ -38,6 +38,7 @@
Скачать Python-Libtorrent
Сортировать поиск по количеству раздающих
Дополнительная фраза в вариантах поиска
+ Шифрование
Интерфейс
P2P Сеть
Дополнительные
diff --git a/resources/language/Ukrainian/strings.xml b/resources/language/Ukrainian/strings.xml
index 44afccd..3268026 100644
--- a/resources/language/Ukrainian/strings.xml
+++ b/resources/language/Ukrainian/strings.xml
@@ -38,6 +38,7 @@
Завантажити за допомогою Python-Libtorrent
Сортувати результати пошуку по кількості роздач
Додаткова пошукова фраза в варіантах пошуку
+ Шифрування
Інтерфейс
P2P Мережа
Додатково
diff --git a/resources/settings.xml b/resources/settings.xml
index 21fa295..ebd80ed 100644
--- a/resources/settings.xml
+++ b/resources/settings.xml
@@ -137,6 +137,13 @@
visible="eq(-9,0)"
enable="eq(-7,true)"
/>
+