# Path: lib/libs/addonsettings.py
# DEFAULT_IMAGESIZE = '1'
# AVAILABLE_IMAGESIZES = {'0': (10000, 10000, 600), '1': (1920, 1080, 600), '2': (1280, 720, 480)}
# PROGRESS_DISPLAY_FULLPROGRESS = '0'
# PROGRESS_DISPLAY_WARNINGSERRORS = '1'
# PROGRESS_DISPLAY_NONE = '2' # Only add-on crashes
# EXCLUSION_PATH_TYPE_FOLDER = '0'
# EXCLUSION_PATH_TYPE_PREFIX = '1'
# EXCLUSION_PATH_TYPE_REGEX = '2'
# class Settings(object):
#     def __init__(self):
#     def update_useragent(self):
#     def update_settings(self):
#     def get_apikey(self, provider):
#     def get_apienabled(self, provider):
#     def get_api_config(self, provider):
#     def autoadd_episodes(self):
#     def autoadd_episodes(self, value):
# def get_projectkey(provider):
# 
# Path: lib/libs/pykodi.py
# def log(message, level=xbmc.LOGDEBUG, tag=None):
#     if is_addon_watched() and level < xbmc.LOGNOTICE:
#         # Messages from this add-on are being watched, elevate to NOTICE so Kodi logs it
#         level_tag = _log_level_tag_lookup[level] + ': ' if level in _log_level_tag_lookup else ''
#         level = xbmc.LOGNOTICE
#     else:
#         level_tag = ''
# 
#     if isinstance(message, (dict, list)) and len(message) > 300:
#         message = str(message)
#     elif isinstance(message, unicode):
#         message = message.encode('utf-8')
#     elif not isinstance(message, str):
#         message = json.dumps(message, cls=UTF8PrettyJSONEncoder)
# 
#     addontag = ADDONID if not tag else ADDONID + ':' + tag
#     file_message = '%s[%s] %s' % (level_tag, addontag, scrub_message(message))
#     xbmc.log(file_message, level)
# 
# def localize(messageid):
#     if isinstance(messageid, basestring):
#         result = messageid
#     elif messageid >= 32000 and messageid < 33000:
#         result = get_main_addon().getLocalizedString(messageid)
#     else:
#         result = xbmc.getLocalizedString(messageid)
#     return result.encode('utf-8') if isinstance(result, unicode) else result
# 
# Path: lib/libs/utils.py
# def natural_sort(string, split_regex=re.compile(r'([0-9]+)')):
# def get_pathsep(path):
# def parent_dir(path):
# def get_simpledict_updates(original, newdict):
# def get_movie_path_list(stackedpath):
# def path_component(string):
# def iter_possible_cleannames(originalname, uniqueslug=None):
# def build_cleanest_name(originalname, uniqueslug=None):
# 
# Path: lib/libs/webhelper.py
# class Getter(object):
#     def __init__(self, contenttype=None, login=lambda: False, session=None):
#         self.session = session or retryable_session()
#         self.login = login
#         if contenttype:
#             self.session.headers['Accept'] = contenttype
# 
#     def __call__(self, url, **kwargs):
#         try:
#             return self._inner_call(url, **kwargs)
#         except (Timeout, ConnectionError, RequestException) as ex:
#             message = ex.response.reason if getattr(ex, 'response', None) is not None else type(ex).__name__
#             raise GetterError(message, ex, not isinstance(ex, RequestException))
# 
#     def _inner_call(self, url, **kwargs):
#         if 'timeout' not in kwargs:
#             kwargs['timeout'] = 20
#         result = self.session.get(url, **kwargs)
#         if result is None:
#             return
#         if result.status_code == 401:
#             if self.login():
#                 result = self.session.get(url, **kwargs)
#                 if result is None:
#                     return
# 
#         if result.status_code == 404:
#             return
#         result.raise_for_status()
#         return result
# 
# class GetterError(Exception):
#     def __init__(self, message, cause, connection_error):
#         super(GetterError, self).__init__()
#         self.message = message
#         self.cause = cause
#         self.connection_error = connection_error
#         self.request = getattr(cause, 'request', None)
#         self.response = getattr(cause, 'response', None)


import StorageServer
import xbmc
from abc import ABCMeta, abstractmethod
from requests.packages import urllib3
from lib.libs.addonsettings import settings
from lib.libs.pykodi import log, localize as L
from lib.libs.utils import SortedDisplay
from lib.libs.webhelper import Getter, GetterError
HTTP_ERROR = 32035

urllib3.disable_warnings()

languages = ()

cache = StorageServer.StorageServer('script.artwork.beef', 72)
monitor = xbmc.Monitor()

# Result of `get_images` is dict of lists, keyed on art type
# {'url': URL, 'language': ISO alpha-2 code, 'rating': SortedDisplay, 'size': SortedDisplay, 'provider': self.name, 'preview': preview URL}
# 'title': optional image title
# 'subtype': optional image subtype, like disc dvd/bluray/3d, SortedDisplay
# language should be None if there is no title on the image

class AbstractProvider(object):
    __metaclass__ = ABCMeta

    name = SortedDisplay(0, '')
    mediatype = None
    contenttype = None

    def __init__(self):
        self.getter = Getter(self.contenttype, self.login)
        self.getter.session.headers['User-Agent'] = settings.useragent

    def doget(self, url, **kwargs):
        try:
            return self.getter(url, **kwargs)
        except GetterError as ex:

# Path: lib/libs/addonsettings.py
# DEFAULT_IMAGESIZE = '1'
# AVAILABLE_IMAGESIZES = {'0': (10000, 10000, 600), '1': (1920, 1080, 600), '2': (1280, 720, 480)}
# PROGRESS_DISPLAY_FULLPROGRESS = '0'
# PROGRESS_DISPLAY_WARNINGSERRORS = '1'
# PROGRESS_DISPLAY_NONE = '2' # Only add-on crashes
# EXCLUSION_PATH_TYPE_FOLDER = '0'
# EXCLUSION_PATH_TYPE_PREFIX = '1'
# EXCLUSION_PATH_TYPE_REGEX = '2'
# class Settings(object):
#     def __init__(self):
#     def update_useragent(self):
#     def update_settings(self):
#     def get_apikey(self, provider):
#     def get_apienabled(self, provider):
#     def get_api_config(self, provider):
#     def autoadd_episodes(self):
#     def autoadd_episodes(self, value):
# def get_projectkey(provider):
# 
# Path: lib/libs/pykodi.py
# def log(message, level=xbmc.LOGDEBUG, tag=None):
#     if is_addon_watched() and level < xbmc.LOGNOTICE:
#         # Messages from this add-on are being watched, elevate to NOTICE so Kodi logs it
#         level_tag = _log_level_tag_lookup[level] + ': ' if level in _log_level_tag_lookup else ''
#         level = xbmc.LOGNOTICE
#     else:
#         level_tag = ''
# 
#     if isinstance(message, (dict, list)) and len(message) > 300:
#         message = str(message)
#     elif isinstance(message, unicode):
#         message = message.encode('utf-8')
#     elif not isinstance(message, str):
#         message = json.dumps(message, cls=UTF8PrettyJSONEncoder)
# 
#     addontag = ADDONID if not tag else ADDONID + ':' + tag
#     file_message = '%s[%s] %s' % (level_tag, addontag, scrub_message(message))
#     xbmc.log(file_message, level)
# 
# def localize(messageid):
#     if isinstance(messageid, basestring):
#         result = messageid
#     elif messageid >= 32000 and messageid < 33000:
#         result = get_main_addon().getLocalizedString(messageid)
#     else:
#         result = xbmc.getLocalizedString(messageid)
#     return result.encode('utf-8') if isinstance(result, unicode) else result
# 
# Path: lib/libs/utils.py
# def natural_sort(string, split_regex=re.compile(r'([0-9]+)')):
# def get_pathsep(path):
# def parent_dir(path):
# def get_simpledict_updates(original, newdict):
# def get_movie_path_list(stackedpath):
# def path_component(string):
# def iter_possible_cleannames(originalname, uniqueslug=None):
# def build_cleanest_name(originalname, uniqueslug=None):
# 
# Path: lib/libs/webhelper.py
# class Getter(object):
#     def __init__(self, contenttype=None, login=lambda: False, session=None):
#         self.session = session or retryable_session()
#         self.login = login
#         if contenttype:
#             self.session.headers['Accept'] = contenttype
# 
#     def __call__(self, url, **kwargs):
#         try:
#             return self._inner_call(url, **kwargs)
#         except (Timeout, ConnectionError, RequestException) as ex:
#             message = ex.response.reason if getattr(ex, 'response', None) is not None else type(ex).__name__
#             raise GetterError(message, ex, not isinstance(ex, RequestException))
# 
#     def _inner_call(self, url, **kwargs):
#         if 'timeout' not in kwargs:
#             kwargs['timeout'] = 20
#         result = self.session.get(url, **kwargs)
#         if result is None:
#             return
#         if result.status_code == 401:
#             if self.login():
#                 result = self.session.get(url, **kwargs)
#                 if result is None:
#                     return
# 
#         if result.status_code == 404:
#             return
#         result.raise_for_status()
#         return result
# 
# class GetterError(Exception):
#     def __init__(self, message, cause, connection_error):
#         super(GetterError, self).__init__()
#         self.message = message
#         self.cause = cause
#         self.connection_error = connection_error
#         self.request = getattr(cause, 'request', None)
#         self.response = getattr(cause, 'response', None)


# Path: lib/providers/base.py
import StorageServer
import xbmc
from abc import ABCMeta, abstractmethod
from requests.packages import urllib3
from lib.libs.addonsettings import settings
from lib.libs.pykodi import log, localize as L
from lib.libs.utils import SortedDisplay
from lib.libs.webhelper import Getter, GetterError

HTTP_ERROR = 32035

urllib3.disable_warnings()

languages = ()

cache = StorageServer.StorageServer('script.artwork.beef', 72)
monitor = xbmc.Monitor()

# Result of `get_images` is dict of lists, keyed on art type
# {'url': URL, 'language': ISO alpha-2 code, 'rating': SortedDisplay, 'size': SortedDisplay, 'provider': self.name, 'preview': preview URL}
# 'title': optional image title
# 'subtype': optional image subtype, like disc dvd/bluray/3d, SortedDisplay
# language should be None if there is no title on the image

class AbstractProvider(object):
    __metaclass__ = ABCMeta

    name = SortedDisplay(0, '')
    mediatype = None
    contenttype = None

    def __init__(self):
        self.getter = Getter(self.contenttype, self.login)
        self.getter.session.headers['User-Agent'] = settings.useragent

    def doget(self, url, **kwargs):
        try:
            return self.getter(url, **kwargs)
        except GetterError as ex:

            message = L(CANT_CONTACT_PROVIDER) if ex.connection_error else L(HTTP_ERROR).format(ex.message)