diff --git a/default.py b/default.py index 8396435..0ba9c25 100644 --- a/default.py +++ b/default.py @@ -2,7 +2,7 @@ import xbmcaddon -from resources.lib.loghandler import LazyLogger +from resources.lib.lazylogger import LazyLogger from resources.lib.functions import main_entry_point from resources.lib.tracking import set_timing_enabled diff --git a/resources/lib/action_menu.py b/resources/lib/action_menu.py index 19f6c0f..df1bb3d 100644 --- a/resources/lib/action_menu.py +++ b/resources/lib/action_menu.py @@ -7,7 +7,7 @@ import threading import xbmc import xbmcgui -from .loghandler import LazyLogger +from .lazylogger import LazyLogger log = LazyLogger(__name__) diff --git a/resources/lib/cache_images.py b/resources/lib/cache_images.py index 6f71508..aff6cf2 100644 --- a/resources/lib/cache_images.py +++ b/resources/lib/cache_images.py @@ -15,7 +15,7 @@ import xbmc import xbmcaddon from .jellyfin import api -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .jsonrpc import JsonRpc, get_value from .utils import translate_string, load_user_details from .kodi_utils import HomeWindow diff --git a/resources/lib/datamanager.py b/resources/lib/datamanager.py index d55b3df..46ac41b 100644 --- a/resources/lib/datamanager.py +++ b/resources/lib/datamanager.py @@ -8,12 +8,12 @@ import time from six.moves import cPickle from .jellyfin import api -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .item_functions import extract_item_info from .kodi_utils import HomeWindow from .tracking import timer from .filelock import FileLock -from .utils import translate_string, load_user_details +from .utils import translate_string, load_user_details, translate_path import xbmc import xbmcaddon @@ -39,7 +39,7 @@ class CacheItem: class DataManager: - addon_dir = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')) + addon_dir = translate_path(xbmcaddon.Addon().getAddonInfo('profile')) def __init__(self, *args): self.user_details = load_user_details() @@ -253,7 +253,7 @@ class CacheManagerThread(threading.Thread): def clear_cached_server_data(): log.debug("clear_cached_server_data() called") - addon_dir = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')) + addon_dir = translate_path(xbmcaddon.Addon().getAddonInfo('profile')) dirs, files = xbmcvfs.listdir(addon_dir) del_count = 0 @@ -271,7 +271,7 @@ def clear_cached_server_data(): def clear_old_cache_data(): log.debug("clear_old_cache_data() : called") - addon_dir = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')) + addon_dir = translate_path(xbmcaddon.Addon().getAddonInfo('profile')) dirs, files = xbmcvfs.listdir(addon_dir) del_count = 0 diff --git a/resources/lib/dialogs.py b/resources/lib/dialogs.py index 859b99c..6c7eae0 100644 --- a/resources/lib/dialogs.py +++ b/resources/lib/dialogs.py @@ -2,7 +2,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera import xbmcgui -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .utils import translate_string, send_event_notification log = LazyLogger(__name__) diff --git a/resources/lib/dir_functions.py b/resources/lib/dir_functions.py index f36e48e..dd0ffec 100644 --- a/resources/lib/dir_functions.py +++ b/resources/lib/dir_functions.py @@ -10,7 +10,7 @@ import sys import re from .datamanager import DataManager -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .item_functions import add_gui_item, ItemDetails from .utils import send_event_notification, translate_string, load_user_details, get_default_filters from .tracking import timer diff --git a/resources/lib/functions.py b/resources/lib/functions.py index 4db8a8b..f0b7ea6 100644 --- a/resources/lib/functions.py +++ b/resources/lib/functions.py @@ -15,12 +15,12 @@ import xbmcaddon import xbmc from .jellyfin import api -from .utils import convert_size, translate_string, get_version, load_user_details, get_art_url, get_default_filters +from .utils import convert_size, translate_string, get_version, load_user_details, get_art_url, get_default_filters, translate_path from .item_functions import get_art from .kodi_utils import HomeWindow from .datamanager import clear_cached_server_data from .server_detect import check_server, check_connection_speed -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .menu_functions import display_main_menu, display_menu, show_movie_alpha_list, show_tvshow_alpha_list, show_genre_list, show_search, show_movie_pages from .server_sessions import show_server_sessions from .action_menu import ActionMenu @@ -34,9 +34,9 @@ from .skin_cloner import clone_default_skin from .play_utils import play_file __addon__ = xbmcaddon.Addon() -__addondir__ = xbmc.translatePath(__addon__.getAddonInfo('profile')) +__addondir__ = translate_path(__addon__.getAddonInfo('profile')) __cwd__ = __addon__.getAddonInfo('path') -PLUGINPATH = xbmc.translatePath(os.path.join(__cwd__)) +PLUGINPATH = translate_path(os.path.join(__cwd__)) log = LazyLogger(__name__) diff --git a/resources/lib/image_server.py b/resources/lib/image_server.py index 097b452..65c8959 100644 --- a/resources/lib/image_server.py +++ b/resources/lib/image_server.py @@ -15,8 +15,9 @@ import requests import io from .jellyfin import api -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .item_functions import get_art +from .utils import translate_path pil_loaded = False try: @@ -170,7 +171,7 @@ class HttpImageHandler(BaseHTTPRequestHandler): else: - image_path = xbmc.translatePath("special://home/addons/plugin.video.jellycon/icon.png").decode('utf-8') + image_path = translate_path("special://home/addons/plugin.video.jellycon/icon.png").decode('utf-8') self.send_response(200) self.send_header('Content-type', 'image/png') modified = xbmcvfs.Stat(image_path).st_mtime() diff --git a/resources/lib/item_functions.py b/resources/lib/item_functions.py index 0d815c7..f05b492 100644 --- a/resources/lib/item_functions.py +++ b/resources/lib/item_functions.py @@ -7,20 +7,15 @@ from six.moves.urllib.parse import quote from datetime import datetime import xbmc -import xbmcaddon import xbmcgui from .utils import datetime_from_string, get_art_url, image_url -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from six import ensure_text log = LazyLogger(__name__) kodi_version = int(xbmc.getInfoLabel('System.BuildVersion')[:2]) -addon_instance = xbmcaddon.Addon() -addon_path = addon_instance.getAddonInfo('path') -PLUGINPATH = xbmc.translatePath(os.path.join(addon_path)) - class ItemDetails: diff --git a/resources/lib/jellyfin.py b/resources/lib/jellyfin.py index 94178b9..680f8a8 100644 --- a/resources/lib/jellyfin.py +++ b/resources/lib/jellyfin.py @@ -6,7 +6,7 @@ from kodi_six.utils import py2_decode import requests from .utils import get_device_id, get_version, load_user_details -from .loghandler import LazyLogger +from .lazylogger import LazyLogger log = LazyLogger(__name__) diff --git a/resources/lib/kodi_utils.py b/resources/lib/kodi_utils.py index 299bddd..563f875 100644 --- a/resources/lib/kodi_utils.py +++ b/resources/lib/kodi_utils.py @@ -8,7 +8,7 @@ import xbmcaddon import sys import json -from .loghandler import LazyLogger +from .lazylogger import LazyLogger log = LazyLogger(__name__) addon = xbmcaddon.Addon() diff --git a/resources/lib/lazylogger.py b/resources/lib/lazylogger.py new file mode 100644 index 0000000..3b5c79d --- /dev/null +++ b/resources/lib/lazylogger.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import division, absolute_import, print_function, unicode_literals + + +class LazyLogger(object): + """`helper.loghandler.getLogger()` is used everywhere. + This class helps avoiding import errors. + """ + __logger = None + __logger_name = None + + def __init__(self, logger_name=None): + self.__logger_name = logger_name + + def __getattr__(self, name): + if self.__logger is None: + from .loghandler import getLogger + self.__logger = getLogger(self.__logger_name) + return getattr(self.__logger, name) \ No newline at end of file diff --git a/resources/lib/loghandler.py b/resources/lib/loghandler.py index 419d0a7..558ce9f 100644 --- a/resources/lib/loghandler.py +++ b/resources/lib/loghandler.py @@ -11,10 +11,12 @@ import traceback from six import ensure_text from kodi_six import xbmc, xbmcaddon +from .utils import translate_path + ################################################################################################## __addon__ = xbmcaddon.Addon(id='plugin.video.jellycon') -__pluginpath__ = xbmc.translatePath(__addon__.getAddonInfo('path')) +__pluginpath__ = translate_path(__addon__.getAddonInfo('path')) ################################################################################################## @@ -110,22 +112,6 @@ class MyFormatter(logging.Formatter): record.relpath = os.path.relpath(record.pathname, __pluginpath__) -class LazyLogger(object): - """`helper.loghandler.getLogger()` is used everywhere. - This class helps avoiding import errors. - """ - __logger = None - __logger_name = None - - def __init__(self, logger_name=None): - self.__logger_name = logger_name - - def __getattr__(self, name): - if self.__logger is None: - self.__logger = getLogger(self.__logger_name) - return getattr(self.__logger, name) - - def get_filesystem_encoding(): enc = sys.getfilesystemencoding() diff --git a/resources/lib/menu_functions.py b/resources/lib/menu_functions.py index 9c39088..9eea1bc 100644 --- a/resources/lib/menu_functions.py +++ b/resources/lib/menu_functions.py @@ -13,7 +13,7 @@ import xbmcaddon from .jellyfin import api from .kodi_utils import add_menu_directory_item, HomeWindow -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .utils import get_jellyfin_url, translate_string, get_art_url, get_default_filters from .item_functions import get_art diff --git a/resources/lib/monitors.py b/resources/lib/monitors.py index 20e8f80..61a1a5e 100644 --- a/resources/lib/monitors.py +++ b/resources/lib/monitors.py @@ -5,7 +5,7 @@ import time import xbmc from .functions import show_menu -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .widgets import check_for_new_content from .tracking import timer diff --git a/resources/lib/picture_viewer.py b/resources/lib/picture_viewer.py index 0ca9eb6..e62f15b 100644 --- a/resources/lib/picture_viewer.py +++ b/resources/lib/picture_viewer.py @@ -2,7 +2,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera import xbmcgui -from .loghandler import LazyLogger +from .lazylogger import LazyLogger log = LazyLogger(__name__) diff --git a/resources/lib/play_utils.py b/resources/lib/play_utils.py index 1c57faa..95396cd 100644 --- a/resources/lib/play_utils.py +++ b/resources/lib/play_utils.py @@ -13,9 +13,9 @@ import re from six.moves.urllib.parse import urlencode from .jellyfin import api -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .dialogs import ResumeDialog -from .utils import send_event_notification, convert_size, get_device_id, translate_string, load_user_details +from .utils import send_event_notification, convert_size, get_device_id, translate_string, load_user_details, translate_path from .kodi_utils import HomeWindow from .datamanager import clear_old_cache_data from .item_functions import extract_item_info, add_gui_item, get_art @@ -280,7 +280,7 @@ def play_file(play_info): play_url = "%s/Items/%s/Images/Primary" play_url = play_url % (server, item_id) - plugin_path = xbmc.translatePath(os.path.join(xbmcaddon.Addon().getAddonInfo('path'))) + plugin_path = translate_path(os.path.join(xbmcaddon.Addon().getAddonInfo('path'))) action_menu = PictureViewer("PictureViewer.xml", plugin_path, "default", "720p") action_menu.setPicture(play_url) action_menu.doModal() @@ -990,7 +990,7 @@ def prompt_for_stop_actions(item_id, data): if play_prompt: plugin_path = settings.getAddonInfo('path') - plugin_path_real = xbmc.translatePath(os.path.join(plugin_path)) + plugin_path_real = translate_path(os.path.join(plugin_path)) play_next_dialog = PlayNextDialog("PlayNextDialog.xml", plugin_path_real, "default", "720p") play_next_dialog.set_episode_info(next_episode) diff --git a/resources/lib/playnext.py b/resources/lib/playnext.py index e66b8c6..2edaa95 100644 --- a/resources/lib/playnext.py +++ b/resources/lib/playnext.py @@ -6,8 +6,9 @@ import threading import xbmc import xbmcaddon -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .dialogs import PlayNextDialog +from .utils import translate_path log = LazyLogger(__name__) @@ -69,7 +70,7 @@ class PlayNextService(threading.Thread): settings = xbmcaddon.Addon() plugin_path = settings.getAddonInfo('path') - plugin_path_real = xbmc.translatePath(os.path.join(plugin_path)) + plugin_path_real = translate_path(os.path.join(plugin_path)) play_next_dialog = PlayNextDialog("PlayNextDialog.xml", plugin_path_real, "default", "720p") play_next_dialog.set_episode_info(next_episode) diff --git a/resources/lib/server_detect.py b/resources/lib/server_detect.py index ffa2142..0952a50 100644 --- a/resources/lib/server_detect.py +++ b/resources/lib/server_detect.py @@ -12,7 +12,7 @@ import xbmc from .kodi_utils import HomeWindow from .jellyfin import API -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .utils import datetime_from_string, translate_string, save_user_details, load_user_details log = LazyLogger(__name__) diff --git a/resources/lib/server_sessions.py b/resources/lib/server_sessions.py index 220d369..8c76545 100644 --- a/resources/lib/server_sessions.py +++ b/resources/lib/server_sessions.py @@ -6,7 +6,7 @@ import xbmcplugin import xbmcaddon from .jellyfin import api -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .item_functions import get_art from .utils import load_user_details diff --git a/resources/lib/skin_cloner.py b/resources/lib/skin_cloner.py index 8f0d890..83897c7 100644 --- a/resources/lib/skin_cloner.py +++ b/resources/lib/skin_cloner.py @@ -9,7 +9,8 @@ import xbmcgui import xbmcvfs from .jsonrpc import JsonRpc, get_value, set_value -from .loghandler import LazyLogger +from .lazylogger import LazyLogger +from .utils import translate_path log = LazyLogger(__name__) ver = xbmc.getInfoLabel('System.BuildVersion')[:2] @@ -49,7 +50,7 @@ def walk_path(root_path, relative_path, all_files): def clone_skin(): log.debug("Cloning Estuary Skin") - kodi_path = xbmc.translatePath("special://xbmc") + kodi_path = translate_path("special://xbmc") kodi_skin_source = os.path.join(kodi_path, "addons", "skin.estuary") log.debug("Kodi Skin Source: {0}".format(kodi_skin_source)) @@ -61,7 +62,7 @@ def clone_skin(): for found in all_files: log.debug("Found Path: {0}".format(found)) - kodi_home_path = xbmc.translatePath("special://home") + kodi_home_path = translate_path("special://home") kodi_skin_destination = os.path.join(kodi_home_path, "addons", "skin.estuary_jellycon") log.debug("Kodi Skin Destination: {0}".format(kodi_skin_destination)) diff --git a/resources/lib/tracking.py b/resources/lib/tracking.py index ea0750c..a7d33ad 100644 --- a/resources/lib/tracking.py +++ b/resources/lib/tracking.py @@ -4,7 +4,7 @@ from __future__ import division, absolute_import, print_function, unicode_litera import sys import functools import time -from .loghandler import LazyLogger +from .lazylogger import LazyLogger log = LazyLogger(__name__) diff --git a/resources/lib/trakttokodi.py b/resources/lib/trakttokodi.py index e68e03c..f0df075 100644 --- a/resources/lib/trakttokodi.py +++ b/resources/lib/trakttokodi.py @@ -7,13 +7,13 @@ import xbmc import xbmcgui from .jellyfin import api -from .loghandler import LazyLogger -from .utils import translate_string +from .lazylogger import LazyLogger +from .utils import translate_string, translate_path log = LazyLogger(__name__) details_string = 'EpisodeCount,SeasonCount,Path,Etag,MediaStreams' -icon = xbmc.translatePath('special://home/addons/plugin.video.jellycon/icon.png') +icon = translate_path('special://home/addons/plugin.video.jellycon/icon.png') def not_found(content_string): diff --git a/resources/lib/utils.py b/resources/lib/utils.py index c05d0e5..86a5a79 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -5,6 +5,7 @@ import xbmcaddon import xbmc import xbmcvfs from kodi_six.utils import py2_encode, py2_decode +import sys import binascii import string @@ -20,7 +21,7 @@ from uuid import uuid4 from six import ensure_text, ensure_binary, text_type from six.moves.urllib.parse import urlencode -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .kodi_utils import HomeWindow # hack to get datetime strptime loaded @@ -29,6 +30,18 @@ throwaway = time.strptime('20110101', '%Y%m%d') log = LazyLogger(__name__) +def kodi_version(): + # Kodistubs returns empty string, causing Python 3 tests to choke on int() + # TODO: Make Kodistubs version configurable for testing purposes + if sys.version_info.major == 2: + default_versionstring = "18" + else: + default_versionstring = "19.1 (19.1.0) Git:20210509-85e05228b4" + + version_string = xbmc.getInfoLabel('System.BuildVersion') or default_versionstring + return int(version_string.split(' ', 1)[0].split('.', 1)[0]) + + def get_jellyfin_url(path, params): params["format"] = "json" url_params = urlencode(params) @@ -118,7 +131,7 @@ def get_device_id(): if client_id: return '{}-{}'.format(client_id, hashed_name) - jellyfin_guid_path = py2_decode(xbmc.translatePath("special://temp/jellycon_guid")) + jellyfin_guid_path = py2_decode(translate_path("special://temp/jellycon_guid")) log.debug("jellyfin_guid_path: {0}".format(jellyfin_guid_path)) guid = xbmcvfs.File(jellyfin_guid_path) client_id = guid.read() @@ -147,7 +160,7 @@ def get_version(): def save_user_details(user_name, user_id, token): settings = xbmcaddon.Addon() save_user_to_settings = settings.getSetting('save_user_to_settings') == 'true' - addon_data = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')) + addon_data = translate_path(xbmcaddon.Addon().getAddonInfo('profile')) # Save to a config file for reference later if desired if save_user_to_settings: @@ -184,7 +197,7 @@ def load_user_details(): user_name = settings.getSetting('username') #settings_user_name = settings.getSetting('username') save_user_to_settings = settings.getSetting('save_user_to_settings') == 'true' - addon_data = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile')) + addon_data = translate_path(xbmcaddon.Addon().getAddonInfo('profile')) if save_user_to_settings: try: @@ -315,3 +328,15 @@ def get_default_filters(): filer_list.append("Overview") return ','.join(filer_list) + + +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/resources/lib/websocket_client.py b/resources/lib/websocket_client.py index 7d2683e..5a936d9 100644 --- a/resources/lib/websocket_client.py +++ b/resources/lib/websocket_client.py @@ -14,7 +14,7 @@ import xbmcgui from .jellyfin import API from .functions import play_action -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .jsonrpc import JsonRpc from .kodi_utils import HomeWindow from .utils import get_device_id, load_user_details diff --git a/resources/lib/widgets.py b/resources/lib/widgets.py index 68013ec..c3ba80d 100644 --- a/resources/lib/widgets.py +++ b/resources/lib/widgets.py @@ -10,7 +10,7 @@ import time from .jellyfin import api from .utils import get_jellyfin_url, image_url, load_user_details, get_art_url, get_default_filters -from .loghandler import LazyLogger +from .lazylogger import LazyLogger from .kodi_utils import HomeWindow from .dir_functions import process_directory from .tracking import timer diff --git a/service.py b/service.py index 44af26c..2296065 100644 --- a/service.py +++ b/service.py @@ -8,7 +8,7 @@ import xbmc import xbmcaddon import xbmcgui -from resources.lib.loghandler import LazyLogger +from resources.lib.lazylogger import LazyLogger from resources.lib.play_utils import Service, PlaybackService, send_progress from resources.lib.kodi_utils import HomeWindow from resources.lib.widgets import set_background_image, set_random_movies