From fb29c46f4f360b7d58d71c2f42b4e4f33596fd55 Mon Sep 17 00:00:00 2001 From: Eduard Prigoana Date: Tue, 4 Feb 2025 17:05:35 +0200 Subject: [PATCH] Add files via upload --- tv/app.py | 58 +++++++++++++++++ tv/playlists/placeholder.txt | 1 + tv/requirements.txt | 1 + tv/templates/index.html | 122 +++++++++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 tv/app.py create mode 100644 tv/playlists/placeholder.txt create mode 100644 tv/requirements.txt create mode 100644 tv/templates/index.html diff --git a/tv/app.py b/tv/app.py new file mode 100644 index 0000000..17906aa --- /dev/null +++ b/tv/app.py @@ -0,0 +1,58 @@ +from flask import Flask, request, render_template, send_from_directory +import requests +import os + +app = Flask(__name__) +M3U_URL = "https://iptv-org.github.io/iptv/index.m3u" +PLAYLIST_DIR = "playlists" + +if not os.path.exists(PLAYLIST_DIR): + os.makedirs(PLAYLIST_DIR) + +def fetch_m3u(): + response = requests.get(M3U_URL) + if response.status_code == 200: + return response.text + return "" + +def parse_m3u(m3u_content): + lines = m3u_content.split("\n") + channels = [] + name, url = None, None + for line in lines: + if line.startswith("#EXTINF"): + parts = line.split(",") + name = parts[-1].strip() if len(parts) > 1 else "Unknown Channel" + elif line.startswith("http"): + url = line.strip() + if name and url: + channels.append((name, name, url)) + name, url = None, None + return channels + +@app.route("/") +def index(): + m3u_content = fetch_m3u() + channels = parse_m3u(m3u_content) + return render_template("index.html", channels=channels) + +@app.route("/generate", methods=["POST"]) +def generate_playlist(): + filename = request.form.get("filename", "custom_playlist").strip() + selected_channels = request.form.getlist("channels") + if not filename.endswith(".m3u"): + filename += ".m3u" + filepath = os.path.join(PLAYLIST_DIR, filename) + with open(filepath, "w") as f: + f.write("#EXTM3U\n") + for channel in selected_channels: + info, url = channel.split("|", 1) + f.write(f"#EXTINF:-1,{info}\n{url}\n") + return f"Playlist created: {filename}" + +@app.route("/playlists/") +def serve_playlist(filename): + return send_from_directory(PLAYLIST_DIR, filename) + +if __name__ == "__main__": + app.run(debug=True) diff --git a/tv/playlists/placeholder.txt b/tv/playlists/placeholder.txt new file mode 100644 index 0000000..5e05e74 --- /dev/null +++ b/tv/playlists/placeholder.txt @@ -0,0 +1 @@ +placeholder diff --git a/tv/requirements.txt b/tv/requirements.txt new file mode 100644 index 0000000..8ab6294 --- /dev/null +++ b/tv/requirements.txt @@ -0,0 +1 @@ +flask \ No newline at end of file diff --git a/tv/templates/index.html b/tv/templates/index.html new file mode 100644 index 0000000..ee21726 --- /dev/null +++ b/tv/templates/index.html @@ -0,0 +1,122 @@ + + + + + + Create Playlist + + + + +
+

Select Channels to Create a New Playlist

+
+ + + +
+ {% for name, info, url in channels %} +
+
+ {{ name }} +
+ +
+
+
+ {% endfor %} +
+ +
+
+ + \ No newline at end of file