Plex only builds the `Guid` array for the Plex Movie / Plex TV Series agents. A library still on a legacy agent answers with the scalar `guid` alone, so `fetchExternalIds` returned nothing for it and every consumer went quiet: trackers logged "no external IDs" and skipped the write, manual ratings showed "Not available", the detail screen dropped its watchlist button, and Continue Watching stopped collapsing duplicate copies. The reverse lookup already read that scalar; only the forward path ignored it. Read both shapes from the one request the method already makes, with the array winning per field and the scalar filling the rest. HAMA identifies anime by AniDB id and nothing else, which no id set could carry. AniDB is the Fribb mapping's own primary key, so it now travels on `ExternalIds` and indexes those rows directly — 7177 of them expose no tvdb/tmdb/imdb at all and were unreachable by any other path. Only plain `anidb-` maps: `anidb2`..`anidb9` group several AniDB entries under one TVDB-numbered show, so the guid names the root entry only. Two guards keep the new id where it means something. It is trusted for season 1, because that mode puts the anime there and its specials in season 0, while a higher season means the library is numbered by TVDB instead. And it resolves nothing for Trakt and Simkl, which never map anime and cannot address an AniDB id, so they keep reporting no ids rather than failing silently further down. `hasCatalogIds` marks the callers that can only speak IMDb/TMDB/TVDB. close #1788
91 lines
3.0 KiB
Dart
91 lines
3.0 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:plezy/services/trackers/fribb_mapping_store.dart';
|
|
|
|
void main() {
|
|
group('parseFribbIndex', () {
|
|
test('parses the current anime-list-mini schema and fans out every id', () {
|
|
// imdb_id is an array; themoviedb_id is {"movie": [...]} (multiple ids).
|
|
final index = parseFribbIndex('''
|
|
[
|
|
{
|
|
"type": "MOVIE",
|
|
"anidb_id": 7,
|
|
"mal_id": 100,
|
|
"anilist_id": 101,
|
|
"simkl_id": 102,
|
|
"imdb_id": ["tt0286390", "tt1"],
|
|
"themoviedb_id": {"movie": [10, 11]},
|
|
"tvdb_id": 81797,
|
|
"season": {"tvdb": 1, "tmdb": 2}
|
|
},
|
|
{
|
|
"type": "TV",
|
|
"anidb_id": 8,
|
|
"mal_id": 200,
|
|
"imdb_id": "tt2",
|
|
"themoviedb_id": {"tv": 456},
|
|
"tvdb_id": 555
|
|
}
|
|
]
|
|
''');
|
|
|
|
final movie = index.byTvdb[81797]!.single;
|
|
expect(movie.malId, 100);
|
|
expect(movie.anilistId, 101);
|
|
expect(movie.simklId, 102);
|
|
expect(movie.isMovie, isTrue);
|
|
expect(movie.imdbIds, ['tt0286390', 'tt1']);
|
|
expect(movie.tmdbIds, [10, 11]);
|
|
// season object still resolves via the readValue helpers.
|
|
expect(movie.tvdbSeason, 1);
|
|
expect(movie.tmdbSeason, 2);
|
|
|
|
// Movie row is indexed under every tmdb id and every imdb id.
|
|
expect(index.byTmdb[10]!.single, same(movie));
|
|
expect(index.byTmdb[11]!.single, same(movie));
|
|
expect(index.byImdb['tt0286390']!.single, same(movie));
|
|
expect(index.byImdb['tt1']!.single, same(movie));
|
|
|
|
// {"tv": id} flattens to a single-element list; legacy flat imdb string
|
|
// is wrapped into a list.
|
|
final tv = index.byTvdb[555]!.single;
|
|
expect(tv.tmdbIds, [456]);
|
|
expect(tv.imdbIds, ['tt2']);
|
|
expect(index.byTmdb[456]!.single, same(tv));
|
|
expect(index.byImdb['tt2']!.single, same(tv));
|
|
|
|
// AniDB is the dataset's primary key, so it indexes to a single row —
|
|
// the only handle a HAMA-matched Plex library can offer (#1788).
|
|
expect(index.byAnidb[7], same(movie));
|
|
expect(index.byAnidb[8], same(tv));
|
|
});
|
|
|
|
test('an unexpected field shape yields null fields, not a whole-parse crash', () {
|
|
final index = parseFribbIndex('''
|
|
[
|
|
{"type": ["TV"], "imdb_id": 123, "themoviedb_id": "garbage", "tvdb_id": 999, "mal_id": 1},
|
|
{"type": "TV", "imdb_id": ["tt9"], "themoviedb_id": {"tv": 42}, "tvdb_id": 1000, "mal_id": 2}
|
|
]
|
|
''');
|
|
|
|
// First row: every odd field coerces to null but the row still parses and
|
|
// is indexed by its (valid) tvdb id.
|
|
final weird = index.byTvdb[999]!.single;
|
|
expect(weird.type, isNull);
|
|
expect(weird.imdbIds, isNull);
|
|
expect(weird.tmdbIds, isNull);
|
|
expect(weird.malId, 1);
|
|
|
|
// Second, well-formed row is unaffected.
|
|
expect(index.byTvdb[1000]!.single.malId, 2);
|
|
expect(index.byTmdb[42]!.single.malId, 2);
|
|
expect(index.byImdb['tt9']!.single.malId, 2);
|
|
});
|
|
|
|
test('returns an empty index for a non-list payload', () {
|
|
final index = parseFribbIndex('{"not": "a list"}');
|
|
expect(index.isEmpty, isTrue);
|
|
});
|
|
});
|
|
}
|