"use-strict"; const { BMiscInfo } = require("./RadioMiscInfo.js") const { EDisplayType } = require("./RadioPreview.js") const CODEC_WARNINGS = { "video/mp4": [ [ "warn", "avc1", "vague, however browsers will accept it. See MDN for format details" ], [ "error", "mp4a", "too vague; Browsers will not accept it! See MDN for format details" ], [ "error", "aac", "invalid! The correct codec is mp4a. See MDN for format details" ] ] } const CODEC_SUGGESTIONS = { "video/mp4": 'codecs may be "avc1" with "mp4a.40.2" (AAC-LC)', "audio/mp3": 'codec is probably "mp3"' } const mediaItemsLint = mediaItems => { for (const item of mediaItems) { const hasAudioSource = item.sources.some(a => a.type.startsWith("audio/")) for (const index in item.sources) { const source = item.sources[index] if (!hasAudioSource && source.type.startsWith("video/") && !source.previews.some(item => item.display_type != EDisplayType.NATIVE)) { const logType = (item?.misc & BMiscInfo.ALT_MEDIA) ? "warn" : "error" console.warn(`${logType[0].toUpperCase()}: [previews] [${item.id}:${index}] No audio fallback preview set!`) } if (source.codecs?.length) for (const [ logType, codec, reason ] of (Object.hasOwn(CODEC_WARNINGS, source.type) ? CODEC_WARNINGS[source.type] : [])) { if (!source.codecs.includes(codec)) continue const msg = `${logType[0].toUpperCase()}: [codecs] [${item.id}:${index}] The declaration "${codec}" is ${reason}` console[logType](msg) } else console.warn(`W: [codecs] [${item.id}:${index}] No codec declarations are set!${Object.hasOwn(CODEC_SUGGESTIONS, source.type)?` The ${CODEC_SUGGESTIONS[source.type]}, check with ffprobe.`:''}`) for (const p_index in source.previews) { const preview = item.sources[index].previews[p_index] if (!preview.type) console.warn(`W: [previews] [${item.id}:${index}] No type set for preview ${p_index} source ${index} of ${item.id}`) if (!preview.size) console.warn(`W: [previews] [${item.id}:${index}] No size set for preview ${p_index} source ${index} of ${item.id}`) } } } } module.exports = { mediaItemsLint }