File size: 3,281 Bytes
040a95f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | 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>
'''
@app.route('/')
def index(): return render_template_string(HTML_TEMPLATE)
@app.route('/login', methods=['POST'])
def login():
if request.form.get('pw') == ADMIN_PASS: session['auth'] = True
return redirect('/')
@app.route('/run-sync-only')
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>"
@app.route('/run-backup')
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>"
@app.route('/api/action', methods=['GET'])
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') |