# 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
# 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):


import re
import urllib
from abc import ABCMeta
from lib.libs import mediatypes
from lib.libs.addonsettings import settings
from lib.libs.pykodi import localize as L
from lib.libs.utils import SortedDisplay, get_movie_path_list

def build_video_thumbnail_path(videofile):
    if videofile.startswith('image://'):
        return videofile
    # Kodi goes lowercase and doesn't encode some chars
    result = 'image://video@{0}/'.format(urllib.quote(videofile, '()!'))
    result = re.sub(r'%[0-9A-F]{2}', lambda mo: mo.group().lower(), result)
    return result

class VideoFileMovieProvider(VideoFileAbstractProvider):
    mediatype = mediatypes.MOVIE

    def get_exact_images(self, mediaitem):
        if not mediatypes.generatethumb(mediaitem.mediatype):
            return {}
        path = get_movie_path_list(mediaitem.file)[0]
        if path.endswith('.iso'):
            return {}
        return {'thumb': self.build_video_thumbnail(path)}

class VideoFileEpisodeProvider(VideoFileAbstractProvider):
    mediatype = mediatypes.EPISODE

    def get_exact_images(self, mediaitem):
        path = mediaitem.file
        if not mediatypes.generatethumb(mediaitem.mediatype) or path.endswith('.iso'):
            return {}
        return {'thumb': self.build_video_thumbnail(path)}

class VideoFileMusicVideoProvider(VideoFileEpisodeProvider):

# 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
# 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/providers/videofile.py
import re
import urllib
from abc import ABCMeta
from lib.libs import mediatypes
from lib.libs.addonsettings import settings
from lib.libs.pykodi import localize as L
from lib.libs.utils import SortedDisplay, get_movie_path_list


def build_video_thumbnail_path(videofile):
    if videofile.startswith('image://'):
        return videofile
    # Kodi goes lowercase and doesn't encode some chars
    result = 'image://video@{0}/'.format(urllib.quote(videofile, '()!'))
    result = re.sub(r'%[0-9A-F]{2}', lambda mo: mo.group().lower(), result)
    return result

class VideoFileMovieProvider(VideoFileAbstractProvider):
    mediatype = mediatypes.MOVIE

    def get_exact_images(self, mediaitem):
        if not mediatypes.generatethumb(mediaitem.mediatype):
            return {}
        path = get_movie_path_list(mediaitem.file)[0]
        if path.endswith('.iso'):
            return {}
        return {'thumb': self.build_video_thumbnail(path)}

class VideoFileEpisodeProvider(VideoFileAbstractProvider):
    mediatype = mediatypes.EPISODE

    def get_exact_images(self, mediaitem):
        path = mediaitem.file
        if not mediatypes.generatethumb(mediaitem.mediatype) or path.endswith('.iso'):
            return {}
        return {'thumb': self.build_video_thumbnail(path)}

class VideoFileMusicVideoProvider(VideoFileEpisodeProvider):

    mediatype = mediatypes.MUSICVIDEO