03-sep: [feature] catalogo por genero: /genero -> tipo -> genero -> 30 mas descargadas -> /torrents -> /bajar

This commit is contained in:
juanjo
2026-09-03 22:37:48 +02:00
parent 1ea1e6782f
commit aff68c3609
2 changed files with 156 additions and 1 deletions

View File

@@ -27,6 +27,15 @@ sys.path.insert(0, str(BASE))
CINEMETA = "https://v3-cinemeta.strem.io"
TORRENTIO = "https://torrentio.strem.fun/language=spanish"
# Catalogo por genero (Cinemeta). "top" = mas descargadas, "imdbRating" = mejor valoradas.
CINEMETA_CAT = "https://cinemeta-catalogs.strem.io"
CATEGORIAS = ("top", "imdbRating")
GENEROS = (
"Action", "Adventure", "Animation", "Biography", "Comedy", "Crime",
"Documentary", "Drama", "Family", "Fantasy", "History", "Horror",
"Mystery", "Romance", "Sci-Fi", "Sport", "Thriller", "War", "Western",
)
HEADERS = {"User-Agent": "Mozilla/5.0"}
# Utilidades de clasificacion reutilizadas de videoclub_buscador
@@ -117,6 +126,65 @@ def torrents_de(imdb_id, tipo="movie"):
return torrents
def generos_disponibles():
"""Devuelve la lista de generos con su numero (1-based) para el usuario."""
return list(enumerate(GENEROS, 1))
def catalogo_por_genero(tipo, genero, categoria="top", limite=30):
"""'las N mas descargadas/valoradas' de un genero y tipo.
tipo: movie|series. genero: nombre en ingles (Action, Horror...).
categoria: top (mas descargadas) | imdbRating (mejor valoradas).
Devuelve lista de {name, type, imdb_id, year}."""
if categoria not in CATEGORIAS:
categoria = "top"
if genero not in GENEROS:
return []
url = (f"{CINEMETA_CAT}/{categoria}/catalog/{tipo}/{categoria}/"
f"genre={urllib.parse.quote(genero)}&skip=0.json")
try:
metas = _get_json(url).get("metas", [])
except Exception:
return []
lista = []
for m in metas:
imdb = m.get("id", "")
if not re.match(r"^tt\d+$", imdb):
continue
name = m.get("name", "")
year = m.get("year") or m.get("releaseInfo") or None
lista.append({
"name": name,
"type": tipo,
"imdb_id": imdb,
"year": str(year) if year else None,
})
return lista[:limite]
def formatear_generos():
"""Numeros la lista de generos para elegir por numero en Telegram."""
lineas = ["🎭 <b>Elige un genero por numero:</b>", ""]
for n, g in generos_disponibles():
lineas.append(f"<b>{n}.</b> {g}")
return vcb.trocear_texto(lineas)
def formatear_catalogo(resultados, tipo, genero, categoria):
"""Numera los titulos de un catalogo por genero para elegir luego /torrents."""
if not resultados:
return [f"No hay resultados para <b>{genero}</b>."]
etiqueta = "🎬 Peliculas" if tipo == "movie" else "📺 Series"
orden = "mas descargadas" if categoria == "top" else "mejor valoradas"
lineas = [f"{etiqueta} · <b>{genero}</b> — {len(resultados)} {orden}:",
"Responde <b>/torrents &lt;numero&gt;</b> para ver torrents.", ""]
for i, r in enumerate(resultados, 1):
icono = "📺" if r["type"] == "series" else "🎬"
y = f" ({r['year']})" if r.get("year") else ""
lineas.append(f"<b>{i}.</b> {icono} {r['name']}{y}")
return vcb.trocear_texto(lineas)
def _seeders(title):
m = re.search(r"👤\s*(\d+)", title)
return int(m.group(1)) if m else 0
@@ -214,6 +282,8 @@ if __name__ == "__main__":
print("Uso:")
print(" python global_buscar.py busca <texto>")
print(" python global_buscar.py torrents <imdb_id> [movie|series]")
print(" python global_buscar.py generos")
print(" python global_buscar.py catalogo <movie|series> <genero> [top|imdbRating] [limite]")
sys.exit(1)
cmd = sys.argv[1]
@@ -230,3 +300,16 @@ if __name__ == "__main__":
for m in formatear_torrents(res, imdb):
print(m)
print("---")
elif cmd == "generos":
for m in formatear_generos():
print(m)
print("---")
elif cmd == "catalogo":
tipo = sys.argv[2]
genero = sys.argv[3]
cat = sys.argv[4] if len(sys.argv) > 4 else "top"
lim = int(sys.argv[5]) if len(sys.argv) > 5 else 30
res = catalogo_por_genero(tipo, genero, cat, lim)
for m in formatear_catalogo(res, tipo, genero, cat):
print(m)
print("---")