From c52c83f7ffbc144e373ee39f0170e5b3ad9bfdfd Mon Sep 17 00:00:00 2001 From: Lucas Media Date: Sun, 25 Oct 2026 14:24:05 +0100 Subject: [PATCH] match series to tvdb: save series/media and season data --- media_editing/match_series_to_tvdb.py | 30 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/media_editing/match_series_to_tvdb.py b/media_editing/match_series_to_tvdb.py index 8c924da..1af9aca 100755 --- a/media_editing/match_series_to_tvdb.py +++ b/media_editing/match_series_to_tvdb.py @@ -4,9 +4,10 @@ import argparse import json import logging import re -import sys from pathlib import Path +import requests + weight_jaccard = 0.5 weight_fuzzy = 1 - weight_jaccard @@ -63,11 +64,18 @@ def get_all_episodes_by_tvdbid(tvdb_id: int): episodes = [] for season in series.get("seasons", []): - season_data = tvdb_get( - f"/seasons/{season['id']}/extended", - {"language": "deu"}, - )["data"] - + logger.info(f"Requesting Season: {season.get('number')}") + season_data = {} + try: + season_data = tvdb_get( + f"/seasons/{season['id']}/extended", + {"language": "deu"}, + )["data"] + except requests.exceptions.RequestException: + logger.error( + "Failed to fetch season %s", + season["id"], + ) for ep in season_data.get("episodes", []): episodes.append( { @@ -78,7 +86,7 @@ def get_all_episodes_by_tvdbid(tvdb_id: int): } ) - return episodes + return series, episodes def parse_series_name(series_name: str): @@ -212,13 +220,17 @@ def process_series(series_path: Path, dry_run: bool = False): logger.info("QUery from TVDB") media_data = get_tvdbid_by_name(series_name) tvdb_id = int(media_data["tvdb_id"]) - episodes = get_all_episodes_by_tvdbid(tvdb_id) + series_data, episodes = get_all_episodes_by_tvdbid(tvdb_id) logger.info("Dump to json") with open(f"{series_name}_media_data.json", "w", encoding="utf-8") as f: json.dump(media_data, f, ensure_ascii=False, indent=2) + with open(f"{series_name}_series_data.json", "w", encoding="utf-8") as f: + json.dump(series_data, f, ensure_ascii=False, indent=2) with open(f"{series_name}_episodes.json", "w", encoding="utf-8") as f: json.dump(episodes, f, ensure_ascii=False, indent=2) - logger.info(f"Found series name {media_data['name']}") + logger.info( + f"Found series name from TVDB: {media_data['name']}, ID: {tvdb_id}, Year: {media_data.get('year')}" + ) extra_episodes_path = series_path / "Extra Episodes" for file in extra_episodes_path.iterdir():