forked from kenzuya/unshackle
feat(providers): fill the AniList ID of a TMDB or TVDB match from the anime-lists ID map
This commit is contained in:
@@ -16,6 +16,8 @@ search_metadata = providers.search_metadata
|
||||
ANIME_MAP = {
|
||||
"21": {"imdb": "tt0388629", "tmdb_tv": 37854, "tvdb": 81797},
|
||||
"199": {"imdb": "tt0245429", "tmdb_movie": 129},
|
||||
"16498": {"tmdb_tv": 1429, "tvdb": 267440, "tmdb_season": 1, "tvdb_season": 1},
|
||||
"20958": {"tmdb_tv": 1429, "tvdb": 267440, "tmdb_season": 2, "tvdb_season": 2},
|
||||
}
|
||||
|
||||
|
||||
@@ -415,18 +417,117 @@ def test_a_supplied_western_id_wins_over_the_map(monkeypatch: pytest.MonkeyPatch
|
||||
assert result.external_ids == ExternalIds(tvdb_id=1, anilist_id=21)
|
||||
|
||||
|
||||
class AniListHit(FakeProvider):
|
||||
class SearchHit(FakeProvider):
|
||||
def search(self, title: str, year: int | None, kind: str) -> MetadataResult | None:
|
||||
return anilist_hit()
|
||||
return self._result
|
||||
|
||||
|
||||
def test_a_search_hit_on_anilist_takes_the_mapped_western_ids(
|
||||
monkeypatch: pytest.MonkeyPatch, anime_map: list[bool]
|
||||
) -> None:
|
||||
monkeypatch.setattr(config, "disable_metadata", False)
|
||||
monkeypatch.setattr(providers, "provider_order", lambda *a: [lambda: AniListHit("anilist")])
|
||||
monkeypatch.setattr(providers, "provider_order", lambda *a: [lambda: SearchHit("anilist", anilist_hit())])
|
||||
|
||||
result = search_metadata("One Piece", None, "tv")
|
||||
|
||||
assert result is not None
|
||||
assert result.external_ids == ExternalIds("tt0388629", 37854, "tv", 81797, 21)
|
||||
|
||||
|
||||
def western_hit(language: str | None = "ja", kind: str = "tv", **ids: Any) -> MetadataResult:
|
||||
ids = {"tmdb_id": 37854, "tmdb_kind": kind, **ids}
|
||||
return MetadataResult(title="One Piece", kind=kind, original_language=language, external_ids=ExternalIds(**ids))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("hit", "kind", "anime", "season", "expected"),
|
||||
[
|
||||
(western_hit(), "tv", False, None, 21),
|
||||
(western_hit("jpn"), "tv", False, None, 21),
|
||||
(western_hit(None), "tv", True, None, 21),
|
||||
(western_hit(tmdb_id=1429), "tv", False, 2, 20958),
|
||||
(western_hit(tmdb_id=1429), "tv", False, None, None),
|
||||
(western_hit(tmdb_id=129, kind="movie"), "movie", False, None, 199),
|
||||
(western_hit(tmdb_kind="movie"), "tv", False, None, None),
|
||||
(
|
||||
MetadataResult(kind="movie", original_language="ja", external_ids=ExternalIds(tmdb_id=37854)),
|
||||
"tv",
|
||||
False,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
(western_hit(anilist_id=7), "tv", False, None, 7),
|
||||
],
|
||||
ids=[
|
||||
"ja",
|
||||
"alpha-3",
|
||||
"anime-run",
|
||||
"season",
|
||||
"no-season",
|
||||
"movie",
|
||||
"movie-id-on-tv",
|
||||
"movie-match-for-tv",
|
||||
"own-anilist-id-kept",
|
||||
],
|
||||
)
|
||||
def test_a_western_match_takes_its_mapped_anilist_id(
|
||||
anime_map: list[bool], hit: MetadataResult, kind: str, anime: bool, season: int | None, expected: int | None
|
||||
) -> None:
|
||||
providers.fill_anilist_id(hit, kind, anime, season)
|
||||
|
||||
assert hit.external_ids.anilist_id == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hit",
|
||||
[western_hit("en"), western_hit(None), western_hit(anilist_id=7), western_hit(tmdb_id=None, tmdb_kind=None)],
|
||||
ids=["english", "no-language", "has-anilist-id", "no-western-id"],
|
||||
)
|
||||
def test_a_match_outside_anime_never_reads_the_map(anime_map: list[bool], hit: MetadataResult) -> None:
|
||||
providers.fill_anilist_id(hit, "tv")
|
||||
|
||||
assert anime_map == []
|
||||
|
||||
|
||||
def test_the_tagging_lookup_picks_the_anilist_entry_of_the_season(
|
||||
monkeypatch: pytest.MonkeyPatch, anime_map: list[bool]
|
||||
) -> None:
|
||||
patch_providers(monkeypatch, {"tmdb": FakeProvider("tmdb", western_hit(tmdb_id=1429))})
|
||||
|
||||
result = providers.resolve_by_ids(1429, kind="tv", prefer="tmdb", season=2)
|
||||
|
||||
assert result is not None
|
||||
assert result.external_ids.anilist_id == 20958
|
||||
|
||||
|
||||
def test_a_supplied_anilist_id_wins_over_the_mapped_one(monkeypatch: pytest.MonkeyPatch, anime_map: list[bool]) -> None:
|
||||
patch_providers(monkeypatch, {"tmdb": FakeProvider("tmdb", western_hit(tmdb_id=1429))})
|
||||
|
||||
result = providers.resolve_by_ids(1429, anilist_id=16498, kind="tv", prefer="tmdb", season=2)
|
||||
|
||||
assert result is not None
|
||||
assert result.external_ids.anilist_id == 16498
|
||||
|
||||
|
||||
def test_a_search_hit_on_tmdb_takes_the_mapped_anilist_id(
|
||||
monkeypatch: pytest.MonkeyPatch, anime_map: list[bool]
|
||||
) -> None:
|
||||
monkeypatch.setattr(config, "disable_metadata", False)
|
||||
monkeypatch.setattr(providers, "provider_order", lambda *a: [lambda: SearchHit("tmdb", western_hit())])
|
||||
monkeypatch.setattr(providers, "search_metadata", search_metadata)
|
||||
|
||||
result = providers.resolve_by_ids(title="One Piece", kind="tv")
|
||||
|
||||
assert result is not None
|
||||
assert result.external_ids == ExternalIds(None, 37854, "tv", None, 21)
|
||||
|
||||
|
||||
def test_the_tagging_search_picks_the_anilist_entry_of_the_season(
|
||||
monkeypatch: pytest.MonkeyPatch, anime_map: list[bool]
|
||||
) -> None:
|
||||
monkeypatch.setattr(providers, "search_metadata", lambda *a, **kw: western_hit(tmdb_id=1429))
|
||||
|
||||
result = providers.resolve_by_ids(title="EXAMPLE", kind="tv", season=2)
|
||||
|
||||
assert result is not None
|
||||
assert result.external_ids.anilist_id == 20958
|
||||
|
||||
Reference in New Issue
Block a user