|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import { normalizeStreamCandidate } from "../src/contracts.mjs"; |
| 3 | +import { |
| 4 | + buildBadges, |
| 5 | + presentStreamCandidate, |
| 6 | + normalizeSourceType, |
| 7 | +} from "../src/stream-presentation.mjs"; |
| 8 | + |
| 9 | +const facts = normalizeStreamCandidate({ |
| 10 | + name: "Purstream", |
| 11 | + url: "https://media.example/master.m3u8", |
| 12 | + quality: "4K", |
| 13 | + language: "VFF", |
| 14 | + codec: "x265", |
| 15 | + audio: "DDP 5.1", |
| 16 | + duration: 169, |
| 17 | + sourceType: "BluRay", |
| 18 | + ageRating: "-12", |
| 19 | +}, { providerId: "purstream" }); |
| 20 | + |
| 21 | +assert.equal(facts.quality, "2160p"); |
| 22 | +assert.equal(facts.language, "VFF"); |
| 23 | +assert.equal(facts.codec, "x265"); |
| 24 | +assert.equal(facts.audio, "DDP 5.1"); |
| 25 | +assert.equal(facts.duration, 169); |
| 26 | +assert.equal(facts.sourceType, "BluRay"); |
| 27 | +assert.equal(facts.ageRating, "-12"); |
| 28 | + |
| 29 | +const presented = presentStreamCandidate(facts, { |
| 30 | + title: "Interstellar", |
| 31 | + year: 2014, |
| 32 | + runtime: 169, |
| 33 | + certification: "-12", |
| 34 | +}, { id: "purstream", name: "Purstream" }); |
| 35 | + |
| 36 | +assert.equal(presented.title, "Purstream"); |
| 37 | +assert.equal(presented.quality, "2160p"); |
| 38 | +assert.equal(presented.codec, "HEVC"); |
| 39 | +assert.equal(presented.audio, "E-AC3 5.1"); |
| 40 | +assert.equal(presented.duration, 169); |
| 41 | +assert.equal(presented.sourceType, "BLU-RAY"); |
| 42 | +assert.match(presented.description, /【4K】/); |
| 43 | +assert.match(presented.description, /【BLU-RAY】/); |
| 44 | +assert.match(presented.description, /🌐 VFF/); |
| 45 | +assert.match(presented.description, /🎞 HEVC/); |
| 46 | +assert.match(presented.description, /🔊 E-AC3 5\.1/); |
| 47 | +assert.match(presented.description, /⏱ 2h49/); |
| 48 | +assert.match(presented.description, /🔞 -12/); |
| 49 | + |
| 50 | +const tmdbFallback = presentStreamCandidate({ |
| 51 | + name: "Cineby", |
| 52 | + url: "https://media.example/unknown.mp4", |
| 53 | + description: "Unknown", |
| 54 | +}, { |
| 55 | + title: "Sinners", |
| 56 | + year: 2025, |
| 57 | + runtime: 137, |
| 58 | + certification: "16+", |
| 59 | +}, { name: "Cineby" }); |
| 60 | +assert.doesNotMatch(tmdbFallback.description ?? "", /Unknown/i); |
| 61 | +assert.match(tmdbFallback.description, /⏱ 2h17/); |
| 62 | +assert.match(tmdbFallback.description, /🔞 16\+/); |
| 63 | + |
| 64 | +const noInventedBluray = presentStreamCandidate({ |
| 65 | + name: "FrenchStream", |
| 66 | + url: "https://media.example/1080.mp4", |
| 67 | + quality: "1080p", |
| 68 | +}, {}, { name: "FrenchStream" }); |
| 69 | +assert.match(noInventedBluray.description, /【1080P】/); |
| 70 | +assert.doesNotMatch(noInventedBluray.description, /BLU-RAY/i); |
| 71 | +assert.equal(normalizeSourceType("1080p"), "1080P"); |
| 72 | + |
| 73 | +const badges = buildBadges({ quality: "4K", language: "VFQ", codec: "H.264" }); |
| 74 | +assert.deepEqual(badges, ["【4K】", "🌐 VFQ", "🎞 H.264"]); |
| 75 | + |
| 76 | +console.log("engine v2 stream presentation tests passed"); |
0 commit comments