From 5e7901be270cc88677b4a3bfc1559b6cde71c890 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 2 Oct 2021 13:26:37 -0400 Subject: [PATCH 1/2] Migrate to new translatePath library --- jellyfin_kodi/client.py | 4 ++-- jellyfin_kodi/database/__init__.py | 11 ++++++----- jellyfin_kodi/entrypoint/context.py | 3 ++- jellyfin_kodi/entrypoint/default.py | 16 ++++++++-------- jellyfin_kodi/entrypoint/service.py | 4 ++-- jellyfin_kodi/helper/loghandler.py | 3 ++- jellyfin_kodi/helper/playutils.py | 3 ++- jellyfin_kodi/helper/utils.py | 12 ++++++++++++ jellyfin_kodi/helper/xmls.py | 3 ++- jellyfin_kodi/objects/actions.py | 3 ++- jellyfin_kodi/player.py | 3 ++- jellyfin_kodi/views.py | 13 +++++++------ 12 files changed, 49 insertions(+), 29 deletions(-) diff --git a/jellyfin_kodi/client.py b/jellyfin_kodi/client.py index 76ea74b4..a521c7dd 100644 --- a/jellyfin_kodi/client.py +++ b/jellyfin_kodi/client.py @@ -8,7 +8,7 @@ import os from kodi_six import xbmc, xbmcaddon, xbmcvfs from helper import translate, window, settings, addon_id, dialog -from helper.utils import create_id +from helper.utils import create_id, translate_path from helper import LazyLogger # noqa: F402 ################################################################################################## @@ -85,7 +85,7 @@ def get_device_id(reset=False): if client_id: return client_id - directory = xbmc.translatePath('special://profile/addon_data/plugin.video.jellyfin/') + directory = translate_path('special://profile/addon_data/plugin.video.jellyfin/') if not xbmcvfs.exists(directory): xbmcvfs.mkdir(directory) diff --git a/jellyfin_kodi/database/__init__.py b/jellyfin_kodi/database/__init__.py index be1d6cbc..fe7d62e1 100644 --- a/jellyfin_kodi/database/__init__.py +++ b/jellyfin_kodi/database/__init__.py @@ -14,6 +14,7 @@ from six import text_type from database import jellyfin_db from helper import translate, settings, window, dialog +from helper.utils import translate_path from objects import obj from helper import LazyLogger @@ -21,7 +22,7 @@ from helper import LazyLogger LOG = LazyLogger(__name__) -ADDON_DATA = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/") +ADDON_DATA = translate_path("special://profile/addon_data/plugin.video.jellyfin/") ################################################################################################# @@ -77,7 +78,7 @@ class Database(object): def _get_database(self, path, silent=False): - path = xbmc.translatePath(path) + path = translate_path(path) if not silent: @@ -105,7 +106,7 @@ class Database(object): xbmc.executebuiltin('UpdateLibrary(video)') xbmc.sleep(200) - databases = xbmc.translatePath("special://database/") + databases = translate_path("special://database/") types = { 'video': "MyVideos", 'music': "MyMusic", @@ -131,7 +132,7 @@ class Database(object): LOG.debug("Discovered database: %s", target) self.discovered_file = target['db_file'] - return xbmc.translatePath("special://database/%s" % target['db_file']) + return translate_path("special://database/%s" % target['db_file']) def _sql(self, db_file): @@ -293,7 +294,7 @@ def reset_artwork(): ''' Remove all existing texture. ''' - thumbnails = xbmc.translatePath('special://thumbnails/') + thumbnails = translate_path('special://thumbnails/') if xbmcvfs.exists(thumbnails): dirs, ignore = xbmcvfs.listdir(thumbnails) diff --git a/jellyfin_kodi/entrypoint/context.py b/jellyfin_kodi/entrypoint/context.py index 2c5703ab..0b0f1708 100644 --- a/jellyfin_kodi/entrypoint/context.py +++ b/jellyfin_kodi/entrypoint/context.py @@ -12,6 +12,7 @@ import database from dialogs import context from helper import translate, settings, dialog from helper import LazyLogger +from helper.utils import translate_path from jellyfin import Jellyfin ################################################################################################# @@ -52,7 +53,7 @@ class Context(object): self.media = xbmc.getInfoLabel('ListItem.DBTYPE') item_id = None - addon_data = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/data.json") + addon_data = translate_path("special://profile/addon_data/plugin.video.jellyfin/data.json") with open(addon_data, 'rb') as infile: data = json.load(infile) diff --git a/jellyfin_kodi/entrypoint/default.py b/jellyfin_kodi/entrypoint/default.py index cbede539..910c2589 100644 --- a/jellyfin_kodi/entrypoint/default.py +++ b/jellyfin_kodi/entrypoint/default.py @@ -15,7 +15,7 @@ import client from database import reset, get_sync, Database, jellyfin_db, get_credentials from objects import Objects, Actions from helper import translate, event, settings, window, dialog, api, JSONRPC -from helper.utils import JsonDebugPrinter +from helper.utils import JsonDebugPrinter, translate_path from helper import LazyLogger from jellyfin import Jellyfin @@ -57,7 +57,7 @@ class Events(object): jellyfin_client = Jellyfin(server).get_client() api_client = jellyfin_client.jellyfin - addon_data = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/data.json") + addon_data = translate_path("special://profile/addon_data/plugin.video.jellyfin/data.json") try: with open(addon_data, 'rb') as infile: data = json.load(infile) @@ -519,7 +519,7 @@ def get_fanart(item_id, path, server_id=None, api_client=None): LOG.info("[ extra fanart ] %s", item_id) objects = Objects() list_li = [] - directory = xbmc.translatePath("special://thumbnails/jellyfin/%s/" % item_id) + directory = translate_path("special://thumbnails/jellyfin/%s/" % item_id) if not xbmcvfs.exists(directory): @@ -792,7 +792,7 @@ def get_themes(api_client): from helper.playutils import PlayUtils from helper.xmls import tvtunes_nfo - library = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/library") + library = translate_path("special://profile/addon_data/plugin.video.jellyfin/library") play = settings('useDirectPaths') == "1" if not xbmcvfs.exists(library + '/'): @@ -886,7 +886,7 @@ def backup(): delete_folder(backup) - addon_data = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin") + addon_data = translate_path("special://profile/addon_data/plugin.video.jellyfin") destination_data = os.path.join(backup, "addon_data", "plugin.video.jellyfin") destination_databases = os.path.join(backup, "Database") @@ -901,18 +901,18 @@ def backup(): databases = Objects().objects - db = xbmc.translatePath(databases['jellyfin']) + db = translate_path(databases['jellyfin']) xbmcvfs.copy(db, os.path.join(destination_databases, db.rsplit('\\', 1)[1])) LOG.info("copied jellyfin.db") - db = xbmc.translatePath(databases['video']) + db = translate_path(databases['video']) filename = db.rsplit('\\', 1)[1] xbmcvfs.copy(db, os.path.join(destination_databases, filename)) LOG.info("copied %s", filename) if settings('enableMusic.bool'): - db = xbmc.translatePath(databases['music']) + db = translate_path(databases['music']) filename = db.rsplit('\\', 1)[1] xbmcvfs.copy(db, os.path.join(destination_databases, filename)) LOG.info("copied %s", filename) diff --git a/jellyfin_kodi/entrypoint/service.py b/jellyfin_kodi/entrypoint/service.py index 04cc4161..8e30b27e 100644 --- a/jellyfin_kodi/entrypoint/service.py +++ b/jellyfin_kodi/entrypoint/service.py @@ -19,7 +19,7 @@ import library import monitor from views import Views from helper import translate, window, settings, event, dialog, set_addon_mode -from helper.utils import JsonDebugPrinter +from helper.utils import JsonDebugPrinter, translate_path from jellyfin import Jellyfin from helper import LazyLogger @@ -44,7 +44,7 @@ class Service(xbmc.Monitor): window('jellyfin_should_stop', clear=True) self.settings['addon_version'] = client.get_version() - self.settings['profile'] = xbmc.translatePath('special://profile') + self.settings['profile'] = translate_path('special://profile') self.settings['mode'] = settings('useDirectPaths') self.settings['log_level'] = settings('logLevel') or "1" self.settings['auth_check'] = True diff --git a/jellyfin_kodi/helper/loghandler.py b/jellyfin_kodi/helper/loghandler.py index f8341102..306a50f2 100644 --- a/jellyfin_kodi/helper/loghandler.py +++ b/jellyfin_kodi/helper/loghandler.py @@ -12,6 +12,7 @@ from kodi_six import xbmc, xbmcaddon import database from helper import get_filesystem_encoding +from helper.utils import translate_path from . import settings from . import kodi_version @@ -19,7 +20,7 @@ from . import kodi_version ################################################################################################## __addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin') -__pluginpath__ = xbmc.translatePath(__addon__.getAddonInfo('path')) +__pluginpath__ = translate_path(__addon__.getAddonInfo('path')) ################################################################################################## diff --git a/jellyfin_kodi/helper/playutils.py b/jellyfin_kodi/helper/playutils.py index 5b352d74..d6d1ea27 100644 --- a/jellyfin_kodi/helper/playutils.py +++ b/jellyfin_kodi/helper/playutils.py @@ -12,6 +12,7 @@ from kodi_six import xbmc, xbmcvfs import client import requests from helper import LazyLogger +from helper.utils import translate_path from . import translate, settings, window, dialog, api @@ -548,7 +549,7 @@ class PlayUtils(object): ''' Download external subtitles to temp folder to be able to have proper names to streams. ''' - temp = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/temp/") + temp = translate_path("special://profile/addon_data/plugin.video.jellyfin/temp/") if not xbmcvfs.exists(temp): xbmcvfs.mkdir(temp) diff --git a/jellyfin_kodi/helper/utils.py b/jellyfin_kodi/helper/utils.py index 5c7d8b89..80bfe13b 100644 --- a/jellyfin_kodi/helper/utils.py +++ b/jellyfin_kodi/helper/utils.py @@ -551,3 +551,15 @@ def find_library(server, item): LOG.error('No ancestor found, not syncing item with ID: {}'.format(item['Id'])) return {} + +def translate_path(path): + ''' + Use new library location for translate path starting in Kodi 19 + ''' + version = kodi_version() + + if version > 18: + return xbmcvfs.translatePath(path) + else: + return xbmc.translatePath(path) + diff --git a/jellyfin_kodi/helper/xmls.py b/jellyfin_kodi/helper/xmls.py index 921865bf..6e62ba9d 100644 --- a/jellyfin_kodi/helper/xmls.py +++ b/jellyfin_kodi/helper/xmls.py @@ -9,6 +9,7 @@ import xml.etree.ElementTree as etree from kodi_six import xbmc from helper import LazyLogger +from helper.utils import translate_path from . import translate, dialog, settings @@ -47,7 +48,7 @@ def advanced_settings(): if settings('useDirectPaths') != "0": return - path = xbmc.translatePath("special://profile/") + path = translate_path("special://profile/") file = os.path.join(path, 'advancedsettings.xml') try: diff --git a/jellyfin_kodi/objects/actions.py b/jellyfin_kodi/objects/actions.py index 4ebfb671..dd2c02de 100644 --- a/jellyfin_kodi/objects/actions.py +++ b/jellyfin_kodi/objects/actions.py @@ -15,6 +15,7 @@ from helper import translate, playutils, api, window, settings, dialog from dialogs import resume from helper import LazyLogger from jellyfin import Jellyfin +from helper.utils import translate_path from .obj import Objects @@ -34,7 +35,7 @@ class Actions(object): LOG.debug('No api client provided, attempting to use config file') jellyfin_client = Jellyfin(server_id).get_client() api_client = jellyfin_client.jellyfin - addon_data = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/data.json") + addon_data = translate_path("special://profile/addon_data/plugin.video.jellyfin/data.json") try: with open(addon_data, 'rb') as infile: data = json.load(infile) diff --git a/jellyfin_kodi/player.py b/jellyfin_kodi/player.py index 7f34568c..86c8eb34 100644 --- a/jellyfin_kodi/player.py +++ b/jellyfin_kodi/player.py @@ -11,6 +11,7 @@ from objects.obj import Objects from helper import translate, api, window, settings, dialog, event, JSONRPC from jellyfin import Jellyfin from helper import LazyLogger +from helper.utils import translate_path ################################################################################################# @@ -420,7 +421,7 @@ class Player(xbmc.Player): LOG.info("<[ transcode/%s ]", item['Id']) item['Server'].jellyfin.close_transcode(item['DeviceId'], item['PlaySessionId']) - path = xbmc.translatePath("special://profile/addon_data/plugin.video.jellyfin/temp/") + path = translate_path("special://profile/addon_data/plugin.video.jellyfin/temp/") if xbmcvfs.exists(path): dirs, files = xbmcvfs.listdir(path) diff --git a/jellyfin_kodi/views.py b/jellyfin_kodi/views.py index aa07aca7..43c98a4e 100644 --- a/jellyfin_kodi/views.py +++ b/jellyfin_kodi/views.py @@ -13,6 +13,7 @@ from database import Database, jellyfin_db, get_sync, save_sync from helper import translate, api, window, event from jellyfin import Jellyfin from helper import LazyLogger +from helper.utils import translate_path ################################################################################################# @@ -186,8 +187,8 @@ class Views(object): ''' Set up playlists, video nodes, window prop. ''' - node_path = xbmc.translatePath("special://profile/library/video") - playlist_path = xbmc.translatePath("special://profile/playlists/video") + node_path = translate_path("special://profile/library/video") + playlist_path = translate_path("special://profile/playlists/video") index = 0 # Kodi 19 doesn't seem to create this directory on it's own @@ -931,7 +932,7 @@ class Views(object): ''' Remove all jellyfin playlists. ''' - path = xbmc.translatePath("special://profile/playlists/video/") + path = translate_path("special://profile/playlists/video/") _, files = xbmcvfs.listdir(path) for file in files: if file.startswith('jellyfin'): @@ -941,7 +942,7 @@ class Views(object): ''' Remove playlist based based on view_id. ''' - path = xbmc.translatePath("special://profile/playlists/video/") + path = translate_path("special://profile/playlists/video/") _, files = xbmcvfs.listdir(path) for file in files: file = file @@ -958,7 +959,7 @@ class Views(object): ''' Remove node and children files. ''' - path = xbmc.translatePath("special://profile/library/video/") + path = translate_path("special://profile/library/video/") dirs, files = xbmcvfs.listdir(path) for file in files: @@ -980,7 +981,7 @@ class Views(object): ''' Remove node and children files based on view_id. ''' - path = xbmc.translatePath("special://profile/library/video/") + path = translate_path("special://profile/library/video/") dirs, files = xbmcvfs.listdir(path) for directory in dirs: From e8beee331c44339ffe2d45adf7cb77b11d745694 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 2 Oct 2021 14:23:28 -0400 Subject: [PATCH 2/2] Replace translatePath in top level files --- context.py | 8 ++++++-- context_play.py | 8 ++++++-- default.py | 8 ++++++-- service.py | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/context.py b/context.py index 88eea1b3..2a6b3d5a 100644 --- a/context.py +++ b/context.py @@ -6,12 +6,16 @@ from __future__ import division, absolute_import, print_function, unicode_litera import os import sys -from kodi_six import xbmc, xbmcaddon +from kodi_six import xbmc, xbmcaddon, xbmcvfs ################################################################################################# +kodi_version = int(xbmc.getInfoLabel('System.BuildVersion')[:2]) __addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin') -__base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) +if kodi_version > 18: + __base__ = xbmcvfs.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) +else: + __base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) sys.path.insert(0, __base__) diff --git a/context_play.py b/context_play.py index 87d1638d..01513485 100644 --- a/context_play.py +++ b/context_play.py @@ -6,12 +6,16 @@ from __future__ import division, absolute_import, print_function, unicode_litera import os import sys -from kodi_six import xbmc, xbmcaddon +from kodi_six import xbmc, xbmcaddon, xbmcvfs ################################################################################################# +kodi_version = int(xbmc.getInfoLabel('System.BuildVersion')[:2]) __addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin') -__base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) +if kodi_version > 18: + __base__ = xbmcvfs.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) +else: + __base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) sys.path.insert(0, __base__) diff --git a/default.py b/default.py index 998ff512..06610631 100644 --- a/default.py +++ b/default.py @@ -6,12 +6,16 @@ from __future__ import division, absolute_import, print_function, unicode_litera import os import sys -from kodi_six import xbmc, xbmcaddon +from kodi_six import xbmc, xbmcaddon, xbmcvfs ################################################################################################# +kodi_version = int(xbmc.getInfoLabel('System.BuildVersion')[:2]) __addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin') -__base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) +if kodi_version > 18: + __base__ = xbmcvfs.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) +else: + __base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) sys.path.insert(0, __base__) diff --git a/service.py b/service.py index 4d0fb7b7..c0f47b84 100644 --- a/service.py +++ b/service.py @@ -7,12 +7,16 @@ import os import threading import sys -from kodi_six import xbmc, xbmcaddon +from kodi_six import xbmc, xbmcaddon, xbmcvfs ################################################################################################# +kodi_version = int(xbmc.getInfoLabel('System.BuildVersion')[:2]) __addon__ = xbmcaddon.Addon(id='plugin.video.jellyfin') -__base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) +if kodi_version > 18: + __base__ = xbmcvfs.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) +else: + __base__ = xbmc.translatePath(os.path.join(__addon__.getAddonInfo('path'), 'jellyfin_kodi')) sys.path.insert(0, __base__)