forked from Codekloeppler/kodi-gamepass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add kodiutils and kodilogging from generator-kodi-addon project
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -467,6 +467,21 @@ License: CC BY-NC 2.0 | |
You. This License may not be modified without the mutual written agreement of | ||
the Licensor and You. | ||
|
||
Files: resources/lib/kodiutils.py, resources/lib/kodilogging.py | ||
Copyright 2016 Kolja Lampe <[email protected]> | ||
License: Apache License, Version 2 | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
. | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
. | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
Files: resources/lib/pigskin/pigskin.py | ||
Copyright: 2012-2018, see git log for respective authors | ||
License: MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
from resources.lib.kodiutils import get_setting_as_bool | ||
|
||
import logging | ||
import xbmc | ||
import xbmcaddon | ||
|
||
|
||
class KodiLogHandler(logging.StreamHandler): | ||
|
||
def __init__(self): | ||
logging.StreamHandler.__init__(self) | ||
addon_id = xbmcaddon.Addon().getAddonInfo('id') | ||
prefix = b"[%s] " % addon_id | ||
formatter = logging.Formatter(prefix + b'%(name)s: %(message)s') | ||
self.setFormatter(formatter) | ||
|
||
def emit(self, record): | ||
levels = { | ||
logging.CRITICAL: xbmc.LOGFATAL, | ||
logging.ERROR: xbmc.LOGERROR, | ||
logging.WARNING: xbmc.LOGWARNING, | ||
logging.INFO: xbmc.LOGINFO, | ||
logging.DEBUG: xbmc.LOGDEBUG, | ||
logging.NOTSET: xbmc.LOGNONE, | ||
} | ||
if get_setting_as_bool('debug'): | ||
try: | ||
xbmc.log(self.format(record), levels[record.levelno]) | ||
except UnicodeEncodeError: | ||
xbmc.log(self.format(record).encode( | ||
'utf-8', 'ignore'), levels[record.levelno]) | ||
|
||
def flush(self): | ||
pass | ||
|
||
|
||
def config(): | ||
logger = logging.getLogger() | ||
logger.addHandler(KodiLogHandler()) | ||
logger.setLevel(logging.DEBUG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import xbmc | ||
import xbmcaddon | ||
import xbmcgui | ||
import sys | ||
import logging | ||
import json as json | ||
|
||
# read settings | ||
ADDON = xbmcaddon.Addon() | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def notification(header, message, time=5000, icon=ADDON.getAddonInfo('icon'), sound=True): | ||
xbmcgui.Dialog().notification(header, message, icon, time, sound) | ||
|
||
|
||
def show_settings(): | ||
ADDON.openSettings() | ||
|
||
|
||
def get_setting(setting): | ||
return ADDON.getSetting(setting).strip().decode('utf-8') | ||
|
||
|
||
def set_setting(setting, value): | ||
ADDON.setSetting(setting, str(value)) | ||
|
||
|
||
def get_setting_as_bool(setting): | ||
return get_setting(setting).lower() == "true" | ||
|
||
|
||
def get_setting_as_float(setting): | ||
try: | ||
return float(get_setting(setting)) | ||
except ValueError: | ||
return 0 | ||
|
||
|
||
def get_setting_as_int(setting): | ||
try: | ||
return int(get_setting_as_float(setting)) | ||
except ValueError: | ||
return 0 | ||
|
||
|
||
def get_string(string_id): | ||
return ADDON.getLocalizedString(string_id).encode('utf-8', 'ignore') | ||
|
||
|
||
def kodi_json_request(params): | ||
data = json.dumps(params) | ||
request = xbmc.executeJSONRPC(data) | ||
|
||
try: | ||
response = json.loads(request) | ||
except UnicodeDecodeError: | ||
response = json.loads(request.decode('utf-8', 'ignore')) | ||
|
||
try: | ||
if 'result' in response: | ||
return response['result'] | ||
return None | ||
except KeyError: | ||
logger.warn("[%s] %s" % | ||
(params['method'], response['error']['message'])) | ||
return None |