match series to tvdb: save series/media and season data
This commit is contained in:
1 parent
b875c1e193
commit
c52c83f7ff
1 file changed
+17
-5
@@ -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", []):
|
||||
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():
|
||||
|
||||
Reference in new issue
Block a user