Skip to content

Commit

Permalink
move some methods out to tmdbhelper common module
Browse files Browse the repository at this point in the history
  • Loading branch information
jurialmunkey committed Aug 21, 2022
1 parent 5235d06 commit 98031b8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 120 deletions.
5 changes: 3 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="script.skinvariables"
version="1.0.5"
version="1.0.7"
name="Skin Variables"
provider-name="jurialmunkey">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="xbmc.python" version="3.0.0" />
<import addon="script.module.tmdbhelper" version="0.0.2" />
</requires>
<extension point="xbmc.python.script" library="script.py" />
<extension point="xbmc.python.pluginsource" library="plugin.py" />
Expand Down
50 changes: 0 additions & 50 deletions resources/lib/fileutils.py

This file was deleted.

73 changes: 11 additions & 62 deletions resources/lib/kodiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,23 @@
# Module: default
# Author: jurialmunkey
# License: GPL v.3 https://www.gnu.org/copyleft/gpl.html
import xbmc
import xbmcgui
import xbmcaddon
import tmdbhelper.logger as tmdbhelper_logger
import tmdbhelper.plugin as tmdbhelper_plugin
from contextlib import contextmanager
from urllib.parse import unquote_plus


ADDON = xbmcaddon.Addon('script.skinvariables')
ADDONLOGNAME = '[script.skinvariables]\n'
KODIPLUGIN = tmdbhelper_plugin.KodiPlugin('script.skinvariables')
ADDON = KODIPLUGIN._addon
get_localized = KODIPLUGIN.get_localized


def kodi_log(value, level=0):
try:
if isinstance(value, list):
value = ''.join(map(str, value))
if isinstance(value, bytes):
value = value.decode('utf-8')
logvalue = u'{0}{1}'.format(ADDONLOGNAME, value)
if level == 1:
xbmc.log(logvalue, level=xbmc.LOGINFO)
else:
xbmc.log(logvalue, level=xbmc.LOGDEBUG)
except Exception as exc:
xbmc.log(u'Logging Error: {}'.format(exc), level=xbmc.LOGINFO)


def parse_paramstring(paramstring):
""" helper to assist to standardise urllib parsing """
params = dict()
paramstring = paramstring.replace('&amp;', '&') # Just in case xml string
for param in paramstring.split('&'):
if '=' not in param:
continue
k, v = param.split('=')
params[unquote_plus(k)] = unquote_plus(v)
return params


def try_int(string, base=None, fallback=0):
'''helper to parse int from string without erroring on empty or misformed string'''
try:
return int(string, base) if base else int(string)
except Exception:
return fallback
LOGGER = tmdbhelper_logger.Logger(
log_name='[script.skinvariables]\n',
notification_head=f'SkinVariables {get_localized(257)}',
notification_text=get_localized(2104),
debug_logging=False)
kodi_log = LOGGER.kodi_log


@contextmanager
Expand All @@ -55,27 +28,3 @@ def isactive_winprop(name, value='True', windowid=10000):
yield
finally:
xbmcgui.Window(windowid).clearProperty(name)


def del_empty_keys(d, values=[]):
my_dict = d.copy()
for k, v in d.items():
if not v or v in values:
del my_dict[k]
return my_dict


def merge_dicts(org, upd, skipempty=False):
source = org.copy()
for k, v in upd.items():
if not k:
continue
if skipempty and not v:
continue
if isinstance(v, dict):
if not isinstance(source.get(k), dict):
source[k] = {}
source[k] = merge_dicts(source.get(k), v, skipempty=skipempty)
continue
source[k] = v
return source
2 changes: 1 addition & 1 deletion resources/lib/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import xbmc
import time
from resources.lib.jsonrpc import get_jsonrpc
from resources.lib.kodiutils import try_int
from tmdbhelper.parser import try_int


def set_player_subtitle(set_player_subtitle, reload_property='UID', **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License: GPL v.3 https://www.gnu.org/copyleft/gpl.html
import sys
import xbmcplugin
from resources.lib.kodiutils import parse_paramstring
from tmdbhelper.parser import parse_paramstring
from resources.lib.jsonrpc import get_player_streams
from resources.lib.method import set_player_subtitle, set_player_audiostream

Expand Down
4 changes: 2 additions & 2 deletions resources/lib/skinvariables.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import xbmcaddon
from json import loads, dumps
import xml.etree.ElementTree as ET
from resources.lib.kodiutils import try_int, del_empty_keys
from tmdbhelper.parser import try_int, del_empty_keys
from resources.lib.xmlhelper import make_xml_includes, get_skinfolders
from resources.lib.fileutils import load_filecontent, write_skinfile, make_hash
from tmdbhelper.futils import load_filecontent, write_skinfile, make_hash

ADDON = xbmcaddon.Addon()

Expand Down
5 changes: 3 additions & 2 deletions resources/lib/viewtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import xbmcvfs
import xbmcaddon
from json import loads, dumps
from tmdbhelper.parser import try_int, merge_dicts
from tmdbhelper.futils import check_hash, make_hash, write_skinfile, write_file, load_filecontent
from resources.lib.jsonrpc import get_jsonrpc
from resources.lib.kodiutils import merge_dicts, try_int, isactive_winprop
from resources.lib.kodiutils import isactive_winprop
from resources.lib.xmlhelper import make_xml_includes, get_skinfolders
from resources.lib.fileutils import check_hash, make_hash, write_skinfile, write_file, load_filecontent


ADDON = xbmcaddon.Addon()
Expand Down

0 comments on commit 98031b8

Please sign in to comment.