From 3a2c8ef7a115e2748879e49d0b5be05eca8bf652 Mon Sep 17 00:00:00 2001 From: Ignacio Rivero Date: Sun, 16 Feb 2025 17:38:59 -0300 Subject: [PATCH] Initial commit. --- main.py | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 2 + 2 files changed, 123 insertions(+) create mode 100644 main.py create mode 100644 readme.md diff --git a/main.py b/main.py new file mode 100644 index 0000000..73b85dd --- /dev/null +++ b/main.py @@ -0,0 +1,121 @@ +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) \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..62841ab --- /dev/null +++ b/readme.md @@ -0,0 +1,2 @@ +# impmv +A small IPTV player for your Raspberry Pi.