mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-29 16:10:56 +03:00
Merge branch 'master' of https://github.com/Tzahi12345/YoutubeDL-Material into downloading-improvements
This commit is contained in:
@@ -8,6 +8,7 @@ var youtubedl = require('youtube-dl');
|
||||
var ffmpeg = require('fluent-ffmpeg');
|
||||
var compression = require('compression');
|
||||
var https = require('https');
|
||||
var multer = require('multer');
|
||||
var express = require("express");
|
||||
var bodyParser = require("body-parser");
|
||||
var archiver = require('archiver');
|
||||
@@ -1324,7 +1325,7 @@ async function downloadFileByURL_normal(url, type, options, sessionID = null) {
|
||||
const ext = is_audio ? '.mp3' : '.mp4';
|
||||
var fileFolderPath = is_audio ? audioFolderPath : videoFolderPath;
|
||||
|
||||
if (is_audio) options.skip_audio_args = true;
|
||||
if (is_audio && url.includes('youtu')) { options.skip_audio_args = true; }
|
||||
|
||||
// prepend with user if needed
|
||||
let multiUserMode = null;
|
||||
@@ -1468,6 +1469,7 @@ async function generateArgs(url, type, options) {
|
||||
return new Promise(async resolve => {
|
||||
var videopath = '%(title)s';
|
||||
var globalArgs = config_api.getConfigItem('ytdl_custom_args');
|
||||
let useCookies = config_api.getConfigItem('ytdl_use_cookies');
|
||||
var is_audio = type === 'audio';
|
||||
|
||||
var fileFolderPath = is_audio ? audioFolderPath : videoFolderPath;
|
||||
@@ -1488,11 +1490,15 @@ async function generateArgs(url, type, options) {
|
||||
var youtubePassword = options.youtubePassword;
|
||||
|
||||
let downloadConfig = null;
|
||||
|
||||
let qualityPath = (is_audio && !options.skip_audio_args) ? '-f bestaudio' :'-f best';
|
||||
|
||||
if (!is_audio && (url.includes('tiktok') || url.includes('pscp.tv'))) {
|
||||
const is_youtube = url.includes('youtu');
|
||||
if (!is_audio && !is_youtube) {
|
||||
// tiktok videos fail when using the default format
|
||||
qualityPath = '-f best';
|
||||
} else if (!is_audio && !is_youtube && (url.includes('reddit') || url.includes('pornhub'))) {
|
||||
qualityPath = '-f bestvideo+bestaudio'
|
||||
}
|
||||
|
||||
if (customArgs) {
|
||||
@@ -1520,6 +1526,14 @@ async function generateArgs(url, type, options) {
|
||||
if (youtubeUsername && youtubePassword) {
|
||||
downloadConfig.push('--username', youtubeUsername, '--password', youtubePassword);
|
||||
}
|
||||
|
||||
if (useCookies) {
|
||||
if (fs.existsSync(path.join(__dirname, 'appdata', 'cookies.txt'))) {
|
||||
downloadConfig.push('--cookies', path.join('appdata', 'cookies.txt'));
|
||||
} else {
|
||||
logger.warn('Cookies file could not be found. You can either upload one, or disable \'use cookies\' in the Advanced tab in the settings.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!useDefaultDownloadingAgent && customDownloadingAgent) {
|
||||
downloadConfig.splice(0, 0, '--external-downloader', customDownloadingAgent);
|
||||
@@ -1927,7 +1941,7 @@ app.post('/api/tomp4', optionalJwt, async function(req, res) {
|
||||
|
||||
const is_playlist = url.includes('playlist');
|
||||
let result_obj = null;
|
||||
if (is_playlist || options.customQualityConfiguration || options.customArgs || options.selectedHeight)
|
||||
if (is_playlist || options.customQualityConfiguration || options.customArgs || options.selectedHeight || !url.includes('youtu'))
|
||||
result_obj = await downloadFileByURL_exec(url, 'video', options, req.query.sessionID);
|
||||
else
|
||||
result_obj = await downloadFileByURL_normal(url, 'video', options, req.query.sessionID);
|
||||
@@ -2565,6 +2579,25 @@ app.post('/api/downloadArchive', async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
var upload_multer = multer({ dest: __dirname + '/appdata/' });
|
||||
app.post('/api/uploadCookies', upload_multer.single('cookies'), async (req, res) => {
|
||||
const new_path = path.join(__dirname, 'appdata', 'cookies.txt');
|
||||
|
||||
if (fs.existsSync(req.file.path)) {
|
||||
fs.renameSync(req.file.path, new_path);
|
||||
} else {
|
||||
res.sendStatus(500);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fs.existsSync(new_path)) {
|
||||
res.send({success: true});
|
||||
} else {
|
||||
res.sendStatus(500);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Updater API calls
|
||||
|
||||
app.get('/api/updaterStatus', async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user