match series to tvdb: save series/media and season data
This commit is contained in:
1 parent
b875c1e193
commit
c52c83f7ff
1 file changed
+21
-9
@@ -4,9 +4,10 @@ import argparse
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
weight_jaccard = 0.5
|
weight_jaccard = 0.5
|
||||||
weight_fuzzy = 1 - weight_jaccard
|
weight_fuzzy = 1 - weight_jaccard
|
||||||
|
|
||||||
@@ -63,11 +64,18 @@ def get_all_episodes_by_tvdbid(tvdb_id: int):
|
|||||||
episodes = []
|
episodes = []
|
||||||
|
|
||||||
for season in series.get("seasons", []):
|
for season in series.get("seasons", []):
|
||||||
season_data = tvdb_get(
|
logger.info(f"Requesting Season: {season.get('number')}")
|
||||||
f"/seasons/{season['id']}/extended",
|
season_data = {}
|
||||||
{"language": "deu"},
|
try:
|
||||||
)["data"]
|
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", []):
|
for ep in season_data.get("episodes", []):
|
||||||
episodes.append(
|
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):
|
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")
|
logger.info("QUery from TVDB")
|
||||||
media_data = get_tvdbid_by_name(series_name)
|
media_data = get_tvdbid_by_name(series_name)
|
||||||
tvdb_id = int(media_data["tvdb_id"])
|
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")
|
logger.info("Dump to json")
|
||||||
with open(f"{series_name}_media_data.json", "w", encoding="utf-8") as f:
|
with open(f"{series_name}_media_data.json", "w", encoding="utf-8") as f:
|
||||||
json.dump(media_data, f, ensure_ascii=False, indent=2)
|
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:
|
with open(f"{series_name}_episodes.json", "w", encoding="utf-8") as f:
|
||||||
json.dump(episodes, f, ensure_ascii=False, indent=2)
|
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"
|
extra_episodes_path = series_path / "Extra Episodes"
|
||||||
|
|
||||||
for file in extra_episodes_path.iterdir():
|
for file in extra_episodes_path.iterdir():
|
||||||
|
|||||||
Reference in new issue
Block a user