From 9562ca4dc0246ec91cda8b02b80846dcff39ff52 Mon Sep 17 00:00:00 2001 From: ALQUDAH <3BOOD.ALQUDAH@GMAIL.COM> Date: Thu, 10 Jul 2025 21:23:31 +0400 Subject: [PATCH] Add Flask web app to play IPTV playlists --- .gitignore | 1 + README.md | 10 ++++++ webapp/app.py | 58 ++++++++++++++++++++++++++++++++++ webapp/requirements.txt | 1 + webapp/sample.m3u | 3 ++ webapp/templates/index.html | 17 ++++++++++ webapp/templates/player.html | 15 +++++++++ webapp/templates/playlist.html | 16 ++++++++++ 8 files changed, 121 insertions(+) create mode 100644 webapp/app.py create mode 100644 webapp/requirements.txt create mode 100644 webapp/sample.m3u create mode 100644 webapp/templates/index.html create mode 100644 webapp/templates/player.html create mode 100644 webapp/templates/playlist.html diff --git a/.gitignore b/.gitignore index 2cbb175..ea0eece 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.m3u .DS_Store *.pyc +!webapp/sample.m3u diff --git a/README.md b/README.md index 18ace62..a1bfc1c 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,16 @@ on Ubuntu/Debian `sudo apt-get install pyqt4-dev-tools` ![alt tag](screenshot/gui.png) +## How to use the Web App + +The repository now includes a small Flask application that can display and play +generated playlists through a browser. + +* `cd webapp` +* install the dependencies `pip install -r requirements.txt` +* run the application with `python app.py` +* open `http://localhost:5000` in your browser + ## Compatibility This program work on Window, Linux, Mac OSX and BSD. The only requirement is diff --git a/webapp/app.py b/webapp/app.py new file mode 100644 index 0000000..adf5b10 --- /dev/null +++ b/webapp/app.py @@ -0,0 +1,58 @@ +from flask import Flask, render_template, request, abort +import os + +app = Flask(__name__) + +# Directory that contains generated playlists +PLAYLIST_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'iptv', 'output') + + +def parse_m3u(path): + channels = [] + name = None + with open(path, 'r', errors='ignore') as f: + for line in f: + line = line.strip() + if not line: + continue + if line.startswith('#EXTINF'): + parts = line.split(',', 1) + if len(parts) > 1: + name = parts[1].strip() + elif line.startswith('#'): + continue + else: + url = line + channels.append({'name': name or url, 'url': url}) + name = None + return channels + + +@app.route('/') +def index(): + if not os.path.isdir(PLAYLIST_DIR): + playlists = [] + else: + playlists = [f for f in os.listdir(PLAYLIST_DIR) if f.endswith('.m3u') or f.endswith('.m3u8')] + return render_template('index.html', playlists=playlists) + + +@app.route('/playlist/') +def playlist(filename): + path = os.path.join(PLAYLIST_DIR, filename) + if not os.path.isfile(path): + abort(404) + channels = parse_m3u(path) + return render_template('playlist.html', playlist=filename, channels=channels) + + +@app.route('/play') +def play(): + url = request.args.get('url') + if not url: + abort(404) + return render_template('player.html', url=url) + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/webapp/requirements.txt b/webapp/requirements.txt new file mode 100644 index 0000000..e3e9a71 --- /dev/null +++ b/webapp/requirements.txt @@ -0,0 +1 @@ +Flask diff --git a/webapp/sample.m3u b/webapp/sample.m3u new file mode 100644 index 0000000..b65e492 --- /dev/null +++ b/webapp/sample.m3u @@ -0,0 +1,3 @@ +#EXTM3U +#EXTINF:-1,Sample Channel +https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8 diff --git a/webapp/templates/index.html b/webapp/templates/index.html new file mode 100644 index 0000000..3b28b9a --- /dev/null +++ b/webapp/templates/index.html @@ -0,0 +1,17 @@ + + + + + IPTV Web App + + +

Available Playlists

+ + + diff --git a/webapp/templates/player.html b/webapp/templates/player.html new file mode 100644 index 0000000..c8d16fc --- /dev/null +++ b/webapp/templates/player.html @@ -0,0 +1,15 @@ + + + + + Player + + +

Channel Player

+ +

Open stream directly

+

Home

+ + diff --git a/webapp/templates/playlist.html b/webapp/templates/playlist.html new file mode 100644 index 0000000..5603461 --- /dev/null +++ b/webapp/templates/playlist.html @@ -0,0 +1,16 @@ + + + + + {{ playlist }} + + +

{{ playlist }}

+ +

Back to playlists

+ +