Версия для Kodi 19
This commit is contained in:
1 parent
e5bd0ca668
commit
baf6d0c369
8 files changed
+235
-203
No files matched your search
@@ -1,28 +1,26 @@
|
||||
from codequick.support import addon_data # @UnresolvedImport
|
||||
from codequick.listing import local_image # @UnresolvedImport
|
||||
from urlquick import urljoin # @UnresolvedImport
|
||||
from codequick.support import addon_data # @UnresolvedImport
|
||||
from codequick.utils import urljoin_partial # @UnresolvedImport
|
||||
from ..settings import option
|
||||
import xbmcgui
|
||||
import os
|
||||
from hashlib import sha1
|
||||
from pyrrent2http import Engine # @UnresolvedImport
|
||||
import sys
|
||||
py3 = sys.version_info >= (3, 0)
|
||||
if py3:
|
||||
from urllib.request import pathname2url # @UnresolvedImport
|
||||
else:
|
||||
from urllib import pathname2url
|
||||
from urllib.request import pathname2url
|
||||
|
||||
|
||||
def notify(heading, message, icon=xbmcgui.NOTIFICATION_INFO):
|
||||
n = xbmcgui.Dialog()
|
||||
n.notification(heading, message, icon, time=5, sound=True)
|
||||
|
||||
|
||||
def localize(sid):
|
||||
return addon_data.getLocalizedString(sid)
|
||||
|
||||
|
||||
def store_torrent_file(file_bytes):
|
||||
h = sha1(file_bytes).hexdigest()
|
||||
t_fname = '{}.torrent'.format(h)
|
||||
full_path = os.path.join(storage_toorents_dir, t_fname)
|
||||
full_path = os.path.join(storage_torrents_dir, t_fname)
|
||||
if os.path.exists(full_path):
|
||||
with open(full_path, 'rb') as f:
|
||||
if sha1(f.read()).hexdigest() == h:
|
||||
@@ -30,32 +28,39 @@ def store_torrent_file(file_bytes):
|
||||
with open(full_path, 'wb') as f:
|
||||
f.write(file_bytes)
|
||||
return full_path
|
||||
|
||||
|
||||
def torrent_full_path(t_fname):
|
||||
return os.path.join(storage_toorents_dir, t_fname)
|
||||
return os.path.join(storage_torrents_dir, t_fname)
|
||||
|
||||
|
||||
def file_url(path):
|
||||
if not path.startswith('file:'):
|
||||
path = urljoin('file:', pathname2url(path))
|
||||
path = urljoin_partial('file:')(pathname2url(path))
|
||||
return path
|
||||
|
||||
|
||||
def get_engine(torrent_uri):
|
||||
if option.get_boolean('use_socks_for_trackers'): # @UndefinedVariable
|
||||
if option.get_boolean('use_socks_for_trackers'): # @UndefinedVariable
|
||||
proxy = {
|
||||
'host': option['socks_ip'],
|
||||
'port': int(option['socks_port'])
|
||||
}
|
||||
}
|
||||
else:
|
||||
proxy = None
|
||||
return Engine(uri=file_url(torrent_uri), download_path=storage_download_dir,
|
||||
encryption=1, keep_complete=False, keep_incomplete=False,
|
||||
dht_routers=["router.bittorrent.com:6881", "router.utorrent.com:6881"], use_random_port=False, listen_port=6881,
|
||||
user_agent='', enable_dht=True, proxy=proxy)
|
||||
encryption=1, keep_complete=False, keep_incomplete=False,
|
||||
dht_routers=["router.bittorrent.com:6881", "router.utorrent.com:6881"], use_random_port=False,
|
||||
listen_port=6881,
|
||||
user_agent='', enable_dht=True, proxy=proxy)
|
||||
|
||||
|
||||
while not option['storage_dir']:
|
||||
dialog = xbmcgui.Dialog()
|
||||
dialog.ok(localize(33000), localize(33051))
|
||||
addon_data.openSettings()
|
||||
storage_root = os.path.abspath(os.path.join(option['storage_dir'], 'Torrenter3'))
|
||||
storage_toorents_dir = os.path.join(storage_root, 'torrents')
|
||||
storage_torrents_dir = os.path.join(storage_root, 'torrents')
|
||||
storage_download_dir = os.path.join(storage_root, 'download')
|
||||
if not os.path.exists(storage_toorents_dir): os.makedirs(storage_toorents_dir)
|
||||
if not os.path.exists(storage_torrents_dir): os.makedirs(storage_torrents_dir)
|
||||
if not os.path.exists(storage_download_dir): os.makedirs(storage_download_dir)
|
||||
Reference in new issue
Block a user