diff --git a/context.py b/context.py index 1b81c554..15256491 100644 --- a/context.py +++ b/context.py @@ -11,10 +11,13 @@ import xbmcaddon ################################################################################################# -cache = xbmc.translatePath('special://temp/emby').decode('utf-8') -sys.path.insert(0, cache) -__addon__ = xbmcaddon.Addon(id='plugin.video.emby').getAddonInfo('path').decode('utf-8') -__base__ = xbmc.translatePath(os.path.join(__addon__, 'resources', 'lib')).decode('utf-8') +__addon__ = xbmcaddon.Addon(id='plugin.video.emby') +__base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib')).decode('utf-8') +__pcache__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('profile'), 'emby')).decode('utf-8') +__cache__ = xbmc.translatePath('special://temp/emby').decode('utf-8') + +sys.path.insert(0, __cache__) +sys.path.insert(0, __pcache__) sys.path.append(__base__) ################################################################################################# diff --git a/context_play.py b/context_play.py index 3d86657c..660fb468 100644 --- a/context_play.py +++ b/context_play.py @@ -11,10 +11,13 @@ import xbmcaddon ################################################################################################# -cache = xbmc.translatePath('special://temp/emby').decode('utf-8') -sys.path.insert(0, cache) -__addon__ = xbmcaddon.Addon(id='plugin.video.emby').getAddonInfo('path').decode('utf-8') -__base__ = xbmc.translatePath(os.path.join(__addon__, 'resources', 'lib')).decode('utf-8') +__addon__ = xbmcaddon.Addon(id='plugin.video.emby') +__base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib')).decode('utf-8') +__pcache__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('profile'), 'emby')).decode('utf-8') +__cache__ = xbmc.translatePath('special://temp/emby').decode('utf-8') + +sys.path.insert(0, __cache__) +sys.path.insert(0, __pcache__) sys.path.append(__base__) ################################################################################################# diff --git a/default.py b/default.py index 00b92ad9..0305ee81 100644 --- a/default.py +++ b/default.py @@ -11,10 +11,13 @@ import xbmcaddon ################################################################################################# -cache = xbmc.translatePath('special://temp/emby').decode('utf-8') -sys.path.insert(0, cache) -__addon__ = xbmcaddon.Addon(id='plugin.video.emby').getAddonInfo('path').decode('utf-8') -__base__ = xbmc.translatePath(os.path.join(__addon__, 'resources', 'lib')).decode('utf-8') +__addon__ = xbmcaddon.Addon(id='plugin.video.emby') +__base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib')).decode('utf-8') +__pcache__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('profile'), 'emby')).decode('utf-8') +__cache__ = xbmc.translatePath('special://temp/emby').decode('utf-8') + +sys.path.insert(0, __cache__) +sys.path.insert(0, __pcache__) sys.path.append(__base__) ################################################################################################# diff --git a/resources/lib/downloader.py b/resources/lib/downloader.py index 231b1d35..18064cfd 100644 --- a/resources/lib/downloader.py +++ b/resources/lib/downloader.py @@ -11,6 +11,7 @@ from datetime import datetime import xbmc import xbmcvfs +import xbmcaddon from libraries import requests from helper.utils import should_stop, delete_folder @@ -23,6 +24,7 @@ from emby.core.exceptions import HTTPException LOG = logging.getLogger("EMBY."+__name__) LIMIT = min(int(settings('limitIndex') or 50), 50) +CACHE = xbmc.translatePath(os.path.join(xbmcaddon.Addon(id='plugin.video.emby').getAddonInfo('profile').decode('utf-8'), 'emby')).decode('utf-8') ################################################################################################# @@ -352,7 +354,7 @@ def get_objects(src, filename): ''' Download objects dependency to temp cache folder. ''' - temp = xbmc.translatePath('special://temp/emby').decode('utf-8') + temp = CACHE restart = not xbmcvfs.exists(os.path.join(temp, "objects") + '/') path = os.path.join(temp, filename).encode('utf-8') @@ -362,7 +364,7 @@ def get_objects(src, filename): restart = False if not xbmcvfs.exists(path): - delete_folder() + delete_folder(CACHE) LOG.info("From %s to %s", src, path.decode('utf-8')) try: diff --git a/resources/lib/entrypoint/default.py b/resources/lib/entrypoint/default.py index aa0b996f..6dd02403 100644 --- a/resources/lib/entrypoint/default.py +++ b/resources/lib/entrypoint/default.py @@ -745,10 +745,10 @@ def get_themes(): from helper.playutils import PlayUtils from helper.xmls import tvtunes_nfo - library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/").decode('utf-8') + library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library").decode('utf-8') play = settings('useDirectPaths') == "1" - if not xbmcvfs.exists(library): + if not xbmcvfs.exists(library + '/'): xbmcvfs.mkdir(library) if xbmc.getCondVisibility('System.HasAddon(script.tvtunes)'): diff --git a/resources/lib/entrypoint/service.py b/resources/lib/entrypoint/service.py index 899c86a2..4cb74b74 100644 --- a/resources/lib/entrypoint/service.py +++ b/resources/lib/entrypoint/service.py @@ -182,24 +182,24 @@ class Service(xbmc.Monitor): if label == objects.version: LOG.info("--[ objects/%s ]", objects.version) - return + return False - if get_objects(zipfile, label + '.zip'): + get_objects(zipfile, label + '.zip') + reload(objects) # to apply latest changes - LOG.info("No previous patch found.") - dialog("ok", heading="{emby}", line1=_(33135)) - xbmc.executebuiltin('RestartApp') - else: - dialog("notification", heading="{emby}", message=_(33156), icon="{emby}") + dialog("notification", heading="{emby}", message=_(33156), icon="{emby}") + LOG.info("--[ new objects/%s ]", objects.version) - try: - if compare_version(self.settings['addon_version'], objects.embyversion) < 0: - dialog("ok", heading="{emby}", line1="%s %s" % (_(33160), objects.embyversion)) - except Exception: - pass + try: + if compare_version(self.settings['addon_version'], objects.embyversion) < 0: + dialog("ok", heading="{emby}", line1="%s %s" % (_(33160), objects.embyversion)) + except Exception: + pass except Exception as error: LOG.exception(error) + + return True def onNotification(self, sender, method, data): diff --git a/resources/lib/helper/utils.py b/resources/lib/helper/utils.py index ba0329ab..b737c703 100644 --- a/resources/lib/helper/utils.py +++ b/resources/lib/helper/utils.py @@ -373,6 +373,9 @@ def copytree(path, dest): ''' dirs, files = xbmcvfs.listdir(path) + if not xbmcvfs.exists(dest): + xbmcvfs.mkdirs(dest) + if dirs: copy_recursive(path, dirs, dest) @@ -401,6 +404,9 @@ def copy_file(path, dest): ''' Copy specific file. ''' + if path.endswith('.pyo'): + return + xbmcvfs.copy(path, dest) LOG.debug("copy: %s to %s", path, dest) diff --git a/service.py b/service.py index 07a90a44..5d5782ba 100644 --- a/service.py +++ b/service.py @@ -12,14 +12,18 @@ import xbmcaddon ################################################################################################# -cache = xbmc.translatePath('special://temp/emby').decode('utf-8') +__addon__ = xbmcaddon.Addon(id='plugin.video.emby') +__base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'resources', 'lib')).decode('utf-8') +__pcache__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('profile'), 'emby')).decode('utf-8') +__cache__ = xbmc.translatePath('special://temp/emby').decode('utf-8') -if not xbmcvfs.exists(cache): - xbmcvfs.mkdir(cache) +if not xbmcvfs.exists(__pcache__ + '/'): + from resources.lib.helper.utils import copytree -sys.path.insert(0, cache) -__addon__ = xbmcaddon.Addon(id='plugin.video.emby').getAddonInfo('path').decode('utf-8') -__base__ = xbmc.translatePath(os.path.join(__addon__, 'resources', 'lib')).decode('utf-8') + copytree(os.path.join(__base__, 'objects').decode('utf-8'), os.path.join(__pcache__, 'objects').decode('utf-8')) + +sys.path.insert(0, __cache__) +sys.path.insert(0, __pcache__) sys.path.append(__base__) #################################################################################################