feat: surface availability, airing progress and the director in preview
Movies get a theatre/stream/blu-ray icon in the info row, series get the latest aired episode as S03 E07. Both reveal the relevant dates on hover or tap through a shared Hint tooltip. Release dates ride along on the details request via append_to_response and the series fields are already in the tv payload, so neither indicator costs an extra call. Theatre state is only claimed while the run can still be current, otherwise a classic with no digital entry would read as in cinemas. The credits carousel now opens with the director, read from the crew array that the credits response already carries. A series has no single director, so the one behind most episodes stands in. Drop with_cast from the starring query: TMDB ANDs it with with_people, so every director link would have resolved to an empty list. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a25252c66d
commit
6fc41c0901
11 files changed
+310
-10
No files matched your search
@@ -0,0 +1,45 @@
|
||||
// TMDB release types: 1 premiere, 2 limited theatrical, 3 theatrical, 4 digital, 5 physical, 6 TV
|
||||
const STATE_BY_RELEASE_TYPE: Record<number, AvailabilityState> = {
|
||||
1: 'theatre',
|
||||
2: 'theatre',
|
||||
3: 'theatre',
|
||||
4: 'stream',
|
||||
5: 'bluray'
|
||||
};
|
||||
|
||||
/** How long a movie is assumed to still be running in theatres when TMDB has no digital/physical date yet */
|
||||
const THEATRICAL_WINDOW = 120 * 24 * 60 * 60 * 1000;
|
||||
|
||||
export const mapReleaseDatesToAvailability = (results?: TMDBCountryReleaseDates[]): Availability | undefined => {
|
||||
// TMDB reports dates per country, it doesn't matter where a window opened first — only when
|
||||
const availability = (results || []).reduce<Availability>((dates, { release_dates }) => {
|
||||
(release_dates || []).forEach(({ type, release_date }) => {
|
||||
const state = STATE_BY_RELEASE_TYPE[type];
|
||||
const earliest = state && dates[state];
|
||||
|
||||
if (!state || !release_date) return;
|
||||
if (!earliest || release_date < earliest) dates[state] = release_date;
|
||||
});
|
||||
|
||||
return dates;
|
||||
}, {});
|
||||
|
||||
return Object.keys(availability).length ? availability : undefined;
|
||||
};
|
||||
|
||||
export const isUpcoming = (date?: string) => Boolean(date && Date.parse(date) > Date.now());
|
||||
|
||||
const isReleased = (date?: string) => Boolean(date && Date.parse(date) <= Date.now());
|
||||
|
||||
export const getAvailabilityState = ({ theatre, stream, bluray }: Availability): AvailabilityState | undefined => {
|
||||
if (isReleased(bluray)) return 'bluray';
|
||||
if (isReleased(stream)) return 'stream';
|
||||
if (isUpcoming(theatre)) return 'theatre';
|
||||
if (!theatre) return undefined;
|
||||
|
||||
// Still in theatres only while the run lasts or while a digital/physical date is announced but not reached,
|
||||
// otherwise TMDB simply never got the digital entry and the movie is long out of cinemas
|
||||
const isRunning = Date.now() - Date.parse(theatre) < THEATRICAL_WINDOW;
|
||||
|
||||
return isRunning || isUpcoming(stream) || isUpcoming(bluray) ? 'theatre' : 'stream';
|
||||
};
|
||||
Reference in new issue
Block a user