Files
ygg-service/backend/alldebrid.py
2025-11-11 20:00:08 +01:00

40 lines
1.4 KiB
Python

import requests
import os
ALLDEBRID_API_KEY = os.getenv("ALLDEBRID_API_KEY", "mtrQI4h583rHe2ZpvpbC")
NTFY_TOPIC_URL = os.getenv("NTFY_TOPIC_URL", "https://ntfy.lucasroyer.fr/alldebrid")
NTFY_TOKEN = os.getenv("NTFY_TOKEN", "tk_qqi1ayj2a0etxafgicl0h7ww71ofb") # Ton token pour topic protégé
def check_alldebrid_status():
# Retourne True si premium actif, False sinon
try:
r = requests.get(
"https://api.alldebrid.com/v4/user",
params={"agent": "ygg-service", "apikey": ALLDEBRID_API_KEY},
timeout=5
)
data = r.json()
return data.get("data", {}).get("user", {}).get("isPremium", False)
except Exception as e:
print("Erreur AllDebrid:", e)
return False
def send_ntfy(title, message):
# Envoie une notification sur le topic ntfy, avec token si nécessaire
headers = {"Title": title}
if NTFY_TOKEN:
headers["Authorization"] = f"Bearer {NTFY_TOKEN}"
try:
r = requests.post(
NTFY_TOPIC_URL,
data=message.encode("utf-8"),
headers=headers,
timeout=5
)
if r.status_code not in (200, 201):
print(f"❌ Échec notification ({r.status_code}): {r.text}")
else:
print(f"✅ Notification envoyée : {title}")
except Exception as e:
print("Erreur ntfy:", e)