mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-16 03:41:30 +03:00
Removed node-youtube-dl dependency
This commit is contained in:
@@ -23,8 +23,6 @@ const session = require('express-session');
|
|||||||
// needed if bin/details somehow gets deleted
|
// 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"})
|
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 logger = require('./logger');
|
||||||
const config_api = require('./config.js');
|
const config_api = require('./config.js');
|
||||||
const downloader_api = require('./downloader');
|
const downloader_api = require('./downloader');
|
||||||
|
|||||||
@@ -65,7 +65,6 @@
|
|||||||
"unzipper": "^0.10.10",
|
"unzipper": "^0.10.10",
|
||||||
"uuidv4": "^6.2.13",
|
"uuidv4": "^6.2.13",
|
||||||
"winston": "^3.7.2",
|
"winston": "^3.7.2",
|
||||||
"xmlbuilder2": "^3.0.2",
|
"xmlbuilder2": "^3.0.2"
|
||||||
"youtube-dl": "^3.0.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const youtubedl = require('youtube-dl');
|
|
||||||
|
|
||||||
const youtubedl_api = require('./youtube-dl');
|
const youtubedl_api = require('./youtube-dl');
|
||||||
const config_api = require('./config');
|
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);
|
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.`);
|
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
|
// simulate a download to verify that a better version exists
|
||||||
youtubedl.getInfo(file_obj['url'], downloadConfig, async (err, output) => {
|
|
||||||
if (err) {
|
const info = await downloader_api.getVideoInfoByURL(file_obj['url'], downloadConfig);
|
||||||
// video is not available anymore for whatever reason
|
if (info && info.length === 1) {
|
||||||
} else if (output) {
|
const metric_to_compare = sub.type === 'audio' ? 'abr' : 'height';
|
||||||
const metric_to_compare = sub.type === 'audio' ? 'abr' : 'height';
|
if (info[metric_to_compare] > file_obj[metric_to_compare]) {
|
||||||
if (output[metric_to_compare] > file_obj[metric_to_compare]) {
|
// download new video as the simulated one is better
|
||||||
// download new video as the simulated one is better
|
const {parsed_output, err} = await youtubedl_api.runYoutubeDLMain(sub.url, downloadConfig);
|
||||||
const {parsed_output, err} = await youtubedl_api.runYoutubeDLMain(sub.url, downloadConfig);
|
if (err) {
|
||||||
if (err) {
|
logger.verbose(`Failed to download better version of video ${file_obj['id']}`);
|
||||||
logger.verbose(`Failed to download better version of video ${file_obj['id']}`);
|
} else if (parsed_output) {
|
||||||
} 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]}`);
|
||||||
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]: info[metric_to_compare]});
|
||||||
await db_api.setVideoProperty(file_obj['uid'], {[metric_to_compare]: output[metric_to_compare]});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
await db_api.setVideoProperty(file_obj['uid'], {'fresh_upload': false});
|
await db_api.setVideoProperty(file_obj['uid'], {'fresh_upload': false});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ const logger = require('./logger');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const CONSTS = require('./consts');
|
const CONSTS = require('./consts');
|
||||||
const config_api = require('./config.js');
|
const config_api = require('./config.js');
|
||||||
const youtubedl = require('youtube-dl');
|
|
||||||
|
|
||||||
const is_windows = process.platform === 'win32';
|
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)
|
// 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 => {
|
return new Promise(resolve => {
|
||||||
downloadMethod(url, args, {maxBuffer: Infinity}, async function(err, output) {
|
downloadMethod(url, args, {maxBuffer: Infinity}, async function(err, output) {
|
||||||
const parsed_output = utils.parseOutputJSON(output, err);
|
const parsed_output = utils.parseOutputJSON(output, err);
|
||||||
@@ -68,6 +67,12 @@ async function getYoutubeDLPath() {
|
|||||||
return guessed_base_path + 'youtube-dl' + (is_windows ? '.exe' : '');
|
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) => {
|
exports.killYoutubeDLProcess = async (child_process) => {
|
||||||
kill(child_process.pid, 'SIGKILL');
|
kill(child_process.pid, 'SIGKILL');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user