Merge pull request #25959 from neo1973/TagLib_deprecation_warnings
[xbmc.git] / addons / metadata.tvshows.themoviedb.org.python / libs / utils.py
bloba9dbfbbb1c25d070deda4f9f2a21b6152c597869
1 # -*- coding: UTF-8 -*-
3 # Copyright (C) 2020, Team Kodi
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # pylint: disable=missing-docstring
19 """Misc utils"""
21 from __future__ import absolute_import, unicode_literals
23 import xbmc
24 from xbmcaddon import Addon
26 try:
27 from typing import Text, Optional, Any, Dict # pylint: disable=unused-import
28 except ImportError:
29 pass
31 ADDON_ID = 'metadata.tvshows.themoviedb.org.python'
32 ADDON = Addon()
35 class logger:
36 log_message_prefix = '[{} ({})]: '.format(
37 ADDON_ID, ADDON.getAddonInfo('version'))
39 @staticmethod
40 def log(message, level=xbmc.LOGDEBUG):
41 # type: (Text, int) -> None
42 if isinstance(message, bytes):
43 message = message.decode('utf-8')
44 message = logger.log_message_prefix + message
45 xbmc.log(message, level)
47 @staticmethod
48 def info(message):
49 # type: (Text) -> None
50 logger.log(message, xbmc.LOGINFO)
52 @staticmethod
53 def error(message):
54 # type: (Text) -> None
55 logger.log(message, xbmc.LOGERROR)
57 @staticmethod
58 def debug(message):
59 # type: (Text) -> None
60 logger.log(message, xbmc.LOGDEBUG)
63 def safe_get(dct, key, default=None):
64 # type: (Dict[Text, Any], Text, Any) -> Any
65 """
66 Get a key from dict
68 Returns the respective value or default if key is missing or the value is None.
69 """
70 if key in dct and dct[key] is not None:
71 return dct[key]
72 return default