Files
plezy/lib/utils/country_codes.dart
edde746 27acbaf435 feat(explore): surface the catalog data providers already return
Explore shelf cards drew a poster, a title and a year. An audit of all six
catalog sources found the rest was lost at two boundaries — the wire-to-DTO
mapping and the DTO-to-CatalogItem mapping — and then simply not drawn: the
grid card fell through every branch of buildMetadataSubtitle to the year-only
case, while the list card used by search already composed certification,
runtime and rating from fields the synthesized MediaItem already held.

Extend CatalogItem with the neutral facts every provider had been dropping:
attributed rating sources, leaderboard ranks that keep their season window,
audience counters that keep their timeframe, broadcast slots, next-episode air
times, server availability and request state, exact release dates, alternate
titles, format, source material, studios, countries, languages, credits, tags,
links, artwork variants, play state, gallery art and background prose. Replace
fetchCast and fetchRelated with one fetchDetail returning the enriched item,
its cast, its recommendations and labelled franchise relations without adding
a request: sources needing two calls keep two and run them concurrently with
isolated failures.

Map those fields in all six sources, widening only field selections that cost
no extra round trip — MAL's fields list, AniList's selection set and a bounded
row cast that lets detail skip its character call, Trakt's guest stars, Seerr's
language parameter and TMDB size ladder, and Plex's includeUserState. Plex hub
artwork widens only on TV, where the spotlight is its only consumer, because it
doubles the payload.

Render them: a rating-first caption and bounded badges on the shelf card,
labelled sections on the detail screen, provider hub styles and result counts
on shelves, and logo, banner and accent art in the TV spotlight.

Verified against live Plex, AniList, Simkl and MAL responses, and on a Pixel 7.
2026-07-29 06:47:54 +02:00

43 lines
1.9 KiB
Dart

import '../data/iso_3166_data.dart';
/// Resolves ISO 3166-1 alpha-2 country codes to display names, mirroring
/// [LanguageCodes] for the country dimension.
///
/// Catalog providers return production countries as bare codes (Plex
/// `Country`, Simkl `country`, AniList `countryOfOrigin`, TMDB
/// `origin_country`). Names are English-only for the same reason the ISO 639
/// catalog is: no localized catalog ships with the app.
class CountryCodes {
/// Display name for [code], or the normalized code when it is not a known
/// alpha-2 value. Returning the code is deliberate — `SU` is more useful to
/// a reader than an empty chip.
static String getDisplayName(String code) => getCountryName(code) ?? code.toUpperCase().trim();
/// Display name for [code], or null when it is not a known alpha-2 value.
static String? getCountryName(String code) {
final normalized = code.toUpperCase().trim();
if (normalized.length != 2) return null;
return countryNames[normalized];
}
/// Alpha-2 code for a country [name], or null when unrecognized.
///
/// Providers are inconsistent about which side of this mapping they send:
/// Plex Discover returns `Country` tags as display names such as
/// `United States of America`, while TMDB and AniList send codes. The index
/// covers official ISO forms, the readable short forms, and colloquial
/// names.
static String? getCountryCode(String name) {
final normalized = name.trim();
if (normalized.isEmpty) return null;
if (normalized.length == 2 && countryNames.containsKey(normalized.toUpperCase())) {
return normalized.toUpperCase();
}
return countryCodesByName[normalized.toLowerCase()];
}
/// Best-effort alpha-2 for a provider value that may be either a code or a
/// name. Falls back to the trimmed uppercase input so nothing is dropped.
static String normalizeCode(String value) => getCountryCode(value) ?? value.toUpperCase().trim();
}