diff --git a/changelog.txt b/changelog.txt index c624cc7..ad7dafe 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,7 @@ -0.16.19k: +0.16.19: Edit custom library path with keyboard +Added Android permission workaround (copy to kodi path) +Added Android system import try 0.6.19k: Added custom library path diff --git a/default.py b/default.py index b2c3fe5..6387199 100644 --- a/default.py +++ b/default.py @@ -26,6 +26,7 @@ __settings__ = xbmcaddon.Addon(id='script.module.libtorrent') __language__ = __settings__.getLocalizedString if __settings__.getSetting('ask_dirname')=='true': set_dirname=__settings__.getSetting('dirname') + __settings__.setSetting('ask_dirname','false') keyboard = xbmc.Keyboard(set_dirname, __language__(1002)) keyboard.doModal() path_keyboard = keyboard.getText() diff --git a/python_libtorrent/__init__.py b/python_libtorrent/__init__.py index 27ca0e6..d8ded52 100644 --- a/python_libtorrent/__init__.py +++ b/python_libtorrent/__init__.py @@ -65,28 +65,41 @@ try: log('CDLL = ' + str(liblibtorrent)) import libtorrent elif platform['system'] in ['android_armv7', 'android_x86']: - import imp - from ctypes import CDLL - - dll_path=os.path.join(dest_path, 'liblibtorrent.so') - log('CDLL path = ' + dll_path) - liblibtorrent=CDLL(dll_path) - log('CDLL = ' + str(liblibtorrent)) - - path_list = [dest_path] - log('path_list = ' + str(path_list)) - fp, pathname, description = imp.find_module('libtorrent', path_list) - log('fp = ' + str(fp)) - log('pathname = ' + str(pathname)) try: - libtorrent = imp.load_module('libtorrent', fp, pathname, description) - finally: - if fp: fp.close() + import libtorrent + log('Imported libtorrent v' + libtorrent.version + ' from system') + except Exception, e: + log('Error importing libtorrent from system. Exception: ' + str(e)) - log('Imported libtorrent v' + libtorrent.version + ' from ' + dest_path) + import imp + from ctypes import CDLL + try: + dll_path=os.path.join(dest_path, 'liblibtorrent.so') + log('CDLL path = ' + dll_path) + liblibtorrent=CDLL(dll_path) + 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] + log('path_list = ' + str(path_list)) + fp, pathname, description = imp.find_module('libtorrent', path_list) + log('fp = ' + str(fp)) + log('pathname = ' + str(pathname)) + try: + libtorrent = imp.load_module('libtorrent', fp, pathname, description) + finally: + if fp: fp.close() + + log('Imported libtorrent v' + libtorrent.version + ' from "' + dest_path + '"') except Exception, e: - log('Error importing libtorrent from' + dest_path + '. Exception: ' + str(e)) + log('Error importing libtorrent from "' + dest_path + '". Exception: ' + str(e)) pass def get_libtorrent(): diff --git a/python_libtorrent/functions.py b/python_libtorrent/functions.py index 7a990b3..4b05f62 100644 --- a/python_libtorrent/functions.py +++ b/python_libtorrent/functions.py @@ -13,31 +13,6 @@ __language__ = __settings__.getLocalizedString 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): try: xbmc.log("### [%s]: %s" % (__plugin__,msg,), level=xbmc.LOGNOTICE ) @@ -46,10 +21,6 @@ def log(msg): except: xbmc.log("### [%s]: %s" % (__plugin__,'ERROR LOG',), level=xbmc.LOGNOTICE ) -def tempdir(dirname): - xbmcvfs.mkdirs(dirname) - return dirname - def getSettingAsBool(setting): return __settings__.getSetting(setting).lower() == "true" @@ -85,4 +56,39 @@ class LibraryManager(): self.download() def download(self): - DownloaderClass(self.dest_path).tools_download() \ No newline at end of file + 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