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

@@ -23,8 +23,6 @@ const session = require('express-session');
// needed if bin/details somehow gets deleted
if (!fs.existsSync(CONSTS.DETAILS_BIN_PATH)) fs.writeJSONSync(CONSTS.DETAILS_BIN_PATH, {"version":"2000.06.06","path":"node_modules\\youtube-dl\\bin\\youtube-dl.exe","exec":"youtube-dl.exe","downloader":"youtube-dl"})
const youtubedl = require('youtube-dl');
const logger = require('./logger');
const config_api = require('./config.js');
const downloader_api = require('./downloader');

View File

@@ -65,7 +65,6 @@
"unzipper": "^0.10.10",
"uuidv4": "^6.2.13",
"winston": "^3.7.2",
"xmlbuilder2": "^3.0.2",
"youtube-dl": "^3.0.2"
"xmlbuilder2": "^3.0.2"
}
}

View File

@@ -1,6 +1,5 @@
const fs = require('fs-extra');
const path = require('path');
const youtubedl = require('youtube-dl');
const youtubedl_api = require('./youtube-dl');
const config_api = require('./config');
@@ -475,23 +474,21 @@ async function checkVideoIfBetterExists(file_obj, sub, user_uid) {
const downloadConfig = await generateArgsForSubscription(sub, user_uid, true, new_path);
logger.verbose(`Checking if a better version of the fresh upload ${file_obj['id']} exists.`);
// simulate a download to verify that a better version exists
youtubedl.getInfo(file_obj['url'], downloadConfig, async (err, output) => {
if (err) {
// video is not available anymore for whatever reason
} else if (output) {
const metric_to_compare = sub.type === 'audio' ? 'abr' : 'height';
if (output[metric_to_compare] > file_obj[metric_to_compare]) {
// download new video as the simulated one is better
const {parsed_output, err} = await youtubedl_api.runYoutubeDLMain(sub.url, downloadConfig);
if (err) {
logger.verbose(`Failed to download better version of video ${file_obj['id']}`);
} else if (parsed_output) {
logger.verbose(`Successfully upgraded video ${file_obj['id']}'s ${metric_to_compare} from ${file_obj[metric_to_compare]} to ${output[metric_to_compare]}`);
await db_api.setVideoProperty(file_obj['uid'], {[metric_to_compare]: output[metric_to_compare]});
}
}
}
});
const info = await downloader_api.getVideoInfoByURL(file_obj['url'], downloadConfig);
if (info && info.length === 1) {
const metric_to_compare = sub.type === 'audio' ? 'abr' : 'height';
if (info[metric_to_compare] > file_obj[metric_to_compare]) {
// download new video as the simulated one is better
const {parsed_output, err} = await youtubedl_api.runYoutubeDLMain(sub.url, downloadConfig);
if (err) {
logger.verbose(`Failed to download better version of video ${file_obj['id']}`);
} else if (parsed_output) {
logger.verbose(`Successfully upgraded video ${file_obj['id']}'s ${metric_to_compare} from ${file_obj[metric_to_compare]} to ${info[metric_to_compare]}`);
await db_api.setVideoProperty(file_obj['uid'], {[metric_to_compare]: info[metric_to_compare]});
}
}
}
await db_api.setVideoProperty(file_obj['uid'], {'fresh_upload': false});
}

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');
}