Browse Source

Update package name, rename types

Use appropriate names for some things.
master
TheoryOfNekomata 1 year ago
parent
commit
016cb99175
3 changed files with 13 additions and 11 deletions
  1. +1
    -1
      package.json
  2. +9
    -7
      src/index.ts
  3. +3
    -3
      test/index.test.ts

+ 1
- 1
package.json View File

@@ -1,5 +1,5 @@
{ {
"name": "youtube-clip-core",
"name": "@modal/webvideo-clip-core",
"version": "0.0.0", "version": "0.0.0",
"files": [ "files": [
"dist", "dist",


+ 9
- 7
src/index.ts View File

@@ -6,18 +6,18 @@ export enum VideoType {
YOUTUBE = 'youtube', YOUTUBE = 'youtube',
} }


interface ClipVideoBaseParams {
interface CreateBaseClipperParams {
url: string; url: string;
start?: number | string; start?: number | string;
end?: number | string; end?: number | string;
postprocessorExecutablePath?: string; postprocessorExecutablePath?: string;
} }


interface ClipYouTubeVideoParams extends ClipVideoBaseParams {
interface CreateYouTubeClipperParams extends CreateBaseClipperParams {
downloaderExecutablePath?: string; downloaderExecutablePath?: string;
} }


interface ClipVideoParams extends ClipYouTubeVideoParams {
export interface CreateVideoClipperParams extends CreateYouTubeClipperParams {
type: VideoType, type: VideoType,
} }


@@ -54,12 +54,12 @@ const getCacheFilename = () => {
return `output-${time}.mkv`; return `output-${time}.mkv`;
}; };


export interface ClipEventEmitter extends EventEmitter {
export interface VideoClipEventEmitter extends EventEmitter {
process(): void; 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(); super();
} }


@@ -140,6 +140,7 @@ class YouTubeVideoClipEventEmitter extends EventEmitter implements ClipEventEmit
const output = readFileSync(cacheFilename); const output = readFileSync(cacheFilename);
unlinkSync(cacheFilename); unlinkSync(cacheFilename);
this.emit('success', { this.emit('success', {
type: 'video/webm',
output, output,
}); });
this.emit('end'); this.emit('end');
@@ -224,6 +225,7 @@ class YouTubeVideoClipEventEmitter extends EventEmitter implements ClipEventEmit
const output = readFileSync(cacheFilename); const output = readFileSync(cacheFilename);
unlinkSync(cacheFilename); unlinkSync(cacheFilename);
this.emit('success', { this.emit('success', {
type: 'video/webm',
output, output,
}); });
this.emit('end'); this.emit('end');
@@ -244,7 +246,7 @@ class YouTubeVideoClipEventEmitter extends EventEmitter implements ClipEventEmit
} }
} }


export const createVideoClipper = (params: ClipVideoParams) => {
export const createVideoClipper = (params: CreateVideoClipperParams) => {
const { const {
type: videoType, type: videoType,
url, url,


+ 3
- 3
test/index.test.ts View File

@@ -4,7 +4,7 @@ import {
import { spawnSync } from 'child_process'; import { spawnSync } from 'child_process';
import { readFileSync, unlinkSync } from 'fs'; import { readFileSync, unlinkSync } from 'fs';
import * as webVideoClipCore from '../src'; import * as webVideoClipCore from '../src';
import { ClipEventEmitter } from '../src';
import { VideoClipEventEmitter } from '../src';


vi.mock('child_process', () => ({ vi.mock('child_process', () => ({
spawnSync: vi.fn(), spawnSync: vi.fn(),
@@ -21,7 +21,7 @@ describe('createVideoClipper', () => {
}); });


describe('with postprocessing', () => { describe('with postprocessing', () => {
let clipper: ClipEventEmitter;
let clipper: VideoClipEventEmitter;
beforeEach(() => { beforeEach(() => {
clipper = webVideoClipCore.createVideoClipper({ clipper = webVideoClipCore.createVideoClipper({
downloaderExecutablePath: 'yt-dlp', downloaderExecutablePath: 'yt-dlp',
@@ -107,7 +107,7 @@ describe('createVideoClipper', () => {
}); });


describe('without postprocessing', () => { describe('without postprocessing', () => {
let clipper: ClipEventEmitter;
let clipper: VideoClipEventEmitter;
beforeEach(() => { beforeEach(() => {
clipper = webVideoClipCore.createVideoClipper({ clipper = webVideoClipCore.createVideoClipper({
downloaderExecutablePath: 'yt-dlp', downloaderExecutablePath: 'yt-dlp',


Loading…
Cancel
Save