plex und threadfin
This commit is contained in:
1 parent
66e53b4be4
commit
fcb87cf881
7 files changed
+223
-42
No files matched your search
+80
-35
@@ -1,6 +1,7 @@
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
# --- KONFIGURATION ---
|
||||
JELLYFIN_URL = "http://localhost:8096" # Oder 192.168.188.124
|
||||
@@ -9,7 +10,7 @@ EPG_PATH = "/home/sandro/m3u/sky_epg.xml"
|
||||
ID_FILE = "last_provider_id.txt" # Lokaler Cache für die ID
|
||||
|
||||
HEADERS = {
|
||||
"X-Emby-Token": API_KEY,
|
||||
"Authorization": 'Mediabrowser Token="' + API_KEY + '"',
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
@@ -17,9 +18,9 @@ def get_provider_id():
|
||||
"""Versucht die ID des XMLTV-Providers von Jellyfin zu holen."""
|
||||
try:
|
||||
# Liste aller Live-TV Provider abfragen
|
||||
response = requests.get(f"{JELLYFIN_URL}/LiveTv/ListingProviders", headers=HEADERS)
|
||||
response = requests.get(f"{JELLYFIN_URL}/System/Configuration/livetv", headers=HEADERS)
|
||||
response.raise_for_status()
|
||||
providers = response.json().get("Listings", [])
|
||||
providers = response.json().get("ListingProviders", [])
|
||||
|
||||
# Suche den Provider, der unseren Pfad nutzt
|
||||
for p in providers:
|
||||
@@ -38,6 +39,7 @@ def sync_jellyfin_epg():
|
||||
# 1. ID finden (aus API oder Cache)
|
||||
provider_id = get_provider_id()
|
||||
|
||||
|
||||
# 2. Wenn ID vorhanden, alten Provider löschen
|
||||
if provider_id:
|
||||
print(f"Lösche Provider mit ID: {provider_id}")
|
||||
@@ -46,40 +48,83 @@ def sync_jellyfin_epg():
|
||||
except Exception as e:
|
||||
print(f"Löschen fehlgeschlagen (evtl. schon weg): {e}")
|
||||
|
||||
# 3. Provider neu anlegen
|
||||
print(f"Lege Provider neu an für: {EPG_PATH}")
|
||||
payload = {
|
||||
"Type": "xmltv",
|
||||
"Path": EPG_PATH,
|
||||
"MoviePrefix": None,
|
||||
"UserAgent": None,
|
||||
"MovieCategories": [],
|
||||
"KidsCategories": [],
|
||||
"NewsCategories": [],
|
||||
"SportsCategories": ["sports"],
|
||||
"EnableAllTuners": True,
|
||||
"EnabledTuners": []
|
||||
}
|
||||
with open("/home/sandro/m3u/sky_epg.xml","r") as epg_file:
|
||||
epg_file_content = epg_file.read()
|
||||
if "<title>None</title>" not in epg_file_content:
|
||||
# 3. Provider neu anlegen
|
||||
print(f"Lege Provider neu an für: {EPG_PATH}")
|
||||
payload = {
|
||||
"Type": "xmltv",
|
||||
"Path": EPG_PATH,
|
||||
"MoviePrefix": None,
|
||||
"UserAgent": None,
|
||||
"MovieCategories": [],
|
||||
"KidsCategories": [],
|
||||
"NewsCategories": [],
|
||||
"SportsCategories": ["sports"],
|
||||
"EnableAllTuners": True,
|
||||
"EnabledTuners": []
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(f"{JELLYFIN_URL}/LiveTv/ListingProviders?ValidateListings=true",
|
||||
headers=HEADERS, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
# Die neue ID aus der Antwort holen und zwischenspeichern
|
||||
new_data = response.json()
|
||||
new_id = new_data.get("Id")
|
||||
|
||||
if new_id:
|
||||
with open(ID_FILE, "w") as f:
|
||||
f.write(new_id)
|
||||
print(f"Erfolgreich! Neue ID {new_id} im Cache gespeichert.")
|
||||
|
||||
# 4. Optional: Sofortigen Refresh der Daten triggern
|
||||
requests.post(f"{JELLYFIN_URL}/LiveTv/Refresh?api_key={API_KEY}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Fehler beim Neuerstellen: {e}")
|
||||
|
||||
def sync_threadfin_epg():
|
||||
url = "http://192.168.189.116:34400/api/"
|
||||
payload = {"cmd": "update.xmltv"}
|
||||
|
||||
print("🚀 Sende EPG-Update-Befehl an Threadfin...")
|
||||
try:
|
||||
# Das requests-Modul wandelt das dict mit 'json=' automatisch in ein sauberes JSON-Payload um
|
||||
response = requests.post(url, json=payload, timeout=10)
|
||||
response.raise_for_status() # Wirft einen Fehler bei HTTP-Codes wie 4xx oder 5xx
|
||||
|
||||
print(f"✅ Erfolgreich! Status: {response.status_code}")
|
||||
print(f"Antwort: {response.text}")
|
||||
# Kommandozeilen-Parameter definieren
|
||||
time.sleep(10)
|
||||
print(f"Wartezeit für Threadfin vorbei, weiter gehts")
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"❌ Fehler beim API-Aufruf: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
def sync_plex_epg():
|
||||
PLEX_IP = "192.168.188.124"
|
||||
PLEX_PORT = "32400"
|
||||
PLEX_DVR_ID = "16" # Deine DVR-ID (aus der XML)
|
||||
PLEX_TOKEN = "xnxczzsEyHyTN1BAveeq" # Dein Plex-Token
|
||||
|
||||
plex_url = f"http://{PLEX_IP}:{PLEX_PORT}/livetv/dvrs/{PLEX_DVR_ID}/reloadGuide?X-Plex-Token={PLEX_TOKEN}"
|
||||
|
||||
try:
|
||||
response = requests.post(f"{JELLYFIN_URL}/LiveTv/ListingProviders?ValidateListings=true",
|
||||
headers=HEADERS, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
# Die neue ID aus der Antwort holen und zwischenspeichern
|
||||
new_data = response.json()
|
||||
new_id = new_data.get("Id")
|
||||
|
||||
if new_id:
|
||||
with open(ID_FILE, "w") as f:
|
||||
f.write(new_id)
|
||||
print(f"Erfolgreich! Neue ID {new_id} im Cache gespeichert.")
|
||||
|
||||
# 4. Optional: Sofortigen Refresh der Daten triggern
|
||||
requests.post(f"{JELLYFIN_URL}/LiveTv/Refresh?api_key={API_KEY}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Fehler beim Neuerstellen: {e}")
|
||||
print("Sende Guide-Reload-Befehl an Plex...")
|
||||
res_plex = requests.post(plex_url, timeout=10)
|
||||
res_plex.raise_for_status()
|
||||
print(f"Plex erfolgreich getriggert (Status: {res_plex.status_code})")
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"Fehler beim API-Aufruf von Plex: {e}")
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sync_jellyfin_epg()
|
||||
sync_threadfin_epg()
|
||||
sync_plex_epg()
|
||||
Reference in new issue
Block a user