03-ago: [videoclub] enlaces directos RD en el listado y en la notificacion IDD

This commit is contained in:
juanjo
2026-08-03 23:36:51 +02:00
parent f452ece724
commit 54325ffaa7
3 changed files with 417 additions and 299 deletions

View File

@@ -72,20 +72,37 @@ def clean_filename(name):
def fetch_catalogo():
"""Descarga el catalogo y devuelve lista de items [{id,name,tipo,clean,year}]."""
"""Descarga el catalogo y devuelve lista de items [{id,name,tipo,clean,year,enlace}]."""
url = CATALOGO.format(config=config.TORRENTIO_CONFIG_WITH_TOKEN)
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(req, timeout=40) as r:
data = json.loads(r.read().decode("utf-8"))
# Enlaces directos de descarga de RealDebrid (1 sola llamada al listado)
enlaces = {}
try:
req2 = urllib.request.Request(
"https://api.real-debrid.com/rest/1.0/torrents",
headers={"Authorization": f"Bearer {config.TORRENTIO_RD_TOKEN}"})
with urllib.request.urlopen(req2, timeout=40) as r2:
for t in json.loads(r2.read().decode("utf-8")):
links = t.get("links") or []
if links:
enlaces[t["id"]] = links[0]
except Exception as e:
print(f"[RD] No se pudieron obtener enlaces: {e}")
items = []
for m in data.get("metas", []):
clean, year, tipo = clean_filename(m.get("name", ""))
rd_id = m.get("id", "").split(":", 1)[-1]
items.append({
"id": m.get("id"),
"name": m.get("name"),
"clean": clean,
"year": year,
"tipo": tipo,
"enlace": enlaces.get(rd_id),
})
return items
@@ -138,7 +155,8 @@ def generar_markdown(fecha, items, novedades):
for it in novedades:
marca = {"pelicula": "🎬", "serie": "📺", "adulto": "🔞", "otro": "📁"}.get(it["tipo"], "📁")
y = f" ({it['year']})" if it["year"] else ""
lineas.append(f"- {marca} {it['clean']}{y} `{it['name'][:60]}`")
link = f" `{it['enlace']}`" if it.get("enlace") else ""
lineas.append(f"- {marca} {it['clean']}{y}{link}")
lineas.append("")
for nombre, clave in [("Películas", "pelicula"), ("Series", "serie"),
("Adulto", "adulto"), ("Otros", "otro")]:
@@ -147,7 +165,8 @@ def generar_markdown(fecha, items, novedades):
lineas.append("")
for it in g[clave]:
y = f" ({it['year']})" if it["year"] else ""
lineas.append(f"- {it['clean']}{y}")
link = f" `{it['enlace']}`" if it.get("enlace") else ""
lineas.append(f"- {it['clean']}{y}{link}")
lineas.append("")
return "\n".join(lineas)