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>
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { type ClassValue, clsx } from 'clsx';
|
|
import { twMerge } from 'tailwind-merge';
|
|
|
|
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));
|
|
|
|
// TMDB dates are UTC midnight, formatting them in the local zone would shift them a day back
|
|
export const formatDate = (date: string) =>
|
|
new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric', timeZone: 'UTC' })
|
|
.format(new Date(date))
|
|
.replace(/\//g, '.');
|
|
|
|
export const createUniqueRandomGenerator = (max: number) => {
|
|
const numbers = Array.from({ length: max }, (_, i) => i + 1);
|
|
|
|
for (let i = numbers.length - 1; i > 0; i--) {
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
[numbers[i], numbers[j]] = [numbers[j], numbers[i]];
|
|
}
|
|
|
|
let index = 0;
|
|
|
|
return () => {
|
|
if (index >= numbers.length) {
|
|
index = 0;
|
|
}
|
|
|
|
return numbers[index++];
|
|
};
|
|
};
|
|
|
|
export const getMagnetHash = (link: string) => {
|
|
const [, hash] = link.match(/btih:([A-Fa-f0-9]{40}|[A-Za-z0-9]{32})/) || [];
|
|
return hash?.toUpperCase();
|
|
};
|
|
|
|
export const formatBytes = (bytes?: number) => {
|
|
if (bytes == null || !isFinite(bytes)) return '';
|
|
|
|
const units = ['B', 'KB', 'MB', 'GB', 'TB'] as const;
|
|
|
|
let i = 0;
|
|
let v = bytes;
|
|
|
|
while (v >= 1024 && i < units.length - 1) {
|
|
v /= 1024;
|
|
i++;
|
|
}
|
|
|
|
return `${v.toFixed(v < 10 && i > 0 ? 1 : 0)} ${units[i]}`;
|
|
};
|
|
|
|
export const detectSafari = () => {
|
|
const ua = navigator.userAgent;
|
|
const isSafari = ua.includes('Safari') && !ua.includes('Chrome') && !ua.includes('CriOS') && !ua.includes('FxiOS');
|
|
|
|
const isIOS = /iPad|iPhone|iPod/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
|
|
|
|
return { isSafari, isIOS };
|
|
};
|
|
|
|
export const isStandaloneApp = () => window.matchMedia('screen and (display-mode: standalone)').matches;
|