android update

pull/1/head
DiMartinoXBMC 2015-07-24 18:00:27 +03:00
parent cea4adbd41
commit bd8df8776a
4 changed files with 71 additions and 49 deletions

View File

@ -1,5 +1,7 @@
0.16.19k: 0.16.19:
Edit custom library path with keyboard Edit custom library path with keyboard
Added Android permission workaround (copy to kodi path)
Added Android system import try
0.6.19k: 0.6.19k:
Added custom library path Added custom library path

View File

@ -26,6 +26,7 @@ __settings__ = xbmcaddon.Addon(id='script.module.libtorrent')
__language__ = __settings__.getLocalizedString __language__ = __settings__.getLocalizedString
if __settings__.getSetting('ask_dirname')=='true': if __settings__.getSetting('ask_dirname')=='true':
set_dirname=__settings__.getSetting('dirname') set_dirname=__settings__.getSetting('dirname')
__settings__.setSetting('ask_dirname','false')
keyboard = xbmc.Keyboard(set_dirname, __language__(1002)) keyboard = xbmc.Keyboard(set_dirname, __language__(1002))
keyboard.doModal() keyboard.doModal()
path_keyboard = keyboard.getText() path_keyboard = keyboard.getText()

View File

@ -65,14 +65,27 @@ try:
log('CDLL = ' + str(liblibtorrent)) log('CDLL = ' + str(liblibtorrent))
import libtorrent import libtorrent
elif platform['system'] in ['android_armv7', 'android_x86']: elif platform['system'] in ['android_armv7', 'android_x86']:
try:
import libtorrent
log('Imported libtorrent v' + libtorrent.version + ' from system')
except Exception, e:
log('Error importing libtorrent from system. Exception: ' + str(e))
import imp import imp
from ctypes import CDLL from ctypes import CDLL
try:
dll_path=os.path.join(dest_path, 'liblibtorrent.so') dll_path=os.path.join(dest_path, 'liblibtorrent.so')
log('CDLL path = ' + dll_path) log('CDLL path = ' + dll_path)
liblibtorrent=CDLL(dll_path) liblibtorrent=CDLL(dll_path)
log('CDLL = ' + str(liblibtorrent)) log('CDLL = ' + str(liblibtorrent))
except:
# If no permission in dest_path we need to go deeper!
# http://i3.kym-cdn.com/photos/images/original/000/531/557/a88.jpg
dest_path=lm.android_workaround()
dll_path=os.path.join(dest_path, 'liblibtorrent.so')
log('NEW CDLL path = ' + dll_path)
liblibtorrent=CDLL(dll_path)
log('CDLL = ' + str(liblibtorrent))
path_list = [dest_path] path_list = [dest_path]
log('path_list = ' + str(path_list)) log('path_list = ' + str(path_list))
fp, pathname, description = imp.find_module('libtorrent', path_list) fp, pathname, description = imp.find_module('libtorrent', path_list)
@ -83,10 +96,10 @@ try:
finally: finally:
if fp: fp.close() if fp: fp.close()
log('Imported libtorrent v' + libtorrent.version + ' from ' + dest_path) log('Imported libtorrent v' + libtorrent.version + ' from "' + dest_path + '"')
except Exception, e: except Exception, e:
log('Error importing libtorrent from' + dest_path + '. Exception: ' + str(e)) log('Error importing libtorrent from "' + dest_path + '". Exception: ' + str(e))
pass pass
def get_libtorrent(): def get_libtorrent():

View File

@ -13,31 +13,6 @@ __language__ = __settings__.getLocalizedString
from platform_pulsar import get_platform, get_libname from platform_pulsar import get_platform, get_libname
class DownloaderClass():
def __init__(self, dest_path):
self.dest_path = dest_path
self.platform = get_platform()
tempdir(self.dest_path)
def tools_download(self):
for libname in get_libname(self.platform):
dest = os.path.join(self.dest_path, libname)
log("try to fetch %s" % libname)
url = "%s/%s/%s.zip" % (__libbaseurl__, self.platform['system'], libname)
if libname!='liblibtorrent.so':
try:
self.http = HTTP()
self.http.fetch(url, download=dest + ".zip", progress=True)
log("%s -> %s" % (url, dest))
xbmc.executebuiltin('XBMC.Extract("%s.zip","%s")' % (dest, self.dest_path), True)
xbmcvfs.delete(dest + ".zip")
except:
text = 'Failed download %s!' % libname
xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__plugin__,text,750,__icon__))
else:
x=xbmcvfs.copy(os.path.join(self.dest_path, 'libtorrent.so'), dest)
return True
def log(msg): def log(msg):
try: try:
xbmc.log("### [%s]: %s" % (__plugin__,msg,), level=xbmc.LOGNOTICE ) xbmc.log("### [%s]: %s" % (__plugin__,msg,), level=xbmc.LOGNOTICE )
@ -46,10 +21,6 @@ def log(msg):
except: except:
xbmc.log("### [%s]: %s" % (__plugin__,'ERROR LOG',), level=xbmc.LOGNOTICE ) xbmc.log("### [%s]: %s" % (__plugin__,'ERROR LOG',), level=xbmc.LOGNOTICE )
def tempdir(dirname):
xbmcvfs.mkdirs(dirname)
return dirname
def getSettingAsBool(setting): def getSettingAsBool(setting):
return __settings__.getSetting(setting).lower() == "true" return __settings__.getSetting(setting).lower() == "true"
@ -85,4 +56,39 @@ class LibraryManager():
self.download() self.download()
def download(self): def download(self):
DownloaderClass(self.dest_path).tools_download() xbmcvfs.mkdirs(self.dest_path)
for libname in get_libname(self.platform):
dest = os.path.join(self.dest_path, libname)
log("try to fetch %s" % libname)
url = "%s/%s/%s.zip" % (__libbaseurl__, self.platform['system'], libname)
if libname!='liblibtorrent.so':
try:
self.http = HTTP()
self.http.fetch(url, download=dest + ".zip", progress=True)
log("%s -> %s" % (url, dest))
xbmc.executebuiltin('XBMC.Extract("%s.zip","%s")' % (dest, self.dest_path), True)
xbmcvfs.delete(dest + ".zip")
except:
text = 'Failed download %s!' % libname
xbmc.executebuiltin("XBMC.Notification(%s,%s,%s,%s)" % (__plugin__,text,750,__icon__))
else:
xbmcvfs.copy(os.path.join(self.dest_path, 'libtorrent.so'), dest)
return True
def android_workaround(self):
new_dest_path=os.path.join(xbmc.translatePath('special://xbmc'), self.platform['system'])
for libname in get_libname(self.platform):
libpath=os.path.join(self.dest_path, libname)
size=str(os.path.getsize(libpath))
new_libpath=os.path.join(new_dest_path, libname)
if not xbmcvfs.exists(new_libpath):
xbmcvfs.copy(libpath, new_libpath)
log('Copied %s -> %s' %(libpath, new_libpath))
else:
new_size=str(os.path.getsize(new_libpath))
if size!=new_size:
xbmcvfs.delete(new_libpath)
xbmcvfs.copy(libpath, new_libpath)
log('Deleted and copied (%s) %s -> (%s) %s' %(size, libpath, new_size, new_libpath))
return new_dest_path