From 099febf27969161377d51de5649058e794a04098 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Tue, 21 Mar 2023 21:15:55 +0800 Subject: [PATCH] Fix weird file extension Normalize file extension when getting download. --- src/common.ts | 5 +++++ src/video-types/youtube.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common.ts b/src/common.ts index 1d63fcd..cf10821 100644 --- a/src/common.ts +++ b/src/common.ts @@ -4,11 +4,16 @@ type ProcessEventCallback = (event: ProcessEvent) => void; type ErrorEventCallback = (event: Error) => void; +type SuccessEvent = { type: string, output: Buffer }; + +type SuccessEventCallback = (event: SuccessEvent) => void; + export interface VideoClipEventEmitter extends NodeJS.EventEmitter { process(): void; on(eventType: 'process', callback: ProcessEventCallback): this; on(eventType: 'error', callback: ErrorEventCallback): this; on(eventType: 'end', callback: ErrorEventCallback): this; + on(eventType: 'success', callback: SuccessEventCallback): this; } export const FILE_TYPES: Record = { diff --git a/src/video-types/youtube.ts b/src/video-types/youtube.ts index 0e25b52..7a27a9f 100644 --- a/src/video-types/youtube.ts +++ b/src/video-types/youtube.ts @@ -35,7 +35,7 @@ const getFileExtension = (downloaderExecutablePath: string, url: string) => { throw result.error; } - return result.stdout.toString('utf-8'); + return result.stdout.toString('utf-8').trim(); }; const constructDownloadSectionsRegex = (start?: number | string, end?: number | string) => {