mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-12 23:33:43 +08:00
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { extractPlaybackQualityLabel } from '@/lib/utils/video';
|
|
|
|
export interface ResolutionBadge {
|
|
label: string;
|
|
color: string;
|
|
}
|
|
|
|
export interface ResolutionLike extends ResolutionBadge {
|
|
width?: number;
|
|
height?: number;
|
|
origin?: 'probed' | 'played' | 'hint';
|
|
episodeIndex?: number;
|
|
}
|
|
|
|
export function shouldExpandForCurrentSource(
|
|
sources: Array<{ source: string }>,
|
|
currentSource: string,
|
|
maxVisible = 5
|
|
): boolean {
|
|
const currentIndex = sources.findIndex((source) => source.source === currentSource);
|
|
return currentIndex >= maxVisible;
|
|
}
|
|
|
|
export function getSourceResolutionBadge(options: {
|
|
isCurrent: boolean;
|
|
currentResolution?: ResolutionLike | null;
|
|
probedResolution?: ResolutionLike | null;
|
|
cachedResolution?: ResolutionLike | null;
|
|
remarks?: string;
|
|
}): ResolutionBadge | null {
|
|
const { isCurrent, currentResolution, probedResolution, cachedResolution, remarks } = options;
|
|
|
|
if (isCurrent && currentResolution) {
|
|
return { label: currentResolution.label, color: currentResolution.color };
|
|
}
|
|
|
|
if (probedResolution) {
|
|
return { label: probedResolution.label, color: probedResolution.color };
|
|
}
|
|
|
|
if (cachedResolution) {
|
|
return { label: cachedResolution.label, color: cachedResolution.color };
|
|
}
|
|
|
|
return extractPlaybackQualityLabel(remarks) || null;
|
|
}
|