diff --git a/main.py b/main.py index 31aff2d..e2278f9 100755 --- a/main.py +++ b/main.py @@ -9,8 +9,7 @@ import os import time import multiprocessing -from flask import request -from flask import jsonify +from flask import request, jsonify, send_from_directory from PyQt5.QtWidgets import * from PyQt5.QtCore import * @@ -486,199 +485,32 @@ def index(): grouped_channels.setdefault(channel["group"], []).append(channel) flat_channel_list = [channel for channel in channels] - - html = f""" - - - IPMPV - - - -

Welcome to IPMPV

-

Current Channel: {channels[current_index]['name'] if current_index is not None else "None"}

- - """ -# -# - - global deinterlace - global low_latency - deinterlace_state = "ON" if deinterlace else "OFF" - retroarch_state = "ON" if retroarch_p and retroarch_p.poll() is None else "OFF" - html += f""" - - - -

Toggle OSD

- - """ - html += f""" -

Play Custom URL

- -

All Channels

-
- """ - + + # Create the channel groups HTML + channel_groups_html = "" for group, ch_list in grouped_channels.items(): - html += f'
{group}' + channel_groups_html += f'
{group}' for channel in ch_list: index = flat_channel_list.index(channel) # Get correct global index - html += f''' + channel_groups_html += f'''
''' - html += '
' - - - html += """ -
- - - - """ - + channel_groups_html += '
' + + # Replace placeholders with actual values + html = open("templates/index.html").read() + html = html.replace("%CURRENT_CHANNEL%", channels[current_index]['name'] if current_index is not None else "None") + html = html.replace("%RETROARCH_STATE%", "ON" if retroarch_p and retroarch_p.poll() is None else "OFF") + html = html.replace("%RETROARCH_LABEL%", "Stop RetroArch" if retroarch_p and retroarch_p.poll() is None else "Start RetroArch") + html = html.replace("%DEINTERLACE_STATE%", "ON" if deinterlace else "OFF") + html = html.replace("%RESOLUTION%", resolution) + html = html.replace("%LATENCY_STATE%", "ON" if low_latency else "OFF") + html = html.replace("%LATENCY_LABEL%", "Lo" if low_latency else "Hi") + html = html.replace("%CHANNEL_GROUPS%", channel_groups_html) + return html def is_valid_url(url): @@ -765,7 +597,7 @@ def toggle_retroarch(): print("Launching RetroArch") retroarch_env = os.environ.copy() retroarch_env["MESA_GL_VERSION_OVERRIDE"] = "3.3" - retroarch_p = subprocess.Popen(re.split('\s', ipmpv_retroarch_cmd if ipmpv_retroarch_cmd is not None else 'retroarch'), env=retroarch_env) + retroarch_p = subprocess.Popen(re.split("\\s", ipmpv_retroarch_cmd if ipmpv_retroarch_cmd is not None else 'retroarch'), env=retroarch_env) return jsonify(state=True) @app.route("/toggle_latency") @@ -823,6 +655,22 @@ def toggle_resolution(): return jsonify(res=get_current_resolution()) +@app.route('/manifest.json') +def serve_manifest(): + return send_from_directory("static", 'manifest.json', + mimetype='application/manifest+json') + +# Serve icon files from root +@app.route('/icon512_rounded.png') +def serve_rounded_icon(): + return send_from_directory("static", 'icon512_rounded.png', + mimetype='image/png') + +@app.route('/icon512_maskable.png') +def serve_maskable_icon(): + return send_from_directory("static", 'icon512_maskable.png', + mimetype='image/png') + if __name__ == "__main__": # Start Qt process qt_proc = multiprocessing.Process(target=qt_process) diff --git a/static/icon512_maskable.png b/static/icon512_maskable.png new file mode 100644 index 0000000..0db1f7a Binary files /dev/null and b/static/icon512_maskable.png differ diff --git a/static/icon512_rounded.png b/static/icon512_rounded.png new file mode 100644 index 0000000..be2088f Binary files /dev/null and b/static/icon512_rounded.png differ diff --git a/static/manifest.json b/static/manifest.json new file mode 100644 index 0000000..0555cf9 --- /dev/null +++ b/static/manifest.json @@ -0,0 +1,27 @@ +{ + "theme_color":"#222222", + "background_color":"#222222", + "start_url": "/", + "icons": + [ + { + "purpose":"maskable", + "sizes":"512x512", + "src":"icon512_maskable.png", + "type":"image/png" + },{ + "purpose":"any", + "sizes":"512x512", + "src":"icon512_rounded.png", + "type":"image/png" + } + ], + "orientation":"any", + "display":"standalone", + "dir":"auto", + "lang":"en", + "name":"IPMPV", + "short_name":"IPMPV", + "description":"Remote control for your IPMPV instance", + "id":"cc.netpaws.ipmpv" +} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..848153c --- /dev/null +++ b/templates/index.html @@ -0,0 +1,474 @@ + + + + IPMPV + + + + + + + + +
+

Welcome to IPMPV

+

Current Channel: %CURRENT_CHANNEL%

+ +
+ + + + +
+ +
+

Toggle OSD

+
+ + +
+
+ +
+

Play Custom URL

+
+
+ + + +
+
+
+ +

All Channels

+
+ + %CHANNEL_GROUPS% +
+
+ + + + \ No newline at end of file