aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/server/DashUploadUtils.ts42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts
index 79143bedd..2c549cc9f 100644
--- a/src/server/DashUploadUtils.ts
+++ b/src/server/DashUploadUtils.ts
@@ -17,6 +17,8 @@ import { resolvedServerUrl } from './server_Initialization';
import { AcceptableMedia, Upload } from './SharedMediaTypes';
import request = require('request-promise');
import formidable = require('formidable');
+import { NoEmitOnErrorsPlugin } from 'webpack';
+const spawn = require('child_process').spawn;
const { exec } = require('child_process');
const parse = require('pdf-parse');
const ffmpeg = require('fluent-ffmpeg');
@@ -128,9 +130,18 @@ export namespace DashUploadUtils {
res(resolveExistingFile(name, finalPath, Directory.videos, 'video/mp4', duration, undefined));
});
} else {
- exec(`yt-dlp -o ${path} "https://www.youtube.com/watch?v=${videoId}" -f "mp4"`, (error: any, stdout: any, stderr: any) => {
- if (error) {
- console.log(`error: Error: ${error.message}`);
+ const ytdlp = spawn(`yt-dlp`, ['-o', path, videoId, '-f', 'mp4']);
+
+ ytdlp.stdout.on('data', function (data: any) {
+ console.log('stdout: ' + data.toString()); // bcz: somehow channel this back to the client...
+ });
+
+ let errors = '';
+ ytdlp.stderr.on('data', (data: any) => (errors = data.toString()));
+
+ ytdlp.on('exit', function (code: any) {
+ if (code) {
+ console.log(`error: Error: ${NoEmitOnErrorsPlugin}`);
res({
source: {
size: 0,
@@ -139,7 +150,7 @@ export namespace DashUploadUtils {
type: '',
toJSON: () => ({ name, path }),
},
- result: { name: 'failed youtube query', message: `Could not upload YouTube video (${videoId}). Error: ${error.message}` },
+ result: { name: 'failed youtube query', message: `Could not upload video. ${errors}` },
});
} else {
exec(`yt-dlp-o ${path} "https://www.youtube.com/watch?v=${videoId}" --get-duration`, (error: any, stdout: any, stderr: any) => {
@@ -151,6 +162,29 @@ export namespace DashUploadUtils {
});
}
});
+ // exec(`yt-dlp -o ${path} "https://www.youtube.com/watch?v=${videoId}" -f "mp4"`, (error: any, stdout: any, stderr: any) => {
+ // if (error) {
+ // console.log(`error: Error: ${error.message}`);
+ // res({
+ // source: {
+ // size: 0,
+ // path,
+ // name,
+ // type: '',
+ // toJSON: () => ({ name, path }),
+ // },
+ // result: { name: 'failed youtube query', message: `Could not upload YouTube video (${videoId}). Error: ${error.message}` },
+ // });
+ // } else {
+ // exec(`yt-dlp-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, 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));
+ // });
+ // }
+ // });
}
});
}