From 745d7fdcf7c502032120a8236ff2e184fcd59d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Thu, 27 Oct 2022 22:35:34 +0200 Subject: [PATCH 1/3] Add back verify_kodi_defaults from #426 Revert changes done in 144f71e71f9a966d8d437fc354360fadca7f48d7 --- jellyfin_kodi/entrypoint/service.py | 3 ++ jellyfin_kodi/helper/xmls.py | 64 ++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/jellyfin_kodi/entrypoint/service.py b/jellyfin_kodi/entrypoint/service.py index 7d5a3bf5..8c3b6aff 100644 --- a/jellyfin_kodi/entrypoint/service.py +++ b/jellyfin_kodi/entrypoint/service.py @@ -20,6 +20,7 @@ from .. import monitor from ..views import Views from ..helper import translate, window, settings, event, dialog, set_addon_mode, LazyLogger from ..helper.utils import JsonDebugPrinter, translate_path +from ..helper.xmls import verify_kodi_defaults from ..jellyfin import Jellyfin ################################################################################################# @@ -66,6 +67,8 @@ class Service(xbmc.Monitor): LOG.info("Using dynamic paths: %s", settings('useDirectPaths') == "0") LOG.info("Log Level: %s", self.settings['log_level']) + verify_kodi_defaults() + window('jellyfin.connected.bool', True) settings('groupedSets.bool', objects.utils.get_grouped_set()) xbmc.Monitor.__init__(self) diff --git a/jellyfin_kodi/helper/xmls.py b/jellyfin_kodi/helper/xmls.py index 907e142c..0c077afd 100644 --- a/jellyfin_kodi/helper/xmls.py +++ b/jellyfin_kodi/helper/xmls.py @@ -6,7 +6,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera import os import xml.etree.ElementTree as etree -from kodi_six import xbmc +from kodi_six import xbmc, xbmcvfs from .utils import translate_path from . import translate, dialog, settings, LazyLogger @@ -71,3 +71,65 @@ def advanced_settings(): xbmc.executebuiltin('RestartApp') return True + +def verify_kodi_defaults(): + ''' Make sure we have the kodi default folder in place. + ''' + + source_base_path = translate_path("special://xbmc/system/library/video") + dest_base_path = translate_path("special://profile/library/video") + + LOG.debug('XMLs source path: `%s`', source_base_path) + + if not os.path.exists(source_base_path): + return False + + # Make sure the files exist in the local profile. + # TODO: Investigate why this is needed. + # I would think Kodi pulls data from the default profile + # if we don't do this. + for source_path, dirs, files in os.walk(source_base_path): + relative_path = os.path.relpath(source_path, source_base_path) + dest_path = os.path.join(dest_base_path, relative_path) + + if not os.path.exists(dest_path): + os.mkdir(os.path.normpath(dest_path)) + + for file_name in files: + dest_file = os.path.join(dest_path, file_name) + copy = False + + if not os.path.exists(dest_file): + copy = True + elif os.path.splitext(file_name)[1].lower() == '.xml': + try: + etree.parse(dest_file) + except etree.ParseError: + LOG.warning("Unable to parse `{}`, recovering from default.".format(dest_file)) + copy = True + + if copy: + source_file = os.path.join(source_path, file_name) + LOG.debug("Copying `{}` -> `{}`".format(source_file, dest_file)) + xbmcvfs.copy(source_file, dest_file) + + # This code seems to enforce a fixed ordering. + # Is it really desirable to force this on users? + # The default (system wide) order is [10, 20, 30] in Kodi 19. + for index, node in enumerate(['movies', 'tvshows', 'musicvideos']): + file_name = os.path.join(dest_base_path, node, "index.xml") + + if xbmcvfs.exists(file_name): + try: + tree = etree.parse(file_name) + except etree.ParseError: + LOG.error("Unable to parse `{}`".format(file_name)) + LOG.exception("We ensured the file was OK above, something is wrong!") + + tree.getroot().set('order', str(17 + index)) + tree.write(file_name) + + playlist_path = translate_path("special://profile/playlists/video") + + if not xbmcvfs.exists(playlist_path): + xbmcvfs.mkdirs(playlist_path) From 26d30b7952ed7cc05022a9d502d6a0a02f83c8e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sat, 29 Oct 2022 12:05:57 +0200 Subject: [PATCH 2/3] Tweak logging --- jellyfin_kodi/helper/xmls.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jellyfin_kodi/helper/xmls.py b/jellyfin_kodi/helper/xmls.py index 0c077afd..b4215446 100644 --- a/jellyfin_kodi/helper/xmls.py +++ b/jellyfin_kodi/helper/xmls.py @@ -79,9 +79,8 @@ def verify_kodi_defaults(): source_base_path = translate_path("special://xbmc/system/library/video") dest_base_path = translate_path("special://profile/library/video") - LOG.debug('XMLs source path: `%s`', source_base_path) - if not os.path.exists(source_base_path): + LOG.error("XMLs source path `%s` not found.", source_base_path) return False # Make sure the files exist in the local profile. From a2c4b97c4535e569d27d968228b87017f63cf9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sat, 29 Oct 2022 17:09:03 +0200 Subject: [PATCH 3/3] Apply PR suggestions --- jellyfin_kodi/helper/xmls.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/jellyfin_kodi/helper/xmls.py b/jellyfin_kodi/helper/xmls.py index b4215446..0831514b 100644 --- a/jellyfin_kodi/helper/xmls.py +++ b/jellyfin_kodi/helper/xmls.py @@ -81,12 +81,9 @@ def verify_kodi_defaults(): if not os.path.exists(source_base_path): LOG.error("XMLs source path `%s` not found.", source_base_path) - return False + return # Make sure the files exist in the local profile. - # TODO: Investigate why this is needed. - # I would think Kodi pulls data from the default profile - # if we don't do this. for source_path, dirs, files in os.walk(source_base_path): relative_path = os.path.relpath(source_path, source_base_path) dest_path = os.path.join(dest_base_path, relative_path)