import requests
import json

BASE = "http://141.94.193.53"

with open("hu.json", "r", encoding="utf-8") as f:
    channels = json.load(f)

found = []

for channel in channels:
    url = f"{BASE}/{channel}/index.m3u8"

    try:
        r = requests.get(url, timeout=4)

        if r.status_code == 200 and (
            "#EXTM3U" in r.text or "#EXT-X-" in r.text
        ):
            print(f"[FOUND] {channel}")

            found.append({
                "name": channel,
                "url": url
            })
        else:
            print(f"[--] {channel}")

    except requests.RequestException:
        print(f"[ERR] {channel}")

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

print()
print(f"Nájdených kanálov: {len(found)}")
print("Výsledok: found.json")