Skip to content

Instantly share code, notes, and snippets.

@chemacortes
Last active October 13, 2025 11:28
Show Gist options
  • Select an option

  • Save chemacortes/8ad8698e2d3a4b0879de4006d6701021 to your computer and use it in GitHub Desktop.

Select an option

Save chemacortes/8ad8698e2d3a4b0879de4006d6701021 to your computer and use it in GitHub Desktop.
Usa la API de RTVE para encontrar el feed de un programa.
#!/bin/env python
import requests
import sys
if len(sys.argv) != 2:
print("Falta 1 argumento de entrada")
sys.exit(1)
arg = sys.argv[1]
npage = 0
while True:
npage = npage + 1
url = f"https://secure-api.rtve.es/api/programas.json?size=1000&page={npage}"
response = requests.get(url)
# Verificar si la respuesta es válida
if response.status_code == 200:
res = response.json()
if res["page"]["numElements"] == 0:
break
for item in res["page"]["items"]:
if arg.lower() in item.get("name", "").lower():
uri = item["uri"]
url = item["htmlUrl"]
fuera_de_emision = item["outOfEmission"]
emision = "FUERA DE EMISIÓN" if fuera_de_emision else "EN EMISIÓN"
response2 = requests.get(uri + "/audios.json")
res_audios = response2.json()
total = res_audios["page"]["total"]
if total > 0:
print("Título:", item["name"] + f" ({emision})")
print("ID:", item["id"])
print("Número de episodios:", total)
print("URI:", uri)
print("URL:", url)
if "/videos/" in url:
print("RSS:", f"{uri}/videos.rss")
elif "/audios/" in url:
print("RSS:", f"{uri}/audios.rss")
if total > 20:
print(" ", f"{uri}/audios.rss?size={total}")
print("Descripción:", item["description"])
print("...")
else:
print("Error al acceder a la API:", response.status_code)
break
@chemacortes
Copy link
Author

El RSS obtiene por defecto enlaces a los últimos 20 episodios. Si quieres acceder a todos añade el número como argumento:

https://www.rtve.es/api/programas/1889/audios.rss?size=1000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment