Download app.py from TsunTzu/EB: direct link, hf CLI and curl.
- Browser
- Download file 3.28 kB
-
https://huggingface.co/spaces/TsunTzu/EB/resolve/main/app.py
- Command line
-
hf download hf://spaces/TsunTzu/EB/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TsunTzu/EB/resolve/main/app.py
3.28 kB
| from flask import Flask, render_template_string, request, redirect, session | |
| import os, subprocess | |
| app = Flask(__name__) | |
| app.secret_key = os.urandom(24) | |
| ADMIN_PASS = os.getenv("ADMIN_PASS", "admin123") | |
| HTML_TEMPLATE = ''' | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Media Manager</title> | |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css"> | |
| </head> | |
| <body class="container p-6 has-text-centered"> | |
| <h1 class="title">Emby Cloud Sync</h1> | |
| {% if not session.get('auth') %} | |
| <div class="box" style="max-width:400px; margin:auto;"> | |
| <form method="post" action="/login"> | |
| <label class="label">Admin Password</label> | |
| <input class="input mb-4" type="password" name="pw" placeholder="••••••••"> | |
| <button class="button is-link is-fullwidth">Login</button> | |
| </form> | |
| </div> | |
| {% else %} | |
| <div class="notification is-success is-light">System Ready (Ping-Pong Backup Active)</div> | |
| <div class="buttons is-centered"> | |
| <a href="/run-sync-only" class="button is-info is-large">🔄 Sync Media Only</a> | |
| <a href="/run-backup" class="button is-danger is-large">💾 Sync & Backup</a> | |
| <a href="/emby/" target="_blank" class="button is-success is-large">▶️ Open Emby</a> | |
| </div> | |
| <p class="help mt-4"><b>Sync Media Only:</b> Google Sheet မှ ဒေတာများကိုယူ၍ .strm ဖိုင်များသာ အသစ်ရေးမည်။</p> | |
| <p class="help"><b>Sync & Backup:</b> .strm ဖိုင်များကို အရင် Update လုပ်ပြီးမှ၊ Emby ကို Dataset (Primary/Secondary) သို့ Ping-Pong စနစ်ဖြင့် သိမ်းဆည်းမည်။</p> | |
| {% endif %} | |
| </body> | |
| </html> | |
| ''' | |
| def index(): return render_template_string(HTML_TEMPLATE) | |
| def login(): | |
| if request.form.get('pw') == ADMIN_PASS: session['auth'] = True | |
| return redirect('/') | |
| def run_sync_only(): | |
| if not session.get('auth'): return redirect('/') | |
| subprocess.run(["python3", "/sync.py"]) | |
| return "Media Sync Done! <a href='/'>Back to Dashboard</a>" | |
| def run_backup(): | |
| if not session.get('auth'): return redirect('/') | |
| subprocess.run(["python3", "/backup.py", "save"]) | |
| return "Media Sync & Config Backup Done! <a href='/'>Back to Dashboard</a>" | |
| def api_action(): | |
| token = request.args.get('token') | |
| action = request.args.get('type') | |
| if token == ADMIN_PASS: | |
| try: | |
| if action == "sync": | |
| subprocess.run(["python3", "/sync.py"]) | |
| return "Media Sync Complete!", 200 | |
| elif action == "backup": | |
| subprocess.run(["python3", "/backup.py", "save"]) | |
| return "Media Sync & Config Backup Complete!", 200 | |
| else: | |
| return "Invalid Action", 400 | |
| except Exception as e: | |
| return f"Error: {str(e)}", 500 | |
| else: | |
| return "Unauthorized", 401 | |
| if __name__ == "__main__": | |
| app.run(port=8080, host='0.0.0.0') |