major settings tweak and encryption

pull/1/head
DiMartinoXBMC 2015-06-28 18:04:09 +03:00
parent 539383d14f
commit 826e03da1b
9 changed files with 75 additions and 98 deletions

16
Core.py
View File

@ -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)

View File

@ -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()

View File

@ -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
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:

View File

@ -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()
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]

View File

@ -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)

View File

@ -38,6 +38,7 @@
<string id="30038">Download via Python-Libtorrent</string>
<string id="30039">Sort search results by seeds</string>
<string id="30040">Custom search option phrase</string>
<string id="30041">Encryption</string>
<string id="30101">Interface</string>
<string id="30102">P2P Network</string>
<string id="30103">Advanced</string>

View File

@ -38,6 +38,7 @@
<string id="30038">Скачать Python-Libtorrent</string>
<string id="30039">Сортировать поиск по количеству раздающих</string>
<string id="30040">Дополнительная фраза в вариантах поиска</string>
<string id="30041">Шифрование</string>
<string id="30101">Интерфейс</string>
<string id="30102">P2P Сеть</string>
<string id="30103">Дополнительные</string>

View File

@ -38,6 +38,7 @@
<string id="30038">Завантажити за допомогою Python-Libtorrent</string>
<string id="30039">Сортувати результати пошуку по кількості роздач</string>
<string id="30040">Додаткова пошукова фраза в варіантах пошуку</string>
<string id="30041">Шифрування</string>
<string id="30101">Інтерфейс</string>
<string id="30102">P2P Мережа</string>
<string id="30103">Додатково</string>

View File

@ -137,6 +137,13 @@
visible="eq(-9,0)"
enable="eq(-7,true)"
/>
<setting
id="encryption"
type="bool"
label="30041"
default="true"
visible="eq(-10,0)"
/>
</category>
<category label="Torrent-client">
<setting id="torrent_save" type="enum" label="50301" lvalues="50302|50303" default="0"/>