Rimossi collegamenti a libtorrent

This commit is contained in:
Alhaziel01
2020-05-11 19:49:14 +02:00
parent f7c85c97dd
commit 5cc48a4d7b
16 changed files with 305 additions and 1490 deletions

View File

@@ -70,11 +70,11 @@ def init():
verify_Kodi_video_DB()
#LIBTORRENT: se descarga el binario de Libtorrent cada vez que se actualiza Alfa
try:
threading.Thread(target=update_libtorrent).start() # Creamos un Thread independiente, hasta el fin de Kodi
time.sleep(2) # Dejamos terminar la inicialización...
except: # Si hay problemas de threading, nos vamos
logger.error(traceback.format_exc())
# try:
# threading.Thread(target=update_libtorrent).start() # Creamos un Thread independiente, hasta el fin de Kodi
# time.sleep(2) # Dejamos terminar la inicialización...
# except: # Si hay problemas de threading, nos vamos
# logger.error(traceback.format_exc())
# #QUASAR: Preguntamos si se hacen modificaciones a Quasar
# if not filetools.exists(filetools.join(config.get_data_path(), "quasar.json")) \
@@ -245,102 +245,102 @@ def update_external_addon(addon_name):
return False
def update_libtorrent():
logger.info()
# def update_libtorrent():
# logger.info()
if not config.get_setting("mct_buffer", server="torrent", default=""):
default = config.get_setting("torrent_client", server="torrent", default=0)
config.set_setting("torrent_client", default, server="torrent")
config.set_setting("mct_buffer", "50", server="torrent")
if config.get_setting("mct_download_path", server="torrent", default=config.get_setting("downloadpath")):
config.set_setting("mct_download_path", config.get_setting("downloadpath"), server="torrent")
config.set_setting("mct_background_download", True, server="torrent")
config.set_setting("mct_rar_unpack", True, server="torrent")
config.set_setting("bt_buffer", "50", server="torrent")
if config.get_setting("bt_download_path", server="torrent", default=config.get_setting("downloadpath")):
config.set_setting("bt_download_path", config.get_setting("downloadpath"), server="torrent")
config.set_setting("mct_download_limit", "", server="torrent")
config.set_setting("magnet2torrent", False, server="torrent")
# if not config.get_setting("mct_buffer", server="torrent", default=""):
# default = config.get_setting("torrent_client", server="torrent", default=0)
# config.set_setting("torrent_client", default, server="torrent")
# config.set_setting("mct_buffer", "50", server="torrent")
# if config.get_setting("mct_download_path", server="torrent", default=config.get_setting("downloadpath")):
# config.set_setting("mct_download_path", config.get_setting("downloadpath"), server="torrent")
# config.set_setting("mct_background_download", True, server="torrent")
# config.set_setting("mct_rar_unpack", True, server="torrent")
# config.set_setting("bt_buffer", "50", server="torrent")
# if config.get_setting("bt_download_path", server="torrent", default=config.get_setting("downloadpath")):
# config.set_setting("bt_download_path", config.get_setting("downloadpath"), server="torrent")
# config.set_setting("mct_download_limit", "", server="torrent")
# config.set_setting("magnet2torrent", False, server="torrent")
if not filetools.exists(filetools.join(config.get_runtime_path(), "custom_code.json")) or not \
config.get_setting("unrar_path", server="torrent", default=""):
# if not filetools.exists(filetools.join(config.get_runtime_path(), "custom_code.json")) or not \
# config.get_setting("unrar_path", server="torrent", default=""):
path = filetools.join(config.get_runtime_path(), 'lib', 'rarfiles')
creationflags = ''
sufix = ''
unrar = ''
for device in filetools.listdir(path):
if xbmc.getCondVisibility("system.platform.android") and 'android' not in device: continue
if xbmc.getCondVisibility("system.platform.windows") and 'windows' not in device: continue
if not xbmc.getCondVisibility("system.platform.windows") and not xbmc.getCondVisibility("system.platform.android") \
and ('android' in device or 'windows' in device): continue
if 'windows' in device:
creationflags = 0x08000000
sufix = '.exe'
else:
creationflags = ''
sufix = ''
unrar = filetools.join(path, device, 'unrar%s') % sufix
if not filetools.exists(unrar): unrar = ''
if unrar:
if not xbmc.getCondVisibility("system.platform.windows"):
try:
if xbmc.getCondVisibility("system.platform.android"):
# Para Android copiamos el binario a la partición del sistema
unrar_org = unrar
unrar = filetools.join(xbmc.translatePath('special://xbmc/'), 'files').replace('/cache/apk/assets', '')
if not filetools.exists(unrar):
filetools.mkdir(unrar)
unrar = filetools.join(unrar, 'unrar')
filetools.copy(unrar_org, unrar, silent=True)
# path = filetools.join(config.get_runtime_path(), 'lib', 'rarfiles')
# creationflags = ''
# sufix = ''
# unrar = ''
# for device in filetools.listdir(path):
# if xbmc.getCondVisibility("system.platform.android") and 'android' not in device: continue
# if xbmc.getCondVisibility("system.platform.windows") and 'windows' not in device: continue
# if not xbmc.getCondVisibility("system.platform.windows") and not xbmc.getCondVisibility("system.platform.android") \
# and ('android' in device or 'windows' in device): continue
# if 'windows' in device:
# creationflags = 0x08000000
# sufix = '.exe'
# else:
# creationflags = ''
# sufix = ''
# unrar = filetools.join(path, device, 'unrar%s') % sufix
# if not filetools.exists(unrar): unrar = ''
# if unrar:
# if not xbmc.getCondVisibility("system.platform.windows"):
# try:
# if xbmc.getCondVisibility("system.platform.android"):
# # Para Android copiamos el binario a la partición del sistema
# unrar_org = unrar
# unrar = filetools.join(xbmc.translatePath('special://xbmc/'), 'files').replace('/cache/apk/assets', '')
# if not filetools.exists(unrar):
# filetools.mkdir(unrar)
# unrar = filetools.join(unrar, 'unrar')
# filetools.copy(unrar_org, unrar, silent=True)
command = ['chmod', '777', '%s' % unrar]
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output_cmd, error_cmd = p.communicate()
command = ['ls', '-l', unrar]
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output_cmd, error_cmd = p.communicate()
xbmc.log('######## UnRAR file: %s' % str(output_cmd), xbmc.LOGNOTICE)
except:
xbmc.log('######## UnRAR ERROR in path: %s' % str(unrar), xbmc.LOGNOTICE)
logger.error(traceback.format_exc(1))
# command = ['chmod', '777', '%s' % unrar]
# p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# output_cmd, error_cmd = p.communicate()
# command = ['ls', '-l', unrar]
# p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# output_cmd, error_cmd = p.communicate()
# xbmc.log('######## UnRAR file: %s' % str(output_cmd), xbmc.LOGNOTICE)
# except:
# xbmc.log('######## UnRAR ERROR in path: %s' % str(unrar), xbmc.LOGNOTICE)
# logger.error(traceback.format_exc(1))
try:
if xbmc.getCondVisibility("system.platform.windows"):
p = subprocess.Popen(unrar, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=creationflags)
else:
p = subprocess.Popen(unrar, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output_cmd, error_cmd = p.communicate()
if p.returncode != 0 or error_cmd:
xbmc.log('######## UnRAR returncode in module %s: %s, %s in %s' % \
(device, str(p.returncode), str(error_cmd), unrar), xbmc.LOGNOTICE)
unrar = ''
else:
xbmc.log('######## UnRAR OK in %s: %s' % (device, unrar), xbmc.LOGNOTICE)
break
except:
xbmc.log('######## UnRAR ERROR in module %s: %s' % (device, unrar), xbmc.LOGNOTICE)
logger.error(traceback.format_exc(1))
unrar = ''
# try:
# if xbmc.getCondVisibility("system.platform.windows"):
# p = subprocess.Popen(unrar, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=creationflags)
# else:
# p = subprocess.Popen(unrar, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# output_cmd, error_cmd = p.communicate()
# if p.returncode != 0 or error_cmd:
# xbmc.log('######## UnRAR returncode in module %s: %s, %s in %s' % \
# (device, str(p.returncode), str(error_cmd), unrar), xbmc.LOGNOTICE)
# unrar = ''
# else:
# xbmc.log('######## UnRAR OK in %s: %s' % (device, unrar), xbmc.LOGNOTICE)
# break
# except:
# xbmc.log('######## UnRAR ERROR in module %s: %s' % (device, unrar), xbmc.LOGNOTICE)
# logger.error(traceback.format_exc(1))
# unrar = ''
if unrar: config.set_setting("unrar_path", unrar, server="torrent")
# if unrar: config.set_setting("unrar_path", unrar, server="torrent")
if filetools.exists(filetools.join(config.get_runtime_path(), "custom_code.json")) and \
config.get_setting("libtorrent_path", server="torrent", default="") :
return
# if filetools.exists(filetools.join(config.get_runtime_path(), "custom_code.json")) and \
# config.get_setting("libtorrent_path", server="torrent", default="") :
# return
try:
from lib.python_libtorrent.python_libtorrent import get_libtorrent
except Exception as e:
logger.error(traceback.format_exc(1))
if not PY3:
e = unicode(str(e), "utf8", errors="replace").encode("utf8")
config.set_setting("libtorrent_path", "", server="torrent")
if not config.get_setting("libtorrent_error", server="torrent", default=''):
config.set_setting("libtorrent_error", str(e), server="torrent")
# try:
# from lib.python_libtorrent.python_libtorrent import get_libtorrent
# except Exception as e:
# logger.error(traceback.format_exc(1))
# if not PY3:
# e = unicode(str(e), "utf8", errors="replace").encode("utf8")
# config.set_setting("libtorrent_path", "", server="torrent")
# if not config.get_setting("libtorrent_error", server="torrent", default=''):
# config.set_setting("libtorrent_error", str(e), server="torrent")
return
# return
def verify_Kodi_video_DB():

View File

@@ -4,7 +4,6 @@
# ------------------------------------------------------------
from __future__ import division
# from builtins import str
from past.utils import old_div
import sys
@@ -31,8 +30,8 @@ from platformcode import logger, config, platformtools
def get_environment():
"""
Devuelve las variables de entorno del OS, de Kodi y de Alfa más habituales,
necesarias para el diagnóstico de fallos
Returns the most common OS, Kodi and Alpha environment variables,
    necessary for fault diagnosis
"""
try:
@@ -56,9 +55,9 @@ def get_environment():
try:
for label_a in subprocess.check_output('getprop').split('\n'):
if 'build.version.release' in label_a:
environment['os_release'] = str(scrapertools.find_single_match(label_a, ':\s*\[(.*?)\]$'))
environment['os_release'] = str(scrapertools.find_single_match(label_a, r':\s*\[(.*?)\]$'))
if 'product.model' in label_a:
environment['prod_model'] = str(scrapertools.find_single_match(label_a, ':\s*\[(.*?)\]$'))
environment['prod_model'] = str(scrapertools.find_single_match(label_a, r':\s*\[(.*?)\]$'))
except:
try:
for label_a in filetools.read(os.environ['ANDROID_ROOT'] + '/build.prop').split():
@@ -196,87 +195,87 @@ def get_environment():
except:
environment['videolab_free'] = '?'
environment['torrent_list'] = []
environment['torrentcli_option'] = ''
environment['torrent_error'] = ''
environment['torrentcli_rar'] = config.get_setting("mct_rar_unpack", server="torrent", default=True)
environment['torrentcli_backgr'] = config.get_setting("mct_background_download", server="torrent", default=True)
environment['torrentcli_lib_path'] = config.get_setting("libtorrent_path", server="torrent", default="")
if environment['torrentcli_lib_path']:
lib_path = 'Activo'
else:
lib_path = 'Inactivo'
environment['torrentcli_unrar'] = config.get_setting("unrar_path", server="torrent", default="")
if environment['torrentcli_unrar']:
if xbmc.getCondVisibility("system.platform.Android"):
unrar = 'Android'
else:
unrar, bin = filetools.split(environment['torrentcli_unrar'])
unrar = unrar.replace('\\', '/')
if not unrar.endswith('/'):
unrar = unrar + '/'
unrar = scrapertools.find_single_match(unrar, '\/([^\/]+)\/$').capitalize()
else:
unrar = 'Inactivo'
torrent_id = config.get_setting("torrent_client", server="torrent", default=0)
environment['torrentcli_option'] = str(torrent_id)
torrent_options = platformtools.torrent_client_installed()
if lib_path == 'Activo':
torrent_options = ['MCT'] + torrent_options
torrent_options = ['BT'] + torrent_options
environment['torrent_list'].append({'Torrent_opt': str(torrent_id), 'Libtorrent': lib_path, \
'RAR_Auto': str(environment['torrentcli_rar']), \
'RAR_backgr': str(environment['torrentcli_backgr']), \
'UnRAR': unrar})
environment['torrent_error'] = config.get_setting("libtorrent_error", server="torrent", default="")
if environment['torrent_error']:
environment['torrent_list'].append({'Libtorrent_error': environment['torrent_error']})
# environment['torrent_list'] = []
# environment['torrentcli_option'] = ''
# environment['torrent_error'] = ''
# environment['torrentcli_rar'] = config.get_setting("mct_rar_unpack", server="torrent", default=True)
# environment['torrentcli_backgr'] = config.get_setting("mct_background_download", server="torrent", default=True)
# environment['torrentcli_lib_path'] = config.get_setting("libtorrent_path", server="torrent", default="")
# if environment['torrentcli_lib_path']:
# lib_path = 'Activo'
# else:
# lib_path = 'Inactivo'
# environment['torrentcli_unrar'] = config.get_setting("unrar_path", server="torrent", default="")
# if environment['torrentcli_unrar']:
# if xbmc.getCondVisibility("system.platform.Android"):
# unrar = 'Android'
# else:
# unrar, bin = filetools.split(environment['torrentcli_unrar'])
# unrar = unrar.replace('\\', '/')
# if not unrar.endswith('/'):
# unrar = unrar + '/'
# unrar = scrapertools.find_single_match(unrar, '\/([^\/]+)\/$').capitalize()
# else:
# unrar = 'Inactivo'
# torrent_id = config.get_setting("torrent_client", server="torrent", default=0)
# environment['torrentcli_option'] = str(torrent_id)
# torrent_options = platformtools.torrent_client_installed()
# if lib_path == 'Activo':
# torrent_options = ['MCT'] + torrent_options
# torrent_options = ['BT'] + torrent_options
# environment['torrent_list'].append({'Torrent_opt': str(torrent_id), 'Libtorrent': lib_path, \
# 'RAR_Auto': str(environment['torrentcli_rar']), \
# 'RAR_backgr': str(environment['torrentcli_backgr']), \
# 'UnRAR': unrar})
# environment['torrent_error'] = config.get_setting("libtorrent_error", server="torrent", default="")
# if environment['torrent_error']:
# environment['torrent_list'].append({'Libtorrent_error': environment['torrent_error']})
for torrent_option in torrent_options:
cliente = dict()
cliente['D_load_Path'] = ''
cliente['Libre'] = '?'
cliente['Plug_in'] = torrent_option.replace('Plugin externo: ', '')
if cliente['Plug_in'] == 'BT':
cliente['D_load_Path'] = str(config.get_setting("bt_download_path", server="torrent", default=''))
if not cliente['D_load_Path']: continue
cliente['Buffer'] = str(config.get_setting("bt_buffer", server="torrent", default=50))
elif cliente['Plug_in'] == 'MCT':
cliente['D_load_Path'] = str(config.get_setting("mct_download_path", server="torrent", default=''))
if not cliente['D_load_Path']: continue
cliente['Buffer'] = str(config.get_setting("mct_buffer", server="torrent", default=50))
elif xbmc.getCondVisibility('System.HasAddon("plugin.video.%s")' % cliente['Plug_in']):
__settings__ = xbmcaddon.Addon(id="plugin.video.%s" % cliente['Plug_in'])
cliente['Plug_in'] = cliente['Plug_in'].capitalize()
if cliente['Plug_in'] == 'Torrenter':
cliente['D_load_Path'] = str(xbmc.translatePath(__settings__.getSetting('storage')))
if not cliente['D_load_Path']:
cliente['D_load_Path'] = str(filetools.join(xbmc.translatePath("special://home/"), \
"cache", "xbmcup", "plugin.video.torrenter",
"Torrenter"))
cliente['Buffer'] = str(__settings__.getSetting('pre_buffer_bytes'))
else:
cliente['D_load_Path'] = str(xbmc.translatePath(__settings__.getSetting('download_path')))
cliente['Buffer'] = str(__settings__.getSetting('buffer_size'))
if __settings__.getSetting('download_storage') == '1' and __settings__.getSetting('memory_size'):
cliente['Memoria'] = str(__settings__.getSetting('memory_size'))
# for torrent_option in torrent_options:
# cliente = dict()
# cliente['D_load_Path'] = ''
# cliente['Libre'] = '?'
# cliente['Plug_in'] = torrent_option.replace('Plugin externo: ', '')
# if cliente['Plug_in'] == 'BT':
# cliente['D_load_Path'] = str(config.get_setting("bt_download_path", server="torrent", default=''))
# if not cliente['D_load_Path']: continue
# cliente['Buffer'] = str(config.get_setting("bt_buffer", server="torrent", default=50))
# elif cliente['Plug_in'] == 'MCT':
# cliente['D_load_Path'] = str(config.get_setting("mct_download_path", server="torrent", default=''))
# if not cliente['D_load_Path']: continue
# cliente['Buffer'] = str(config.get_setting("mct_buffer", server="torrent", default=50))
# elif xbmc.getCondVisibility('System.HasAddon("plugin.video.%s")' % cliente['Plug_in']):
# __settings__ = xbmcaddon.Addon(id="plugin.video.%s" % cliente['Plug_in'])
# cliente['Plug_in'] = cliente['Plug_in'].capitalize()
# if cliente['Plug_in'] == 'Torrenter':
# cliente['D_load_Path'] = str(xbmc.translatePath(__settings__.getSetting('storage')))
# if not cliente['D_load_Path']:
# cliente['D_load_Path'] = str(filetools.join(xbmc.translatePath("special://home/"), \
# "cache", "xbmcup", "plugin.video.torrenter",
# "Torrenter"))
# cliente['Buffer'] = str(__settings__.getSetting('pre_buffer_bytes'))
# else:
# cliente['D_load_Path'] = str(xbmc.translatePath(__settings__.getSetting('download_path')))
# cliente['Buffer'] = str(__settings__.getSetting('buffer_size'))
# if __settings__.getSetting('download_storage') == '1' and __settings__.getSetting('memory_size'):
# cliente['Memoria'] = str(__settings__.getSetting('memory_size'))
if cliente['D_load_Path']:
try:
if environment['os_name'].lower() == 'windows':
free_bytes = ctypes.c_ulonglong(0)
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(cliente['D_load_Path']),
None, None, ctypes.pointer(free_bytes))
cliente['Libre'] = str(round(float(free_bytes.value) / \
(1024 ** 3), 3)).replace('.', ',')
else:
disk_space = os.statvfs(cliente['D_load_Path'])
if not disk_space.f_frsize: disk_space.f_frsize = disk_space.f_frsize.f_bsize
cliente['Libre'] = str(round((float(disk_space.f_bavail) / \
(1024 ** 3)) * float(disk_space.f_frsize), 3)).replace('.', ',')
except:
pass
environment['torrent_list'].append(cliente)
# if cliente['D_load_Path']:
# try:
# if environment['os_name'].lower() == 'windows':
# free_bytes = ctypes.c_ulonglong(0)
# ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(cliente['D_load_Path']),
# None, None, ctypes.pointer(free_bytes))
# cliente['Libre'] = str(round(float(free_bytes.value) / \
# (1024 ** 3), 3)).replace('.', ',')
# else:
# disk_space = os.statvfs(cliente['D_load_Path'])
# if not disk_space.f_frsize: disk_space.f_frsize = disk_space.f_frsize.f_bsize
# cliente['Libre'] = str(round((float(disk_space.f_bavail) / \
# (1024 ** 3)) * float(disk_space.f_frsize), 3)).replace('.', ',')
# except:
# pass
# environment['torrent_list'].append(cliente)
environment['proxy_active'] = ''
try: