Removed node-youtube-dl dependency

This commit is contained in:
Isaac Abadi
2023-09-11 15:33:37 -04:00
parent ea43ea7121
commit 3a86d5c636
4 changed files with 23 additions and 24 deletions

View File

@@ -7,7 +7,6 @@ const logger = require('./logger');
const utils = require('./utils');
const CONSTS = require('./consts');
const config_api = require('./config.js');
const youtubedl = require('youtube-dl');
const is_windows = process.platform === 'win32';
@@ -39,7 +38,7 @@ exports.runYoutubeDL = async (url, args, downloadMethod = null) => {
}
// Run youtube-dl in a main thread (with possible downloadMethod)
exports.runYoutubeDLMain = async (url, args, downloadMethod = youtubedl.exec) => {
exports.runYoutubeDLMain = async (url, args, downloadMethod = defaultDownloadMethod) => {
return new Promise(resolve => {
downloadMethod(url, args, {maxBuffer: Infinity}, async function(err, output) {
const parsed_output = utils.parseOutputJSON(output, err);
@@ -68,6 +67,12 @@ async function getYoutubeDLPath() {
return guessed_base_path + 'youtube-dl' + (is_windows ? '.exe' : '');
}
async function defaultDownloadMethod(url, args, options, callback) {
const {child_process, _} = await runYoutubeDLProcess(url, args);
const {stdout, stderr} = await child_process;
return await callback(stderr, stdout.trim().split(/\r?\n/));
}
exports.killYoutubeDLProcess = async (child_process) => {
kill(child_process.pid, 'SIGKILL');
}