import xbmcaddon
import xbmc

def parsePlaylist(playlistPath):
    m3u = open(playlistPath, 'r', encoding='utf-8').read().splitlines()
    result = []

    for line in m3u:
        if line.startswith("plugin://"):
            result[-1]["url"] = line

        if not line.startswith('#EXTINF:'):
            continue

        result.append({
            "name": line.split(',')[1],
            "logo": line.split('tvg-logo="')[1].split('"')[0],
            "group": line.split('group-title="')[1].split('"')[0]
        })

    return result
    

def getEnabled():
    allowed = []
    _ADDON = xbmcaddon.Addon()
    if _ADDON.getSettingBool("CSEnabled"):
        allowed.append("SK")
        allowed.append("CZ")
        allowed.append("CS")

    if _ADDON.getSettingBool("USEnabled"):
        allowed.append("US")

    if _ADDON.getSettingBool("UKEnabled"):
        allowed.append("UK")

    if _ADDON.getSettingBool("DEEnabled"):
        allowed.append("DE")

    if _ADDON.getSettingBool("ENEnabled"):
        allowed.append("EN")

    if _ADDON.getSettingBool("FREnabled"):
        allowed.append("FR")

    if _ADDON.getSettingBool("PLEnabled"):
        allowed.append("PL")

    return allowed

def stopifPlaying():
    if xbmc.Player().isPlaying():
        xbmc.Player().stop()