diff options
-rw-r--r-- | src/server/DashUploadUtils.ts | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index c66e932dd..c38f603a4 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -102,24 +102,26 @@ export namespace DashUploadUtils { export function uploadYoutube(videoId: string): Promise<Upload.FileResponse> { return new Promise<Upload.FileResponse<Upload.FileInformation>>((res, rej) => { console.log('Uploading YouTube video: ' + videoId); - exec('youtube-dl -o ' + (videoId.replace(/^-/, '__') + '.mp4') + ' "https://www.youtube.com/watch?v=' + videoId + '" -f "mp4[filesize<5M]/bestvideo[filesize<5M]+bestaudio/bestvideo+bestaudio"', (error: any, stdout: any, stderr: any) => { + const name = videoId; + const path = name.replace(/^-/, '__') + '.mp4'; + exec(`youtube-dl -o ${path} "https://www.youtube.com/watch?v=${videoId}" -f "mp4[filesize<5M]/bestvideo[filesize<5M]+bestaudio/bestvideo+bestaudio"`, (error: any, stdout: any, stderr: any) => { if (error) { console.log(`error: Error: ${error.message}`); res({ source: { size: 0, - path: videoId.replace(/^-/, '__'), - name: videoId, + path, + name, type: '', - toJSON: () => ({ name: videoId, path: videoId.replace(/^-/, '__') }), + toJSON: () => ({ name, path }), }, result: { name: 'failed youtube query', message: `Could not upload YouTube video (${videoId}). Error: ${error.message}` }, }); } else { - exec('youtube-dl -o ' + (videoId.replace(/^-/, '__') + '.mp4') + ' "https://www.youtube.com/watch?v=' + videoId + '" --get-duration', (error: any, stdout: any, stderr: any) => { + exec(`youtube-dl -o ${path} "https://www.youtube.com/watch?v=${videoId}" --get-duration`, (error: any, stdout: any, stderr: any) => { const time = Array.from(stdout.trim().split(':')).reverse(); const duration = (time.length > 2 ? Number(time[2]) * 1000 * 60 : 0) + (time.length > 1 ? Number(time[1]) * 60 : 0) + (time.length > 0 ? Number(time[0]) : 0); - const data = { size: 0, path: videoId.replace(/^-/, '__') + '.mp4', name: videoId, type: 'video/mp4' }; + const data = { size: 0, path, name, type: 'video/mp4' }; const file = { ...data, toJSON: () => ({ ...data, filename: data.path.replace(/.*\//, ''), mtime: duration.toString(), mime: '', toJson: () => undefined as any }) }; res(MoveParsedFile(file, Directory.videos)); }); |