fix(media): a tvdb episode page is not the episode list
Tvdb's default episode query answers at most 500 rows and states no total. One Piece (1999), Crayon Shin-chan (1992) and Detective Conan (1996) each answer exactly 500 while holding over a thousand, so the contradiction rule added in the previous commit read every long-running show as contradicted: the pack books more episodes than "the authority holds", and the rule that exists to stop a wrong anime title would have stripped the right one from every file of the season. A capped list now records that it is capped (`tvdb:capped:<id>`, so a warm cache answers the same question a cold one did) and contradicts nothing; titles for the episodes the page does hold still ride. Test: a 500-row page with a 501-episode pack keeps ` - Episode 1` and lists no contradiction. Red before the change, proved in a copy of the tree with the cap raised past the fixture.
This commit is contained in:
1 parent
acab4cef22
commit
e4656cfd7a
3 files changed
+66
-15
No files matched your search
+34
-14
@@ -404,20 +404,37 @@ def tvdb_search(name):
|
||||
return None
|
||||
|
||||
|
||||
# Tvdb's default episode query answers AT MOST this many rows and states no
|
||||
# total: One Piece (1999), Crayon Shin-chan (1992) and Detective Conan (1996)
|
||||
# each answer exactly 500 while holding over a thousand. A list that long bounds
|
||||
# nothing above itself, so it must never be read as "the series holds 500".
|
||||
EPISODE_PAGE_CAP = 500
|
||||
|
||||
|
||||
def tvdb_episodes(sid):
|
||||
"""`season/episode` -> title for one series, in the one call tvdb answers."""
|
||||
"""`season/episode` -> title for one series, in the one call tvdb answers.
|
||||
Whether that call came back a cut-off page is recorded in the cache beside
|
||||
it, so a warm cache answers the same question a cold one did."""
|
||||
ck = f"tvdb:episodes:{sid}"
|
||||
if ck in CACHE:
|
||||
return CACHE[ck]
|
||||
data = tvdb(f"/series/{sid}/episodes/default")
|
||||
if not data:
|
||||
return None
|
||||
CACHE[ck] = {f"{e.get('seasonNumber')}/{e.get('number')}":
|
||||
(e.get("name") or "").strip()
|
||||
for e in data.get("episodes") or []}
|
||||
if ck not in CACHE:
|
||||
data = tvdb(f"/series/{sid}/episodes/default")
|
||||
if not data:
|
||||
return None
|
||||
rows = data.get("episodes") or []
|
||||
CACHE[ck] = {f"{e.get('seasonNumber')}/{e.get('number')}":
|
||||
(e.get("name") or "").strip() for e in rows}
|
||||
CACHE[f"tvdb:capped:{sid}"] = len(rows) >= EPISODE_PAGE_CAP
|
||||
return CACHE[ck]
|
||||
|
||||
|
||||
def tvdb_list_capped(sid):
|
||||
"""True when tvdb's episode answer for this series is a page, not a list."""
|
||||
rows = tvdb_episodes(sid)
|
||||
if not rows:
|
||||
return False
|
||||
return CACHE.get(f"tvdb:capped:{sid}", len(rows) >= EPISODE_PAGE_CAP)
|
||||
|
||||
|
||||
|
||||
# tvdb's titles read backwards, for the rows that carry a title and no numbering.
|
||||
_TITLE_IDX = {}
|
||||
@@ -757,14 +774,17 @@ def label_of(s):
|
||||
|
||||
def contradicted_seasons(s):
|
||||
"""Seasons whose numbering tvdb's own episode list contradicts — the one place
|
||||
a tvdb title can be a confident lie. An anime pack numbered by its release group
|
||||
books S05E01 in a season tvdb does not hold, or books more episodes there than
|
||||
tvdb lists, and the slot its number points at is a DIFFERENT episode. Books <=
|
||||
tvdb's count stays plausible: a partial pack is the normal shape."""
|
||||
a tvdb title can be a confident lie. An anime pack numbered by its release group
|
||||
books S05E01 in a season tvdb does not hold, or books more episodes there than
|
||||
tvdb lists, and the slot its number points at is a DIFFERENT episode. Books <=
|
||||
tvdb's count stays plausible: a partial pack is the normal shape. A list the
|
||||
authority cut off at its page limit (EPISODE_PAGE_CAP) contradicts nothing —
|
||||
it says nothing about the episodes it never sent."""
|
||||
if "contradicted" in s:
|
||||
return s["contradicted"]
|
||||
bad = set()
|
||||
eps = tvdb_episodes(s["tvdb"]) if s["tvdb"] else None
|
||||
eps = None if not s["tvdb"] or tvdb_list_capped(s["tvdb"]) \
|
||||
else tvdb_episodes(s["tvdb"])
|
||||
if eps:
|
||||
have = collections.Counter()
|
||||
for k in eps:
|
||||
|
||||
Reference in new issue
Block a user