Skip to content

Commit

Permalink
Add Python2 and Kodi 18 compatibility tweaks
Browse files Browse the repository at this point in the history
- Ensure new style classes are used
- Use correct inputstream property for listitems
- Use correct infolabel date formatting
- Use correct setting type getter/setter for str list
- Ignore labelmask parameter in sort methods
- Use traditional packages rather than namespace packages
  • Loading branch information
MoojMidge committed Dec 11, 2023
1 parent ef9ca69 commit f4d41db
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 22 deletions.
Empty file.
13 changes: 7 additions & 6 deletions resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import xbmcvfs

from ..abstract_context import AbstractContext
from ... import utils
from ...player.xbmc.xbmc_player import XbmcPlayer
from ...player.xbmc.xbmc_playlist import XbmcPlaylist
from ...settings.xbmc.xbmc_plugin_settings import XbmcPluginSettings
from ...ui.xbmc.xbmc_context_ui import XbmcContextUI
from ...utils import current_system_version, loose_version, to_unicode


class XbmcContext(AbstractContext):
Expand Down Expand Up @@ -403,16 +403,17 @@ def localize(self, text_id, default_text=''):
"""
source = self._addon if 30000 <= text_id < 31000 else xbmc
result = source.getLocalizedString(text_id)
result = utils.to_unicode(result) if result else default_text
result = to_unicode(result) if result else default_text
return result

def set_content_type(self, content_type):
self.log_debug('Setting content-type: "%s" for "%s"' % (content_type, self.get_path()))
xbmcplugin.setContent(self._plugin_handle, content_type)

def add_sort_method(self, *sort_methods):
args = slice(None if current_system_version.compatible(19, 0) else 2)
for sort_method in sort_methods:
xbmcplugin.addSortMethod(self._plugin_handle, *sort_method)
xbmcplugin.addSortMethod(self._plugin_handle, *sort_method[args])

def clone(self, new_path=None, new_params=None):
if not new_path:
Expand Down Expand Up @@ -524,16 +525,16 @@ def inputstream_adaptive_capabilities(self, capability=None):
if not self.use_inputstream_adaptive() or not inputstream_version:
return frozenset() if capability is None else None

isa_loose_version = utils.loose_version(inputstream_version)
isa_loose_version = loose_version(inputstream_version)
if capability is None:
capabilities = frozenset(
capability for capability, version in self._ISA_CAPABILITIES.items()
if version is True
or version and isa_loose_version >= utils.loose_version(version)
or version and isa_loose_version >= loose_version(version)
)
return capabilities
version = self._ISA_CAPABILITIES.get(capability)
return version is True or version and isa_loose_version >= utils.loose_version(version)
return version is True or version and isa_loose_version >= loose_version(version)

@staticmethod
def inputstream_adaptive_auto_stream_selection():
Expand Down
9 changes: 5 additions & 4 deletions resources/lib/youtube_plugin/kodion/network/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
import json
import os
import re
from socket import error as socket_error
from http import server as BaseHTTPServer
from io import open
from socket import error as socket_error
from textwrap import dedent
from urllib.parse import parse_qs, urlparse

from xbmc import getCondVisibility, executebuiltin
from xbmc import executebuiltin, getCondVisibility
from xbmcaddon import Addon
from xbmcgui import Dialog, Window
from xbmcvfs import translatePath
from xbmcaddon import Addon

from .requests import BaseRequestsClass
from ..logger import log_debug
Expand All @@ -32,7 +33,7 @@
_server_requests = BaseRequestsClass()


class YouTubeProxyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
class YouTubeProxyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler, object):
base_path = translatePath('special://temp/{0}'.format(_addon_id))
chunk_size = 1024 * 64
local_ranges = (
Expand Down
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, xbmc_addon):

if self._funcs:
return
if current_system_version.get_version() >= (20, 0):
if current_system_version.compatible(20, 0):
_class = xbmcaddon.Settings

self._funcs.update({
Expand All @@ -41,11 +41,11 @@ def __init__(self, xbmc_addon):
_class = xbmcaddon.Addon

def _get_string_list(store, setting):
return _class.getSettingString(store, setting).split(',')
return _class.getSetting(store, setting).split(',')

def _set_string_list(store, setting, value):
value = ','.join(value)
return _class.setSettingString(store, setting, value)
return _class.setSetting(store, setting, value)

self._funcs.update({
'get_bool': _class.getSettingBool,
Expand All @@ -62,7 +62,7 @@ def _set_string_list(store, setting, value):
def flush(cls, xbmc_addon):
cls._echo = get_kodi_setting('debug.showloginfo')
cls._cache = {}
if current_system_version.get_version() >= (20, 0):
if current_system_version.compatible(20, 0):
cls._store = xbmc_addon.getSettings()
else:
cls._store = xbmc_addon
Expand Down
Empty file.
8 changes: 5 additions & 3 deletions resources/lib/youtube_plugin/kodion/ui/xbmc/info_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
See LICENSES/GPL-2.0-only for more information.
"""

from ... import utils
from ...items import AudioItem, DirectoryItem, ImageItem, VideoItem
from ...utils import current_system_version, datetime_parser


def _process_date_value(info_labels, name, param):
Expand All @@ -19,7 +19,9 @@ def _process_date_value(info_labels, name, param):

def _process_datetime_value(info_labels, name, param):
if param:
info_labels[name] = param.isoformat('T')
info_labels[name] = (param.isoformat('T')
if current_system_version.compatible(19, 0) else
param.strftime('%d.%d.%Y'))


def _process_int_value(info_labels, name, param):
Expand Down Expand Up @@ -64,7 +66,7 @@ def _process_video_rating(info_labels, param):

def _process_date_string(info_labels, name, param):
if param:
date = utils.datetime_parser.parse(param)
date = datetime_parser.parse(param)
info_labels[name] = date.isoformat()


Expand Down
11 changes: 6 additions & 5 deletions resources/lib/youtube_plugin/kodion/ui/xbmc/xbmc_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from . import info_labels
from ...items import AudioItem, UriItem, VideoItem
from ...utils import datetime_parser
from ...utils import current_system_version, datetime_parser


try:
Expand All @@ -34,10 +34,8 @@ def add_stream_info(self, *args, **kwargs):

def set_resume_point(self,
infoproperties,
*_args,
resume_key='ResumeTime',
total_key='TotalTime',
**_kwargs):
total_key='TotalTime',):
if resume_key in infoproperties:
infoproperties[resume_key] = str(infoproperties[resume_key])
if total_key in infoproperties:
Expand Down Expand Up @@ -95,7 +93,10 @@ def video_playback_item(context, video_item):
manifest_type = 'hls'
mime_type = 'application/x-mpegURL'

props['inputstream'] = 'inputstream.adaptive'
inputstream_property = ('inputstream'
if current_system_version.compatible(19, 0) else
'inputstreamaddon')
props[inputstream_property] = 'inputstream.adaptive'
props['inputstream.adaptive.manifest_type'] = manifest_type

if headers:
Expand Down
3 changes: 3 additions & 0 deletions resources/lib/youtube_plugin/kodion/utils/system_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,8 @@ def get_version(self):
def get_app_name(self):
return self._appname

def compatible(self, *version):
return self._version >= version


current_system_version = SystemVersion()

0 comments on commit f4d41db

Please sign in to comment.