|
@@ -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, |
|
|