import assert from 'node:assert/strict'; import { test } from 'node:test'; import { mediaFromItem } from '../src/platforms/tiktok.ts'; import { fixture } from './helpers.ts'; test('a video post picks a playable file and carries the referrer the CDN demands', async () => { const media = await mediaFromItem(fixture('tiktok/video.json')); assert.equal(media.length, 1); const [item] = media; assert.equal(item?.kind, 'video'); assert.match(item?.url ?? '', /^https:\/\//); // Without this header the CDN answers 403 and the player shows nothing. assert.equal(item?.fetchHeaders?.['Referer'], 'https://www.tiktok.com/'); assert.ok(item?.kind === 'video' && item.poster, 'expected a cover frame'); assert.ok(item?.width && item.height); assert.ok(item?.kind === 'video' && item.durationSec); }); test('the highest bitrate rendition wins', async () => { const media = await mediaFromItem({ video: { playAddr: 'https://cdn/fallback.mp4', bitrateInfo: [ { Bitrate: 500_000, PlayAddr: { UrlList: ['https://cdn/low.mp4'] } }, { Bitrate: 2_000_000, PlayAddr: { UrlList: ['https://cdn/high.mp4'] } }, ], }, }); assert.equal(media[0]?.url, 'https://cdn/high.mp4'); }); test('a photo post yields images rather than an empty video', async () => { const media = await mediaFromItem({ imagePost: { images: [ { imageURL: { UrlList: ['https://cdn/1.jpg'] }, imageWidth: 1080, imageHeight: 1350 }, { imageURL: { UrlList: ['https://cdn/2.jpg'] }, imageWidth: 1080, imageHeight: 1350 }, ], }, video: { cover: 'https://cdn/cover.jpg' }, }); assert.equal(media.length, 2); assert.ok(media.every((m) => m.kind === 'image')); });