From 016cb99175dedcb27199ada5f201a512c27d2d22 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Tue, 21 Mar 2023 16:47:37 +0800 Subject: [PATCH] Update package name, rename types Use appropriate names for some things. --- package.json | 2 +- src/index.ts | 16 +++++++++------- test/index.test.ts | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 3a804c5..61ebce9 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "youtube-clip-core", + "name": "@modal/webvideo-clip-core", "version": "0.0.0", "files": [ "dist", diff --git a/src/index.ts b/src/index.ts index 6c79831..0804aa5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,18 +6,18 @@ export enum VideoType { YOUTUBE = 'youtube', } -interface ClipVideoBaseParams { +interface CreateBaseClipperParams { url: string; start?: number | string; end?: number | string; postprocessorExecutablePath?: string; } -interface ClipYouTubeVideoParams extends ClipVideoBaseParams { +interface CreateYouTubeClipperParams extends CreateBaseClipperParams { downloaderExecutablePath?: string; } -interface ClipVideoParams extends ClipYouTubeVideoParams { +export interface CreateVideoClipperParams extends CreateYouTubeClipperParams { type: VideoType, } @@ -54,12 +54,12 @@ const getCacheFilename = () => { return `output-${time}.mkv`; }; -export interface ClipEventEmitter extends EventEmitter { +export interface VideoClipEventEmitter extends EventEmitter { process(): void; } -class YouTubeVideoClipEventEmitter extends EventEmitter implements ClipEventEmitter { - constructor(private readonly params: ClipYouTubeVideoParams) { +class YouTubeVideoClipEventEmitter extends EventEmitter implements VideoClipEventEmitter { + constructor(private readonly params: CreateYouTubeClipperParams) { super(); } @@ -140,6 +140,7 @@ class YouTubeVideoClipEventEmitter extends EventEmitter implements ClipEventEmit const output = readFileSync(cacheFilename); unlinkSync(cacheFilename); this.emit('success', { + type: 'video/webm', output, }); this.emit('end'); @@ -224,6 +225,7 @@ class YouTubeVideoClipEventEmitter extends EventEmitter implements ClipEventEmit const output = readFileSync(cacheFilename); unlinkSync(cacheFilename); this.emit('success', { + type: 'video/webm', output, }); this.emit('end'); @@ -244,7 +246,7 @@ class YouTubeVideoClipEventEmitter extends EventEmitter implements ClipEventEmit } } -export const createVideoClipper = (params: ClipVideoParams) => { +export const createVideoClipper = (params: CreateVideoClipperParams) => { const { type: videoType, url, diff --git a/test/index.test.ts b/test/index.test.ts index 07453e3..55045c3 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -4,7 +4,7 @@ import { import { spawnSync } from 'child_process'; import { readFileSync, unlinkSync } from 'fs'; import * as webVideoClipCore from '../src'; -import { ClipEventEmitter } from '../src'; +import { VideoClipEventEmitter } from '../src'; vi.mock('child_process', () => ({ spawnSync: vi.fn(), @@ -21,7 +21,7 @@ describe('createVideoClipper', () => { }); describe('with postprocessing', () => { - let clipper: ClipEventEmitter; + let clipper: VideoClipEventEmitter; beforeEach(() => { clipper = webVideoClipCore.createVideoClipper({ downloaderExecutablePath: 'yt-dlp', @@ -107,7 +107,7 @@ describe('createVideoClipper', () => { }); describe('without postprocessing', () => { - let clipper: ClipEventEmitter; + let clipper: VideoClipEventEmitter; beforeEach(() => { clipper = webVideoClipCore.createVideoClipper({ downloaderExecutablePath: 'yt-dlp',