The Serie Extractor module specializes in extracting structured data from TV series pages, including series metadata and complete episode listings organized by seasons.
from backend.extractors.serie_extractor import extraer_episodios_serieresultado = extraer_episodios_serie("https://example.com/serie/breaking-bad/")print(f"Serie: {resultado['info']['titulo']}")print(f"Géneros: {', '.join(resultado['info']['generos'])}")print(f"Total de episodios: {len(resultado['episodios'])}")for ep in resultado['episodios'][:5]: print(f"S{ep['temporada']:02d}E{ep['episodio']:02d} - {ep['titulo']}")# Output:# Serie: Breaking Bad# Géneros: Crime, Drama, Thriller# Total de episodios: 62# S01E01 - Pilot# S01E02 - Cat's in the Bag...# S01E03 - ...And the Bag's in the River# S01E04 - Cancer Man# S01E05 - Gray Matter
The function uses a robust fallback mechanism for title extraction:
First attempts: div.data h1
Fallback: h1.entry-title
Default: Empty string
titulo = ''titulo_data = soup.select_one('div.data h1')if titulo_data: titulo = titulo_data.text.strip()else: titulo_alt = soup.select_one('h1.entry-title') titulo = titulo_alt.text.strip() if titulo_alt else ''
if poster_img: imagen_poster = poster_img.get('data-src') or poster_img.get('data-lazy-src') or poster_img.get('src', '') if 'data:image' in imagen_poster: noscript = soup.select_one('div.poster noscript img') if noscript: imagen_poster = noscript.get('src', imagen_poster)if not imagen_poster or 'data:image' in imagen_poster: og_image = soup.find('meta', property='og:image') if og_image: imagen_poster = og_image.get('content', imagen_poster)
The premiere date is intelligently extracted from the first episode’s air date:
fechas_episodios = []for episodio in episodios: fecha = episodio.select_one('.date').text.strip() if episodio.select_one('.date') else '' if fecha: fechas_episodios.append(fecha)fecha_estreno = fechas_episodios[0] if fechas_episodios else ''
from backend.extractors.serie_extractor import extraer_episodios_seriefrom datetime import datetimedata = extraer_episodios_serie("https://example.com/serie/the-walking-dead/")# Get the latest seasonlatest_season = max(ep['temporada'] for ep in data['episodios'])latest_episodes = [ep for ep in data['episodios'] if ep['temporada'] == latest_season]print(f"Season {latest_season} has {len(latest_episodes)} episodes:")for ep in latest_episodes: print(f" E{ep['episodio']:02d}: {ep['titulo']} - {ep['fecha']}")