#!/usr/bin/env python3
import requests
import re
import sys
USERNAME = "1ARbE2L7ak"
PASSWORD = "ezfQtdrB3J"
PANEL_URL = "http://cchelp.xyz:826"
OUTPUT_FILE = "iptv_safe_playlist.m3u"
def sanitize(text):
"""Safely clean up channel names and categories."""
text = re.sub(r'[#\s]+$', '', str(text).strip())
return re.sub(r'[\\/*?:"<>|]', "", text)
def main():
print("Fetching live categories...")
cat_resp = requests.get(f"{PANEL_URL}/player_api.php", params={
"username": USERNAME, "password": PASSWORD, "action": "get_live_categories"
}, timeout=15)
cat_resp.raise_for_status()
categories = {str(cat["category_id"]): sanitize(cat["category_name"]) for cat in cat_resp.json()}
print("Fetching live streams...")
stream_resp = requests.get(f"{PANEL_URL}/player_api.php", params={
"username": USERNAME, "password": PASSWORD, "action": "get_live_streams"
}, timeout=15)
stream_resp.raise_for_status()
streams = stream_resp.json()
print(f"Found {len(streams)} channels. Generating safe M3U...")
m3u_lines = ["#EXTM3U"]
for stream in streams:
name = sanitize(stream["name"])
group = categories.get(str(stream.get("category_id")), "General")
stream_url = f"{PANEL_URL}/live/{USERNAME}/{PASSWORD}/{stream['stream_id']}.ts"
m3u_lines.append(f'#EXTINF:-1 group-title="{group}",{name}')
m3u_lines.append(stream_url)
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
f.write("\n".join(m3u_lines))
print(f"Success! Clean playlist saved as {OUTPUT_FILE}")
if __name__ == "__main__":
try:
main()
except Exception as e:
print(f"Error: {e}")
sys.exit(1)