import mpv import requests import flask import re from flask import request XTEVE_M3U_URL = "http://tv.netpaws.cc/m3u/xteve.m3u" def get_channels(): response = requests.get(XTEVE_M3U_URL) lines = response.text.splitlines() channels = [] regex = re.compile(r'tvg-logo="(.*?)".*?group-title="(.*?)"', re.IGNORECASE) for i in range(len(lines)): if lines[i].startswith("#EXTINF"): match = regex.search(lines[i]) logo = match.group(1) if match else "" group = match.group(2) if match else "Other" name = lines[i].split(",")[-1] url = lines[i + 1] channels.append({"name": name, "url": url, "logo": logo, "group": group}) return channels player = mpv.MPV( vo='gpu', demuxer_lavf_o='reconnect=1', deinterlace='yes', keepaspect = 'no', geometry = '100%:100%' ) channels = get_channels() current_index = 0 def play_channel(index): global current_index current_index = index % len(channels) print(f"Playing {channels[current_index]["url"]}") player.play(channels[current_index]["url"]) play_channel(current_index) # Flask web server app = flask.Flask(__name__) @app.route("/") def index(): grouped_channels = {} for channel in channels: grouped_channels.setdefault(channel["group"], []).append(channel) html = f""" IPTV Remote

IPTV Remote

Current Channel: {channels[current_index]['name']}

All Channels

""" flat_channel_list = [channel for group in grouped_channels.values() for channel in group] for group, ch_list in grouped_channels.items(): html += f'
{group}' for channel in ch_list: index = flat_channel_list.index(channel) # Get correct global index html += f'''
''' html += '
' html += """
""" return html @app.route("/channel") def switch_channel(): index = int(request.args.get("index", current_index)) play_channel(index) return "", 204 if __name__ == "__main__": app.run(host="0.0.0.0", port=5000)