# 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


import xbmc
import xbmcgui
import xbmcvfs
import xml.etree.ElementTree as ET
from contextlib import closing
from lib.libs.pykodi import log, localize as L

FILENAME = 'special://userdata/advancedsettings.xml'
FILENAME_BAK = FILENAME + '.beef.bak'

ROOT_TAG = 'advancedsettings'
VIDEO_TAG = 'videolibrary'
MUSIC_TAG = 'musiclibrary'
ARTTYPE_TAG = 'arttype'

# 0: mediatype tag name, 1: library tag name, 2: Kodi's hardcoded art types to exclude from AS.xml
mediatype_map = {'tvshow': ('tvshowextraart', VIDEO_TAG, ('poster', 'banner', 'fanart')),
    'season': ('tvshowseasonextraart', VIDEO_TAG, ('poster', 'banner', 'fanart')),
    'episode': ('episodeextraart', VIDEO_TAG, ('thumb',)),
    'movie': ('movieextraart', VIDEO_TAG, ('poster', 'fanart')),
    'set': ('moviesetextraart', VIDEO_TAG, ('poster', 'fanart')),
    'musicvideo': ('musicvideoextraart', VIDEO_TAG, ('poster', 'fanart')),
    'artist': ('artistextraart', MUSIC_TAG, ('thumb', 'fanart')),
    'album': ('albumextraart', MUSIC_TAG, ('thumb',))}
unsupported_types = ('song',)

MALFORMED = 32654
BACKUP_SUCCESSFUL = 32655
BACKUP_UNSUCCESSFUL = 32656
RESTORE_SUCCESSFUL = 32657
RESTORE_UNSUCCESSFUL = 32658
RESTART_KODI = 32659

def save_arttypes(arttype_map):
    root = read_xml()
    if root is None:

# 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/advancedsettings.py
import xbmc
import xbmcgui
import xbmcvfs
import xml.etree.ElementTree as ET
from contextlib import closing
from lib.libs.pykodi import log, localize as L


FILENAME = 'special://userdata/advancedsettings.xml'
FILENAME_BAK = FILENAME + '.beef.bak'

ROOT_TAG = 'advancedsettings'
VIDEO_TAG = 'videolibrary'
MUSIC_TAG = 'musiclibrary'
ARTTYPE_TAG = 'arttype'

# 0: mediatype tag name, 1: library tag name, 2: Kodi's hardcoded art types to exclude from AS.xml
mediatype_map = {'tvshow': ('tvshowextraart', VIDEO_TAG, ('poster', 'banner', 'fanart')),
    'season': ('tvshowseasonextraart', VIDEO_TAG, ('poster', 'banner', 'fanart')),
    'episode': ('episodeextraart', VIDEO_TAG, ('thumb',)),
    'movie': ('movieextraart', VIDEO_TAG, ('poster', 'fanart')),
    'set': ('moviesetextraart', VIDEO_TAG, ('poster', 'fanart')),
    'musicvideo': ('musicvideoextraart', VIDEO_TAG, ('poster', 'fanart')),
    'artist': ('artistextraart', MUSIC_TAG, ('thumb', 'fanart')),
    'album': ('albumextraart', MUSIC_TAG, ('thumb',))}
unsupported_types = ('song',)

MALFORMED = 32654
BACKUP_SUCCESSFUL = 32655
BACKUP_UNSUCCESSFUL = 32656
RESTORE_SUCCESSFUL = 32657
RESTORE_UNSUCCESSFUL = 32658
RESTART_KODI = 32659

def save_arttypes(arttype_map):
    root = read_xml()
    if root is None:

        xbmcgui.Dialog().notification("Artwork Beef", L(MALFORMED), xbmcgui.NOTIFICATION_WARNING)