# Path: lib/libs/mediatypes.py
# TVSHOW = 'tvshow'
# MOVIE = 'movie'
# EPISODE = 'episode'
# SEASON = 'season'
# MOVIESET = 'set'
# MUSICVIDEO = 'musicvideo'
# ARTIST = 'artist'
# ALBUM = 'album'
# SONG = 'song'
# PREFERRED_SOURCE_SHARED = {'0': None, '1': 'fanart.tv'}
# PREFERRED_SOURCE_MEDIA = {'tvshows': ('thetvdb.com', (TVSHOW, SEASON, EPISODE)),
#     'movies': ('themoviedb.org', (MOVIE, MOVIESET)),
#     'music': ('theaudiodb.com', audiotypes),
#     'musicvideos': ('theaudiodb.com', (MUSICVIDEO,))}
# def get_artinfo(mediatype, arttype):
# def hack_mediaarttype(mediatype, arttype):
# def disabled(mediatype):
# def iter_every_arttype(mediatype):
# def downloadartwork(mediatype, arttype):
# def downloadanyartwork(mediatype):
# def _split_arttype(arttype):
# def generatethumb(mediatype):
# def haspreferred_source(mediatype):
# def ispreferred_source(mediatype, provider):
# def only_filesystem(mediatype):
# def update_settings():
# def _get_autolimit_from_setting(settingid):
# def _set_allmulti(always_multi):
# 
# 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
# ADDONID = 'script.artwork.beef'
# def get_main_addon():
# def is_addon_watched():
# def get_kodi_version():
# def localize(messageid):
# def get_conditional(conditional):
# def get_infolabel(infolabel):
# def execute_builtin(builtin_command):
# def datetime_now():
# def datetime_strptime(date_string, format_string):
# def execute_jsonrpc(jsonrpc_command):
# def log(message, level=xbmc.LOGDEBUG, tag=None):
# def scrub_message(message):
# def set_log_scrubstring(key, string):
# def get_language(language_format=xbmc.ENGLISH_NAME, region=False):
# def unquoteimage(imagestring):
# def quoteimage(imagestring):
# def unquotearchive(filepath):
# def get_command(*first_arg_keys):
# def get_busydialog():
#     def __init__(self, *args, **kwargs):
#     def get_setting(self, settingid):
#     def set_setting(self, settingid, value):
#     def __init__(self, *args, **kwargs):
#     def default(self, obj):
#     def __init__(self, *args, **kwargs):
#     def iterencode(self, obj, _one_shot=False):
#     def raw_decode(self, s, idx=0):
#     def _json_unicode_to_str(self, jsoninput):
#     def __init__(self):
#     def create(self):
#     def close(self):
#     def __del__(self):
# class Addon(xbmcaddon.Addon):
# class ObjectJSONEncoder(json.JSONEncoder):
# class UTF8PrettyJSONEncoder(ObjectJSONEncoder):
# class UTF8JSONDecoder(json.JSONDecoder):
# class DialogBusy(object):
# 
# 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/providers/base.py
# CANT_CONTACT_PROVIDER = 32034
# HTTP_ERROR = 32035
# class AbstractProvider(object):
# class AbstractImageProvider(AbstractProvider):
# class ProviderError(Exception):
#     def __init__(self):
#     def doget(self, url, **kwargs):
#     def log(self, message, level=xbmc.LOGDEBUG):
#     def login(self):
# def build_key_error(provider):
#     def get_images(self, uniqueids, types=None):
#     def __init__(self, message, cause=None):


import xbmc
from abc import ABCMeta
from lib.libs import mediatypes
from lib.libs.addonsettings import settings
from lib.libs.pykodi import json, UTF8JSONDecoder
from lib.libs.utils import SortedDisplay
from lib.providers.base import AbstractProvider, AbstractImageProvider, cache, build_key_error


cfgurl = 'https://api.themoviedb.org/3/configuration'

class TheMovieDBAbstractProvider(AbstractImageProvider):
    __metaclass__ = ABCMeta
    contenttype = 'application/json'

    name = SortedDisplay('themoviedb.org', 'The Movie Database')
    _baseurl = None
    artmap = {}

    @property
    def baseurl(self):
        if not self._baseurl:
            apikey = settings.get_apikey('tmdb')
            if not apikey:
                raise build_key_error('tmdb')
            response = self.doget(cfgurl, params={'api_key': apikey})
            if response is None:
                return

# Path: lib/libs/mediatypes.py
# TVSHOW = 'tvshow'
# MOVIE = 'movie'
# EPISODE = 'episode'
# SEASON = 'season'
# MOVIESET = 'set'
# MUSICVIDEO = 'musicvideo'
# ARTIST = 'artist'
# ALBUM = 'album'
# SONG = 'song'
# PREFERRED_SOURCE_SHARED = {'0': None, '1': 'fanart.tv'}
# PREFERRED_SOURCE_MEDIA = {'tvshows': ('thetvdb.com', (TVSHOW, SEASON, EPISODE)),
#     'movies': ('themoviedb.org', (MOVIE, MOVIESET)),
#     'music': ('theaudiodb.com', audiotypes),
#     'musicvideos': ('theaudiodb.com', (MUSICVIDEO,))}
# def get_artinfo(mediatype, arttype):
# def hack_mediaarttype(mediatype, arttype):
# def disabled(mediatype):
# def iter_every_arttype(mediatype):
# def downloadartwork(mediatype, arttype):
# def downloadanyartwork(mediatype):
# def _split_arttype(arttype):
# def generatethumb(mediatype):
# def haspreferred_source(mediatype):
# def ispreferred_source(mediatype, provider):
# def only_filesystem(mediatype):
# def update_settings():
# def _get_autolimit_from_setting(settingid):
# def _set_allmulti(always_multi):
# 
# 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
# ADDONID = 'script.artwork.beef'
# def get_main_addon():
# def is_addon_watched():
# def get_kodi_version():
# def localize(messageid):
# def get_conditional(conditional):
# def get_infolabel(infolabel):
# def execute_builtin(builtin_command):
# def datetime_now():
# def datetime_strptime(date_string, format_string):
# def execute_jsonrpc(jsonrpc_command):
# def log(message, level=xbmc.LOGDEBUG, tag=None):
# def scrub_message(message):
# def set_log_scrubstring(key, string):
# def get_language(language_format=xbmc.ENGLISH_NAME, region=False):
# def unquoteimage(imagestring):
# def quoteimage(imagestring):
# def unquotearchive(filepath):
# def get_command(*first_arg_keys):
# def get_busydialog():
#     def __init__(self, *args, **kwargs):
#     def get_setting(self, settingid):
#     def set_setting(self, settingid, value):
#     def __init__(self, *args, **kwargs):
#     def default(self, obj):
#     def __init__(self, *args, **kwargs):
#     def iterencode(self, obj, _one_shot=False):
#     def raw_decode(self, s, idx=0):
#     def _json_unicode_to_str(self, jsoninput):
#     def __init__(self):
#     def create(self):
#     def close(self):
#     def __del__(self):
# class Addon(xbmcaddon.Addon):
# class ObjectJSONEncoder(json.JSONEncoder):
# class UTF8PrettyJSONEncoder(ObjectJSONEncoder):
# class UTF8JSONDecoder(json.JSONDecoder):
# class DialogBusy(object):
# 
# 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/providers/base.py
# CANT_CONTACT_PROVIDER = 32034
# HTTP_ERROR = 32035
# class AbstractProvider(object):
# class AbstractImageProvider(AbstractProvider):
# class ProviderError(Exception):
#     def __init__(self):
#     def doget(self, url, **kwargs):
#     def log(self, message, level=xbmc.LOGDEBUG):
#     def login(self):
# def build_key_error(provider):
#     def get_images(self, uniqueids, types=None):
#     def __init__(self, message, cause=None):


# Path: lib/providers/themoviedb.py
import xbmc
from abc import ABCMeta
from lib.libs import mediatypes
from lib.libs.addonsettings import settings
from lib.libs.pykodi import json, UTF8JSONDecoder
from lib.libs.utils import SortedDisplay
from lib.providers.base import AbstractProvider, AbstractImageProvider, cache, build_key_error



cfgurl = 'https://api.themoviedb.org/3/configuration'

class TheMovieDBAbstractProvider(AbstractImageProvider):
    __metaclass__ = ABCMeta
    contenttype = 'application/json'

    name = SortedDisplay('themoviedb.org', 'The Movie Database')
    _baseurl = None
    artmap = {}

    @property
    def baseurl(self):
        if not self._baseurl:
            apikey = settings.get_apikey('tmdb')
            if not apikey:
                raise build_key_error('tmdb')
            response = self.doget(cfgurl, params={'api_key': apikey})
            if response is None:
                return

            self._baseurl = response.json()['images']['secure_base_url']