# -*- coding: utf-8 -*-
import sys
l11ll111_opy_ = sys.version_info [0] == 2
l1lll1l1_opy_ = 2048
l11lllll_opy_ = 7
def l1l11_opy_ (l11ll1_opy_):
	global l1llll11_opy_
	l1ll1111_opy_ = ord (l11ll1_opy_ [-1])
	l11ll11l_opy_ = l11ll1_opy_ [:-1]
	l11l11l_opy_ = l1ll1111_opy_ % len (l11ll11l_opy_)
	l111l1_opy_ = l11ll11l_opy_ [:l11l11l_opy_] + l11ll11l_opy_ [l11l11l_opy_:]
	if l11ll111_opy_:
		l1lll1_opy_ = unicode () .join ([unichr (ord (char) - l1lll1l1_opy_ - (l1l1l_opy_ + l1ll1111_opy_) % l11lllll_opy_) for l1l1l_opy_, char in enumerate (l111l1_opy_)])
	else:
		l1lll1_opy_ = str () .join ([chr (ord (char) - l1lll1l1_opy_ - (l1l1l_opy_ + l1ll1111_opy_) % l11lllll_opy_) for l1l1l_opy_, char in enumerate (l111l1_opy_)])
	return eval (l1lll1_opy_)
import platform
try:    l1ll1l11l_opy_ = platform.system
except: l1ll1l11l_opy_ = None
def l1lll11ll_opy_():
    if l1ll1l11l_opy_:
        return l1ll1l11l_opy_()
    import sys
    if sys.platform.lower().startswith(l1l11_opy_ (u"ࠨࡹ࡬ࡲࠬ࡟")):
        return l1l11_opy_ (u"࡚ࠩ࡭ࡳࡪ࡯ࡸࡵࠪࡠ")
    return l1l11_opy_ (u"ࠪࡓࡹ࡮ࡥࡳࠢࡒࡗࡪࡹࠠࡵࡱࠣࡦࡪࠦࡤࡦࡶࡨࡶࡲ࡯࡮ࡦࡦࠪࡡ")
platform.system = l1lll11ll_opy_
import requests
platform.system = l1ll1l11l_opy_
import os
import json
import dixie
l1lll1l1l_opy_ = dixie.PROFILE
PATH = os.path.join(l1lll1l1l_opy_, l1l11_opy_ (u"ࠫࡵࡲࡩࡴࡶࡶࠫࡢ"))
def loadPlaylists():
    dixie.log(l1l11_opy_ (u"ࠬࡃ࠽࠾࠿ࡀࡁࡂࡃ࠽࠾࠿ࡀࡁࠥࡖࡌࡂ࡛ࡏࡍࡘ࡚ࡓࠡ࠿ࡀࡁࡂࡃ࠽࠾࠿ࡀࡁࡂࡃࠧࡣ"))
    if os.path.exists(PATH):
        return json.load(open(PATH))
    try:
        l1lll111l_opy_()
        return json.load(open(PATH))
    except:
        dixie.log(l1l11_opy_ (u"࠭࠽࠾࠿ࡀࠤࡕࡲࡡࡺ࡮࡬ࡷࡹࠦ࡬ࡰࡣࡧࠤࡪࡸࡲࡰࡴࠣࡁࡂࡃ࠽ࠨࡤ"))
        return []
def l1lll111l_opy_():
    source = dixie.GetSetting(l1l11_opy_ (u"ࠧࡪࡲࡷࡺ࠳ࡹ࡯ࡶࡴࡦࡩࠬࡥ"))
    if not source == l1l11_opy_ (u"ࠨ࠳ࠪࡦ"):
        return l1llll11l_opy_()
    return l1ll11111_opy_()
def l1llll11l_opy_():
    l111l111_opy_ = []
    if dixie.GetSetting(l1l11_opy_ (u"ࠩࡌࡔ࡙࡜࡟࠱ࠩࡧ")) == l1l11_opy_ (u"ࠪࡸࡷࡻࡥࠨࡨ"):
        l1lllllll_opy_  = dixie.GetSetting(l1l11_opy_ (u"ࠫࡎࡖࡔࡗࡡ࠳ࡣ࡚ࡘࡌࠨࡩ"))
        l1llllll1_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠬࡏࡐࡕࡘࡢ࠴ࡤࡖࡏࡓࡖࠪࡪ"))
        l1lll1lll_opy_ = dixie.GetSetting(l1l11_opy_ (u"࠭ࡉࡑࡖ࡙ࡣ࠵ࡥࡔ࡚ࡒࡈࠫ࡫"))
        l1111111_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠧࡊࡒࡗ࡚ࡤ࠶࡟ࡖࡕࡈࡖࠬ࡬"))
        l11111l1_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠨࡋࡓࡘ࡛ࡥ࠰ࡠࡒࡄࡗࡘ࠭࡭"))
        if len(l1lllllll_opy_) > 0:
            l1ll1111l_opy_ = l1ll11l1l_opy_(l1lllllll_opy_, l1llllll1_opy_, l1lll1lll_opy_, l1111111_opy_, l11111l1_opy_)
            l111l111_opy_.append((l1ll1111l_opy_, l1l11_opy_ (u"ࠩࡌࡔ࡙࡜࠱࠻ࠢࠪ࡮")))
    if dixie.GetSetting(l1l11_opy_ (u"ࠪࡍࡕ࡚ࡖࡠ࠳ࠪ࡯")) == l1l11_opy_ (u"ࠫࡹࡸࡵࡦࠩࡰ"):
        l1lllllll_opy_  = dixie.GetSetting(l1l11_opy_ (u"ࠬࡏࡐࡕࡘࡢ࠵ࡤ࡛ࡒࡍࠩࡱ"))
        l1llllll1_opy_ = dixie.GetSetting(l1l11_opy_ (u"࠭ࡉࡑࡖ࡙ࡣ࠶ࡥࡐࡐࡔࡗࠫࡲ"))
        l1lll1lll_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠧࡊࡒࡗ࡚ࡤ࠷࡟ࡕ࡛ࡓࡉࠬࡳ"))
        l1111111_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠨࡋࡓࡘ࡛ࡥ࠱ࡠࡗࡖࡉࡗ࠭ࡴ"))
        l11111l1_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠩࡌࡔ࡙࡜࡟࠲ࡡࡓࡅࡘ࡙ࠧࡵ"))
        if len(l1lllllll_opy_) > 0:
            l1lllll1l_opy_ = l1ll11l1l_opy_(l1lllllll_opy_, l1llllll1_opy_, l1lll1lll_opy_, l1111111_opy_, l11111l1_opy_)
            l111l111_opy_.append((l1lllll1l_opy_, l1l11_opy_ (u"ࠪࡍࡕ࡚ࡖ࠳࠼ࠣࠫࡶ")))
    if dixie.GetSetting(l1l11_opy_ (u"ࠫࡎࡖࡔࡗࡡ࠵ࠫࡷ")) == l1l11_opy_ (u"ࠬࡺࡲࡶࡧࠪࡸ"):
        l1lllllll_opy_  = dixie.GetSetting(l1l11_opy_ (u"࠭ࡉࡑࡖ࡙ࡣ࠷ࡥࡕࡓࡎࠪࡹ"))
        l1llllll1_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠧࡊࡒࡗ࡚ࡤ࠸࡟ࡑࡑࡕࡘࠬࡺ"))
        l1lll1lll_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠨࡋࡓࡘ࡛ࡥ࠲ࡠࡖ࡜ࡔࡊ࠭ࡻ"))
        l1111111_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠩࡌࡔ࡙࡜࡟࠳ࡡࡘࡗࡊࡘࠧࡼ"))
        l11111l1_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠪࡍࡕ࡚ࡖࡠ࠴ࡢࡔࡆ࡙ࡓࠨࡽ"))
        if len(l1lllllll_opy_) > 0:
            l1lllll11_opy_ = l1ll11l1l_opy_(l1lllllll_opy_, l1llllll1_opy_, l1lll1lll_opy_, l1111111_opy_, l11111l1_opy_)
            l111l111_opy_.append((l1lllll11_opy_, l1l11_opy_ (u"ࠫࡎࡖࡔࡗ࠵࠽ࠤࠬࡾ")))
    return l1ll1l111_opy_(l1l11_opy_ (u"࡛ࠬࡒࡍࡕࠪࡿ"),  l111l111_opy_)
def l1ll11111_opy_():
    l111l111_opy_ = []
    if dixie.GetSetting(l1l11_opy_ (u"࠭ࡰ࡭ࡣࡼࡰ࡮ࡹࡴ࠯ࡶࡼࡴࡪ࠭ࢀ")) == l1l11_opy_ (u"ࠧ࠱ࠩࢁ"):
        if dixie.GetSetting(l1l11_opy_ (u"ࠨࡗࡕࡐࡤࡕࠧࢂ")) == l1l11_opy_ (u"ࠩࡷࡶࡺ࡫ࠧࢃ"):
            l1l1lllll_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠪࡴࡱࡧࡹ࡭࡫ࡶࡸ࠳ࡻࡲ࡭ࠩࢄ"))
            if len(l1l1lllll_opy_) > 0:
                l111l111_opy_.append((l1l1lllll_opy_, l1l11_opy_ (u"࡚ࠫࡘࡌ࠲࠼ࠣࠫࢅ")))
        if dixie.GetSetting(l1l11_opy_ (u"࡛ࠬࡒࡍࡡ࠴ࠫࢆ")) == l1l11_opy_ (u"࠭ࡴࡳࡷࡨࠫࢇ"):
            l1ll1l1ll_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠧࡱ࡮ࡤࡽࡱ࡯ࡳࡵ࠰ࡸࡶࡱ࠷ࠧ࢈"))
            if len(l1ll1l1ll_opy_) > 0:
                l111l111_opy_.append((l1ll1l1ll_opy_, l1l11_opy_ (u"ࠨࡗࡕࡐ࠷ࡀࠠࠨࢉ")))
        if dixie.GetSetting(l1l11_opy_ (u"ࠩࡘࡖࡑࡥ࠲ࠨࢊ")) == l1l11_opy_ (u"ࠪࡸࡷࡻࡥࠨࢋ"):
            l1llll1ll_opy_ = dixie.GetSetting(l1l11_opy_ (u"ࠫࡵࡲࡡࡺ࡮࡬ࡷࡹ࠴ࡵࡳ࡮࠵ࠫࢌ"))
            if len(l1llll1ll_opy_) > 0:
                l111l111_opy_.append((l1llll1ll_opy_, l1l11_opy_ (u"࡛ࠬࡒࡍ࠵࠽ࠤࠬࢍ")))
        dixie.log(l111l111_opy_)
        return l1ll1l111_opy_(l1l11_opy_ (u"࠭ࡕࡓࡎࡖࠫࢎ"),  l111l111_opy_)
    if dixie.GetSetting(l1l11_opy_ (u"ࠧࡱ࡮ࡤࡽࡱ࡯ࡳࡵ࠰ࡷࡽࡵ࡫ࠧ࢏")) == l1l11_opy_ (u"ࠨ࠳ࠪ࢐"):
        if dixie.GetSetting(l1l11_opy_ (u"ࠩࡉࡍࡑࡋ࡟࠱ࠩ࢑")) == l1l11_opy_ (u"ࠪࡸࡷࡻࡥࠨ࢒"):
            l1111l1l_opy_ = os.path.join(dixie.GetSetting(l1l11_opy_ (u"ࠫࡵࡲࡡࡺ࡮࡬ࡷࡹ࠴ࡦࡪ࡮ࡨࠫ࢓")))
            if l1111l1l_opy_:
                l111l111_opy_.append((l1111l1l_opy_, l1l11_opy_ (u"ࠬࡌࡉࡍࡇ࠴࠾ࠥ࠭࢔")))
        if dixie.GetSetting(l1l11_opy_ (u"࠭ࡆࡊࡎࡈࡣ࠵࠭࢕")) == l1l11_opy_ (u"ࠧࡵࡴࡸࡩࠬ࢖"):
            l1111ll1_opy_ = os.path.join(dixie.GetSetting(l1l11_opy_ (u"ࠨࡲ࡯ࡥࡾࡲࡩࡴࡶ࠱ࡪ࡮ࡲࡥ࠲ࠩࢗ")))
            if l1111ll1_opy_:
                l111l111_opy_.append((l1111ll1_opy_, l1l11_opy_ (u"ࠩࡉࡍࡑࡋ࠲࠻ࠢࠪ࢘")))
        if dixie.GetSetting(l1l11_opy_ (u"ࠪࡊࡎࡒࡅࡠ࠲࢙ࠪ")) == l1l11_opy_ (u"ࠫࡹࡸࡵࡦ࢚ࠩ"):
            l1111lll_opy_ = os.path.join(dixie.GetSetting(l1l11_opy_ (u"ࠬࡶ࡬ࡢࡻ࡯࡭ࡸࡺ࠮ࡧ࡫࡯ࡩ࠷࢛࠭")))
            if l1111lll_opy_:
                l111l111_opy_.append((l1111lll_opy_, l1l11_opy_ (u"࠭ࡆࡊࡎࡈ࠷࠿ࠦࠧ࢜")))
        dixie.log(l111l111_opy_)
        return l1ll1l111_opy_(l1l11_opy_ (u"ࠧࡇࡋࡏࡉࡘ࠭࢝"), l111l111_opy_)
def l1ll111ll_opy_():
    l1ll11l11_opy_ = [l1l11_opy_ (u"ࠨࡪࡷࡸࡵࡀ࠯࠰ࡺ࠱ࡧࡴ࠵ࡈࡆ࡜࠸࡞ࡾ࡯ࡊࡦ࡙ࠪ࢞")]
    for url in l1ll11l11_opy_:
        request = requests.get(url)
        content = request.content
        if l1l11_opy_ (u"ࠩࠦࡉ࡝࡚ࡍ࠴ࡗࠪ࢟") in content:
            return l1ll1l111_opy_(l1l11_opy_ (u"ࠪࡇࡑࡕࡕࡅࠩࢠ"), [(url, l1l11_opy_ (u"ࠫࠬࢡ"))])
            break
def l1ll1l111_opy_(l1ll11ll1_opy_, plist):
    dixie.log(l1ll11ll1_opy_)
    dixie.log(plist)
    playlists = []
    for item in plist:
        url = item[0]
        l11111ll_opy_ = item[1]
        l1llll1l1_opy_ = l1111l11_opy_(l1ll11ll1_opy_, url, l11111ll_opy_)
        playlists.extend(l1llll1l1_opy_)
    json.dump(playlists, open(PATH,l1l11_opy_ (u"ࠬࡽࠧࢢ")))
def l1111l11_opy_(l1ll11ll1_opy_, url, l11111ll_opy_):
    content  = l1ll111l1_opy_(l1ll11ll1_opy_, url)
    pairs    = []
    for i in range(1,len(content), 2):
        if l1ll11lll_opy_(content[i+1]):
            l1lll1l11_opy_ = content[i]
            l1ll1lll1_opy_   = content[i+1].rstrip()
            pairs.append([l1lll1l11_opy_, l1ll1lll1_opy_])
    l1ll1ll11_opy_ = list()
    l1lll1l11_opy_   = l1l11_opy_ (u"࠭ࠧࢣ")
    value   = l1l11_opy_ (u"ࠧࠨࢤ")
    for item in pairs:
        l1lll1ll1_opy_ = item[0]
        l1llll111_opy_ = item[1]
        l1lll1111_opy_   = l1lll1ll1_opy_.split(l1l11_opy_ (u"ࠨ࠮ࠪࢥ"))[-1].strip()
        l1ll1llll_opy_   = dixie.cleanLabel(l1lll1111_opy_)
        l1lll11l1_opy_ = dixie.cleanPrefix(l1ll1llll_opy_)
        l111111l_opy_ = dixie.mapChannelName(l1lll11l1_opy_)
        value = l1llll111_opy_.replace(l1l11_opy_ (u"ࠩࡵࡸࡲࡶ࠺࠰࠱ࠧࡓࡕ࡚࠺ࡳࡶࡰࡴ࠲ࡸࡡࡸ࠿ࠪࢦ"), l1l11_opy_ (u"ࠪࠫࢧ")).strip()
        l1ll1ll11_opy_.append((l11111ll_opy_, l111111l_opy_, value))
    return l1ll1ll11_opy_
def l1ll11lll_opy_(link):
    if link == l1l11_opy_ (u"ࠫࠨࡋࡘࡕ࠯࡛࠱ࡊࡔࡄࡍࡋࡖࡘࠬࢨ"):
        return False
    if len(link) < 1:
        return False
    if l1l11_opy_ (u"ࠬ࠵࡭ࡰࡸ࡬ࡩ࠴࠭ࢩ") in link:
        return False
    if l1l11_opy_ (u"࠭࠯ࡴࡧࡵ࡭ࡪࡹ࠯ࠨࢪ") in link:
        return False
    return True
def l1ll111l1_opy_(l1ll11ll1_opy_, url):
    import urllib
    if (l1ll11ll1_opy_ == l1l11_opy_ (u"ࠧࡖࡔࡏࡗࠬࢫ")) or (l1ll11ll1_opy_ == l1l11_opy_ (u"ࠨࡅࡏࡓ࡚ࡊࠧࢬ")):
        response = urllib.urlopen(url)
        content  = response.readlines()
        return content
    if l1ll11ll1_opy_ == l1l11_opy_ (u"ࠩࡉࡍࡑࡋࡓࠨࢭ"):
        with open(url) as content:
            return content.readlines()
def l1ll11l1l_opy_(l1lllllll_opy_, l1llllll1_opy_, l1lll1lll_opy_, l1111111_opy_, l11111l1_opy_):
    if l1lllllll_opy_.startswith(l1l11_opy_ (u"ࠪ࡬ࡹࡺࡰ࠻࠱࠲ࠫࢮ")):
        url = l1lllllll_opy_
    else:
        url = l1l11_opy_ (u"ࠫ࡭ࡺࡴࡱ࠼࠲࠳ࠬࢯ") + l1lllllll_opy_
    url +=  l1ll1l1l1_opy_(l1llllll1_opy_)
    url += l1l11_opy_ (u"ࠬ࠵ࡧࡦࡶ࠱ࡴ࡭ࡶ࠿ࡶࡵࡨࡶࡳࡧ࡭ࡦ࠿ࠪࢰ")
    url +=  l1111111_opy_
    url += l1l11_opy_ (u"࠭ࠦࡱࡣࡶࡷࡼࡵࡲࡥ࠿ࠪࢱ")
    url +=  l11111l1_opy_
    url += l1l11_opy_ (u"ࠧࠧࡶࡼࡴࡪࡃ࡭࠴ࡷࡢࡴࡱࡻࡳࠧࡱࡸࡸࡵࡻࡴ࠾ࠩࢲ")
    url +=  l1ll1ll1l_opy_(l1lll1lll_opy_)
    return url
def l1ll1l1l1_opy_(l1llllll1_opy_):
    if not l1llllll1_opy_ == l1l11_opy_ (u"ࠨࠩࢳ"):
        return l1l11_opy_ (u"ࠩ࠽ࠫࢴ") + l1llllll1_opy_
    return l1l11_opy_ (u"ࠪࠫࢵ")
def l1ll1ll1l_opy_(l1lll1lll_opy_):
    if l1lll1lll_opy_ == l1l11_opy_ (u"ࠫ࠵࠭ࢶ"):
        return l1l11_opy_ (u"ࠬࡳ࠳ࡶ࠺ࠪࢷ")
    if l1lll1lll_opy_ == l1l11_opy_ (u"࠭࠱ࠨࢸ"):
        return l1l11_opy_ (u"ࠧ࡮ࡲࡨ࡫ࡹࡹࠧࢹ")
if __name__ == l1l11_opy_ (u"ࠨࡡࡢࡱࡦ࡯࡮ࡠࡡࠪࢺ"):
    l1lll111l_opy_()