Сезоны и эпизоды в графе, график десятилетий на панели
Сериалы разложены до сезонов: сериал → сезон «содержит» с числом эпизодов, сезон → эпоха. Данные из Sonarr (/api/v3/episode?seriesId), агрегация по номеру сезона. 19 сезонных карточек, граф 486/530. Команда «сезоны Foundation» и GET /seasons. На панели — график «фантастика по десятилетиям» с полосками. Ловушка: выходящие сериалы дают неполные сезоны (Foundation, сезон 4 — 1 эпизод), из-за чего счётчик сезонов завышен.
This commit is contained in:
1 parent
d58a1b1e3b
commit
ea5a211d7e
5 files changed
+176
No files matched your search
@@ -96,6 +96,28 @@ def series():
|
||||
out = []
|
||||
for x in data or []:
|
||||
seasons = len([y for y in (x.get("seasons") or []) if (y.get("seasonNumber") or 0) > 0])
|
||||
eps, err2 = get(f"{url}/api/v3/episode?seriesId={x.get('id')}", {"X-Api-Key": key})
|
||||
by_season = {}
|
||||
for e in (eps or []):
|
||||
sn = e.get("seasonNumber")
|
||||
if not sn or sn <= 0:
|
||||
continue
|
||||
item = by_season.setdefault(sn, {"episodes": 0, "aired": 0, "years": set()})
|
||||
item["episodes"] += 1
|
||||
ad = e.get("airDateUtc") or ""
|
||||
if ad:
|
||||
item["aired"] += 1
|
||||
item["years"].add(ad[:4])
|
||||
seasons_info = []
|
||||
for sn in sorted(by_season):
|
||||
info = by_season[sn]
|
||||
years = sorted(info["years"])
|
||||
seasons_info.append({
|
||||
"season": sn,
|
||||
"episodes": info["episodes"],
|
||||
"aired": info["aired"],
|
||||
"year": years[0] if years else None,
|
||||
})
|
||||
raw_title = x.get("title") or ""
|
||||
clean = re.sub(r"\s*\(\d{4}\)\s*$", "", raw_title).strip() or raw_title
|
||||
out.append({
|
||||
@@ -103,6 +125,7 @@ def series():
|
||||
"tvdb": x.get("tvdbId"), "genres": x.get("genres") or [],
|
||||
"network": x.get("network"), "seasons": seasons,
|
||||
"status": x.get("status"),
|
||||
"seasons_info": seasons_info,
|
||||
})
|
||||
return out
|
||||
|
||||
@@ -134,6 +157,15 @@ print(json.dumps(rows, ensure_ascii=False))
|
||||
return []
|
||||
|
||||
|
||||
def plural_ep(n):
|
||||
n = int(n or 0)
|
||||
if n % 10 == 1 and n % 100 != 11:
|
||||
return str(n) + " эпизод"
|
||||
if n % 10 in (2, 3, 4) and n % 100 not in (12, 13, 14):
|
||||
return str(n) + " эпизода"
|
||||
return str(n) + " эпизодов"
|
||||
|
||||
|
||||
def decade(year):
|
||||
try:
|
||||
y = int(year)
|
||||
@@ -264,6 +296,18 @@ def main():
|
||||
if dec:
|
||||
link(sid, card("эпоха", "decade:" + dec, dec), "снят в")
|
||||
|
||||
for x in sr:
|
||||
sid = ids.get("sonarr:" + str(x["tvdb"]))
|
||||
for info in x.get("seasons_info") or []:
|
||||
s_key = "season:" + str(x["tvdb"]) + ":" + str(info["season"])
|
||||
scard = card("сезон", s_key, x["title"] + " — сезон " + str(info["season"]),
|
||||
plural_ep(info["episodes"]))
|
||||
link(sid, scard, "содержит")
|
||||
if info.get("year"):
|
||||
dec = decade(info["year"])
|
||||
if dec:
|
||||
link(scard, card("эпоха", "decade:" + dec, dec), "снят в")
|
||||
|
||||
# похожие сериалы по жанрам
|
||||
made_s = 0
|
||||
for i, a in enumerate(sr):
|
||||
|
||||
Reference in new issue
Block a user