diff --git a/tv/app.py b/app.py similarity index 96% rename from tv/app.py rename to app.py index 17906aa..b930eed 100644 --- a/tv/app.py +++ b/app.py @@ -1,58 +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) +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/playlists/placeholder.txt similarity index 92% rename from tv/playlists/placeholder.txt rename to playlists/placeholder.txt index 5e05e74..48cdce8 100644 --- a/tv/playlists/placeholder.txt +++ b/playlists/placeholder.txt @@ -1 +1 @@ -placeholder +placeholder diff --git a/tv/requirements.txt b/requirements.txt similarity index 100% rename from tv/requirements.txt rename to requirements.txt diff --git a/tv/templates/index.html b/templates/index.html similarity index 97% rename from tv/templates/index.html rename to templates/index.html index ee21726..5c31ef4 100644 --- a/tv/templates/index.html +++ b/templates/index.html @@ -1,122 +1,122 @@ - - - - - - Create Playlist - - - - -
-

Select Channels to Create a New Playlist

-
- - - -
- {% for name, info, url in channels %} -
-
- {{ name }} -
- -
-
-
- {% endfor %} -
- -
-
- + + + + + + Create Playlist + + + + +
+

Select Channels to Create a New Playlist

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