# 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/mediainfo.py
# def arttype_matches_base(arttype, basetype):
#     return re.match(r'{0}\d*$'.format(basetype), arttype)
# 
# def format_arttype(basetype, index):
#     return "{0}{1}".format(basetype, index if index else '')
# 
# def find_central_infodir(mediaitem):
#     fromtv = mediaitem.mediatype in (mediatypes.SEASON, mediatypes.EPISODE)
#     fromartist = mediaitem.mediatype in mediatypes.audiotypes
#     fromalbum = mediaitem.mediatype in (mediatypes.ALBUM, mediatypes.SONG)
#     cdtype = mediatypes.TVSHOW if fromtv else mediatypes.ARTIST if fromartist else mediaitem.mediatype
#     basedir = mediatypes.central_directories.get(cdtype)
#     if not basedir:
#         return None
#     slug1 = _get_uniqueslug(mediaitem, mediatypes.ARTIST) if fromartist else None
#     slug2 = _get_uniqueslug(mediaitem, mediatypes.ALBUM) if fromalbum else None
#     title1 = mediaitem.showtitle if fromtv \
#         else mediaitem.artist if fromartist else mediaitem.label
#     title2 = mediaitem.album if fromalbum \
#         else mediaitem.label if mediaitem.mediatype == mediatypes.EPISODE \
#         else None
#     title3 = mediaitem.label if mediaitem.mediatype == mediatypes.SONG else None
#     sep = utils.get_pathsep(basedir)
#     mediayear = mediaitem.year if mediaitem.mediatype == mediatypes.MOVIE else None
# 
#     single_dir = mediaitem.mediatype == mediatypes.MOVIESET and not settings.setartwork_subdirs
#     thisdir = _find_existing(basedir, title1, slug1, mediayear, single_dir)
#     if not thisdir:
#         if mediaitem.mediatype == mediatypes.MOVIE:
#             title1 = '{0} ({1})'.format(mediaitem.label, mediaitem.year)
#         thisdir = utils.build_cleanest_name(title1, slug1)
#     result = basedir + thisdir
#     if not single_dir:
#         result += sep
#     if not title2:
#         return result
#     usefiles = mediaitem.mediatype == mediatypes.EPISODE
#     thisdir = _find_existing(result, title2, slug2, files=usefiles)
#     if not thisdir:
#         thisdir = utils.build_cleanest_name(title2, slug2)
#     result += thisdir
#     if not usefiles:
#         result += sep
#     if not title3:
#         return result
#     final = _find_existing(result, title3, files=True)
#     if not final:
#         final = utils.build_cleanest_name(title3)
#     result += final
#     return 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):


import os
import xbmcvfs
from abc import ABCMeta
from lib.libs import mediatypes
from lib.libs.addonsettings import settings
from lib.libs.mediainfo import arttype_matches_base, format_arttype, find_central_infodir
from lib.libs.utils import SortedDisplay, natural_sort, get_movie_path_list, get_pathsep, \
    iter_possible_cleannames, parent_dir


ARTWORK_EXTS = ('.jpg', '.png', '.gif')
ARTIST_INFOFOLDER_PROVIDER = SortedDisplay('file:art', 20223)

ARTTYPE_MAXLENGTH = 30

class ArtFilesAbstractProvider(object):
    __metaclass__ = ABCMeta
    # 13514 = Local art

# 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/mediainfo.py
# def arttype_matches_base(arttype, basetype):
#     return re.match(r'{0}\d*$'.format(basetype), arttype)
# 
# def format_arttype(basetype, index):
#     return "{0}{1}".format(basetype, index if index else '')
# 
# def find_central_infodir(mediaitem):
#     fromtv = mediaitem.mediatype in (mediatypes.SEASON, mediatypes.EPISODE)
#     fromartist = mediaitem.mediatype in mediatypes.audiotypes
#     fromalbum = mediaitem.mediatype in (mediatypes.ALBUM, mediatypes.SONG)
#     cdtype = mediatypes.TVSHOW if fromtv else mediatypes.ARTIST if fromartist else mediaitem.mediatype
#     basedir = mediatypes.central_directories.get(cdtype)
#     if not basedir:
#         return None
#     slug1 = _get_uniqueslug(mediaitem, mediatypes.ARTIST) if fromartist else None
#     slug2 = _get_uniqueslug(mediaitem, mediatypes.ALBUM) if fromalbum else None
#     title1 = mediaitem.showtitle if fromtv \
#         else mediaitem.artist if fromartist else mediaitem.label
#     title2 = mediaitem.album if fromalbum \
#         else mediaitem.label if mediaitem.mediatype == mediatypes.EPISODE \
#         else None
#     title3 = mediaitem.label if mediaitem.mediatype == mediatypes.SONG else None
#     sep = utils.get_pathsep(basedir)
#     mediayear = mediaitem.year if mediaitem.mediatype == mediatypes.MOVIE else None
# 
#     single_dir = mediaitem.mediatype == mediatypes.MOVIESET and not settings.setartwork_subdirs
#     thisdir = _find_existing(basedir, title1, slug1, mediayear, single_dir)
#     if not thisdir:
#         if mediaitem.mediatype == mediatypes.MOVIE:
#             title1 = '{0} ({1})'.format(mediaitem.label, mediaitem.year)
#         thisdir = utils.build_cleanest_name(title1, slug1)
#     result = basedir + thisdir
#     if not single_dir:
#         result += sep
#     if not title2:
#         return result
#     usefiles = mediaitem.mediatype == mediatypes.EPISODE
#     thisdir = _find_existing(result, title2, slug2, files=usefiles)
#     if not thisdir:
#         thisdir = utils.build_cleanest_name(title2, slug2)
#     result += thisdir
#     if not usefiles:
#         result += sep
#     if not title3:
#         return result
#     final = _find_existing(result, title3, files=True)
#     if not final:
#         final = utils.build_cleanest_name(title3)
#     result += final
#     return 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/providers/artfiles.py
import os
import xbmcvfs
from abc import ABCMeta
from lib.libs import mediatypes
from lib.libs.addonsettings import settings
from lib.libs.mediainfo import arttype_matches_base, format_arttype, find_central_infodir
from lib.libs.utils import SortedDisplay, natural_sort, get_movie_path_list, get_pathsep, \
    iter_possible_cleannames, parent_dir



ARTWORK_EXTS = ('.jpg', '.png', '.gif')
ARTIST_INFOFOLDER_PROVIDER = SortedDisplay('file:art', 20223)

ARTTYPE_MAXLENGTH = 30

class ArtFilesAbstractProvider(object):
    __metaclass__ = ABCMeta
    # 13514 = Local art

    name = SortedDisplay('file:art', 13514)