def translatepath(path):
    ret = []
    if path.lower().startswith('special://'):
        special = re.split(r'\\|/', path[10:])[0]
        if special.startswith('addondata'):
            myid = re.findall(r'addondata\((.+?)\)', special)
            if len(myid) > 0:
                ret.append(addondatapath(myid[0]))
            else:
                ret.append(addondatapath())
        elif special.startswith('addon'):
            myid = re.findall(r'addon\((.+?)\)', special)
            if len(myid) > 0:
                ret.append(addonpath(myid[0]))
            else:
                ret.append(addonpath())

        else:
            ret.append(kodiTP('special://%s' % special))
        path = path[10:]
        ret = ret + re.split(r'\\|/', path)[1:]
    else:
        ret = re.split(r'\\|/', path)
    if ret[0].endswith(':'):
        ret[0] = '%s\\' % ret[0]
    ret = os.path.join(*ret)
    ret = os.path.expandvars(ret)
    ret = os.path.expanduser(ret)
    if path.startswith('/'):
        ret = '/%s' % ret
    return ret
def translatepath(path):
    ret = []
    if path.lower().startswith('special://'):
        special = re.split(r'\\|/', path[10:])[0]
        if special.startswith('addondata'):
            myid =  re.findall(r'addondata\((.+?)\)', special)
            if len(myid)>0:
                ret.append(addondatapath(myid[0]))
            else:
                ret.append(addondatapath())
        elif special.startswith('addon'):
            myid =  re.findall(r'addon\((.+?)\)', special)
            if len(myid)>0:
                ret.append(addonpath(myid[0]))
            else:
                ret.append(addonpath())

        else:
            ret.append(kodiTP('special://%s' % special))
        path = path[10:]
        ret = ret + re.split(r'\\|/', path)[1:]
    else:
        ret = re.split(r'\\|/', path)
    if ret[0].endswith(':'):
        ret[0] = '%s\\' % ret[0]
    ret = os.path.join(*ret)
    ret = os.path.expandvars(ret)
    ret = os.path.expanduser(ret)
    if path.startswith('/'):
        ret = '/%s' % ret
    return ret
def translatepath(path):
    ret = []
    if path.lower().startswith(u'special://'):
        special = re.split(ur'\\|/', path[10:])[0]
        if special.startswith(u'addondata'):
            myid = re.findall(ur'addondata\((.+?)\)', special)
            if len(myid) > 0:
                ret.append(addondatapath(myid[0]))
            else:
                ret.append(addondatapath())
        elif special.startswith(u'addon'):
            myid = re.findall(ur'addon\((.+?)\)', special)
            if len(myid) > 0:
                ret.append(addonpath(myid[0]))
            else:
                ret.append(addonpath())
        else:
            ret.append(kodiTP(u'special://%s' % special))
        path = path[10:]
        ret = ret + re.split(ur'\\|/', path)[1:]
    else:
        ret = re.split(ur'\\|/', path)
    if ret[0].endswith(':'):
        ret[0] = u'%s\\' % ret[0]
    for i, r in enumerate(ret):
        ret[i] = secure_filename(r)
    ret = os.path.join(*ret)
    ret = os.path.expandvars(ret)
    ret = os.path.expanduser(ret)
    ret = os.path.normpath(ret)
    if path.startswith('/'):
        ret = u'/%s' % ret

    # if not os.path.supports_unicode_filenames:
    #     ret = ret.decode('utf-8')

    ret = secure_filename(ret)
    return ret
def translatepath(path):
    ret = []
    if path.lower().startswith(u'special://'):
        special = re.split(ur'\\|/', path[10:])[0]
        if special.startswith(u'addondata'):
            myid = re.findall(ur'addondata\((.+?)\)', special)
            if len(myid) > 0:
                ret.append(addondatapath(myid[0]))
            else:
                ret.append(addondatapath())
        elif special.startswith(u'addon'):
            myid = re.findall(ur'addon\((.+?)\)', special)
            if len(myid) > 0:
                ret.append(addonpath(myid[0]))
            else:
                ret.append(addonpath())
        else:
            ret.append(kodiTP(u'special://%s' % special))
        path = path[10:]
        ret = ret + re.split(ur'\\|/', path)[1:]
    else:
        ret = re.split(ur'\\|/', path)
    if ret[0].endswith(':'):
        ret[0] = u'%s\\' % ret[0]
    for i, r in enumerate(ret):
        ret[i] = secure_filename(r)
    ret = os.path.join(*ret)
    ret = os.path.expandvars(ret)
    ret = os.path.expanduser(ret)
    ret = os.path.normpath(ret)
    if path.startswith('/'):
        ret = u'/%s' % ret

    # if not os.path.supports_unicode_filenames:
    #     ret = ret.decode('utf-8')

    ret = secure_filename(ret)
    return ret
import xbmc
import xbmcaddon


def _translatePathMock(path):
    return kodiTranslatePathMock(path)


try:
    from xbmc import translatePath as kodiTP
except ImportError:
    kodiTP = _translatePathMock
    isStub = True
else:
    if kodiTP('special://home') == u'':
        isStub = True
        kodiTP = _translatePathMock
    else:
        isStub = False

_split = re.compile(r'\0')


def getPlatform():
    if sys.platform.startswith('win'):
        ret = 'win'
    elif platform.system().lower().startswith('darwin'):
        if platform.machine().startswith('iP'):
            ret = 'ios'
        else:
import xbmcaddon
import re
import stat


def _translatePathMock(path):
    return kodiTranslatePathMock(path)


try:
    from xbmc import translatePath as kodiTP
except ImportError:
    kodiTP = _translatePathMock
    isStub = True
else:
    if kodiTP('special://home') == u'':
        isStub = True
        kodiTP = _translatePathMock
    else:
        isStub = False


def getPlatform():
    if sys.platform.startswith('win'):
        ret = 'win'
    elif platform.system().lower().startswith('darwin'):
        if platform.machine().startswith('iP'):
            ret = 'ios'
        else:
            ret = 'osx'
    elif 'XBMC_ANDROID_SYSTEM_LIBS' in os.environ.keys():