import json

INPUT = "/opt/epg/2.txt"
OUTPUT = "/opt/epg/channels.json"

channels = {}

with open(INPUT, "r", encoding="utf-8") as f:
    for line in f:
        line = line.strip()

        if not line:
            continue

        parts = line.split(maxsplit=1)

        if len(parts) != 2:
            continue

        cid, name = parts

        name = name.title().replace(" Hd", " HD")
        channels[cid] = f"{name} ({cid}) SK"

with open(OUTPUT, "w", encoding="utf-8") as f:
    json.dump(channels, f, ensure_ascii=False, indent=4)

print(f"Hotovo: {len(channels)} kanálov")