# 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
    '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)
        return False

    set_arttypes(root, arttype_map)

    if save_backup():
        save_xml(root)
        xbmcgui.Dialog().ok("Artwork Beef", L(RESTART_KODI))

def set_arttypes(root, arttype_map):
    for key, artlist in arttype_map.items():
        if key not in mediatype_map:
            if key not in unsupported_types:
                log("Can't set arttypes for '{0}' in advancedsettings.xml".format(key), xbmc.LOGNOTICE)
            continue
        typemap = mediatype_map[key]

# 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

    '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)
        return False

    set_arttypes(root, arttype_map)

    if save_backup():
        save_xml(root)
        xbmcgui.Dialog().ok("Artwork Beef", L(RESTART_KODI))

def set_arttypes(root, arttype_map):
    for key, artlist in arttype_map.items():
        if key not in mediatype_map:
            if key not in unsupported_types:
                log("Can't set arttypes for '{0}' in advancedsettings.xml".format(key), xbmc.LOGNOTICE)
            continue
        typemap = mediatype_map[key]

        library_elem = root.find(typemap[1])