Skip to content

Commit a0d34f3

Browse files
committed
core: preserve stream metadata facts
1 parent f1493eb commit a0d34f3

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

engine_v2/src/contracts.mjs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,16 @@ export function normalizeStreamCandidate(raw = {}, context = {}) {
9595
return {
9696
title: textOrNull(raw.title) ?? textOrNull(raw.name) ?? context.providerName ?? "Unknown",
9797
name: textOrNull(raw.name),
98+
description: textOrNull(raw.description),
9899
url,
99100
quality: normalizeQualityLabel(raw.quality ?? raw.resolution),
100101
size: textOrNull(raw.size),
101-
language: textOrNull(raw.language),
102+
language: textOrNull(raw.language ?? raw.lang ?? raw.audioLanguage),
103+
codec: textOrNull(raw.codec ?? raw.videoCodec ?? raw.video_codec),
104+
audio: textOrNull(raw.audio ?? raw.audioCodec ?? raw.audio_codec),
105+
duration: normalizeDurationMinutes(raw.duration ?? raw.durationMinutes ?? raw.runtime),
106+
sourceType: textOrNull(raw.sourceType ?? raw.source_type ?? raw.releaseType ?? raw.release_type),
107+
ageRating: textOrNull(raw.ageRating ?? raw.age_rating ?? raw.certification),
102108
provider: textOrNull(raw.provider) ?? context.providerId ?? null,
103109
type: textOrNull(raw.type),
104110
headers,
@@ -197,6 +203,23 @@ function normalizeQualityLabel(value) {
197203
return text;
198204
}
199205

206+
function normalizeDurationMinutes(value) {
207+
if (value == null || value === "") return null;
208+
if (typeof value === "number" && Number.isFinite(value) && value > 0) {
209+
return value > 600 ? Math.round(value / 60) : Math.round(value);
210+
}
211+
const text = textOrNull(value);
212+
if (!text) return null;
213+
const hm = text.match(/(?:(\d+)\s*h(?:ours?)?)?\s*(?:(\d+)\s*m(?:in(?:utes?)?)?)?/i);
214+
if (hm && (hm[1] || hm[2])) {
215+
const minutes = Number(hm[1] || 0) * 60 + Number(hm[2] || 0);
216+
return minutes > 0 ? minutes : null;
217+
}
218+
const parsed = Number(text);
219+
if (!Number.isFinite(parsed) || parsed <= 0) return null;
220+
return parsed > 600 ? Math.round(parsed / 60) : Math.round(parsed);
221+
}
222+
200223
function normalizeStringList(value) {
201224
const list = Array.isArray(value) ? value : value == null ? [] : [value];
202225
return [...new Set(list.map(textOrNull).filter(Boolean).map((v) => v.toLowerCase()))];

0 commit comments

Comments
 (0)