70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
InstagramExtractor,
|
|
normalizeInstagramSessionCookie,
|
|
} from '../src/services/extractors/instagram.extractor.js';
|
|
import { readTranscriptSegments } from '../src/services/extractors/youtube.extractor.js';
|
|
|
|
test('Instagram session ID를 Cookie 헤더 형식으로 정규화한다', () => {
|
|
assert.equal(
|
|
normalizeInstagramSessionCookie('123456%3Aexample'),
|
|
'sessionid=123456%3Aexample;',
|
|
);
|
|
assert.equal(
|
|
normalizeInstagramSessionCookie('sessionid=123456%3Aexample;'),
|
|
'sessionid=123456%3Aexample;',
|
|
);
|
|
});
|
|
|
|
test('Instagram 릴스의 커버 이미지를 썸네일로 사용한다', async () => {
|
|
let requestedMediaId;
|
|
const extractor = new InstagramExtractor({
|
|
sessionCookie: '123456%3Aexample',
|
|
clientFactory: () => ({
|
|
fetchPost: async () => ({
|
|
caption: '테스트 레시피',
|
|
media_id: 'media-1',
|
|
shortcode: 'Db137BuzUJe',
|
|
postType: 'reel',
|
|
links: [{ type: 'video', url: 'https://video.example.com/reel.mp4' }],
|
|
}),
|
|
fetchPostByMediaId: async (mediaId) => {
|
|
requestedMediaId = mediaId;
|
|
return {
|
|
items: [{
|
|
image_versions2: {
|
|
candidates: [{ url: 'https://images.example.com/reel-cover.jpg' }],
|
|
},
|
|
}],
|
|
};
|
|
},
|
|
}),
|
|
});
|
|
|
|
const source = await extractor.extract('https://www.instagram.com/reel/Db137BuzUJe/');
|
|
|
|
assert.equal(requestedMediaId, 'media-1');
|
|
assert.equal(source.thumbnailUrl, 'https://images.example.com/reel-cover.jpg');
|
|
});
|
|
|
|
test('youtubei.js transcript 구조에서 timestamp를 보존한다', () => {
|
|
const result = readTranscriptSegments({
|
|
transcript: {
|
|
content: {
|
|
body: {
|
|
initial_segments: [
|
|
{ start_ms: '12400', end_ms: '18000', snippet: { toString: () => '김치를 볶는다' } },
|
|
{ start_ms: '18000', end_ms: '24000', snippet: { toString: () => '물을 넣는다' } },
|
|
],
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(result, [
|
|
{ startSec: 12.4, endSec: 18, text: '김치를 볶는다' },
|
|
{ startSec: 18, endSec: 24, text: '물을 넣는다' },
|
|
]);
|
|
});
|