Upload 9 files
Browse files- app.js +5 -18
- config.json +1 -14
app.js
CHANGED
|
@@ -5,7 +5,6 @@ const fs = require('fs');
|
|
| 5 |
const path = require('path');
|
| 6 |
const crypto = require('crypto');
|
| 7 |
const os = require('os');
|
| 8 |
-
const { getProxyForUrl, validateProxy } = require('./proxy-config');
|
| 9 |
|
| 10 |
const app = express();
|
| 11 |
const PORT = process.env.PORT || 7860; // Hugging Face Spaces sử dụng port 7860
|
|
@@ -64,11 +63,7 @@ app.post('/video-info', async (req, res) => {
|
|
| 64 |
return res.status(400).json({ error: 'URL là bắt buộc' });
|
| 65 |
}
|
| 66 |
|
| 67 |
-
|
| 68 |
-
const proxyUrl = getProxyForUrl(url);
|
| 69 |
-
const proxyFlag = proxyUrl && validateProxy(proxyUrl) ? `--proxy "${proxyUrl}"` : '';
|
| 70 |
-
|
| 71 |
-
const command = `yt-dlp ${proxyFlag} --dump-json "${url}"`.replace(/\s+/g, ' ').trim();
|
| 72 |
|
| 73 |
exec(command, (error, stdout, stderr) => {
|
| 74 |
if (error) {
|
|
@@ -110,10 +105,6 @@ app.post('/download', async (req, res) => {
|
|
| 110 |
const fileId = generateFileId();
|
| 111 |
const timestamp = Date.now();
|
| 112 |
|
| 113 |
-
// Lấy proxy cho URL này
|
| 114 |
-
const proxyUrl = getProxyForUrl(url);
|
| 115 |
-
const proxyFlag = proxyUrl && validateProxy(proxyUrl) ? `--proxy "${proxyUrl}"` : '';
|
| 116 |
-
|
| 117 |
let command;
|
| 118 |
let expectedExtension;
|
| 119 |
|
|
@@ -121,7 +112,7 @@ app.post('/download', async (req, res) => {
|
|
| 121 |
// Tải audio
|
| 122 |
expectedExtension = 'mp3';
|
| 123 |
const outputTemplate = path.join(downloadsDir, `${fileId}.%(ext)s`);
|
| 124 |
-
command = `yt-dlp
|
| 125 |
} else {
|
| 126 |
// Tải video với format selection tối ưu
|
| 127 |
expectedExtension = 'mp4';
|
|
@@ -137,14 +128,10 @@ app.post('/download', async (req, res) => {
|
|
| 137 |
formatFlag = `-f "bestvideo[height<=${quality.replace('p', '')}]+bestaudio/best[height<=${quality.replace('p', '')}]"`;
|
| 138 |
}
|
| 139 |
|
| 140 |
-
command = `yt-dlp ${
|
| 141 |
}
|
| 142 |
|
| 143 |
-
|
| 144 |
-
if (proxyUrl) {
|
| 145 |
-
console.log(`🌐 Sử dụng proxy: ${proxyUrl.replace(/\/\/[^@]+@/, '//***:***@')}`);
|
| 146 |
-
}
|
| 147 |
-
console.log('Đang thực thi lệnh:', command.replace(/--proxy "[^"]+"/, '--proxy "***"'));
|
| 148 |
|
| 149 |
exec(command, (error, stdout, stderr) => {
|
| 150 |
if (error) {
|
|
@@ -168,7 +155,7 @@ app.post('/download', async (req, res) => {
|
|
| 168 |
scheduleFileCleanup(filePath);
|
| 169 |
|
| 170 |
// Lấy thông tin video để trả về
|
| 171 |
-
const getVideoInfoCommand = `yt-dlp
|
| 172 |
exec(getVideoInfoCommand, (infoError, infoStdout) => {
|
| 173 |
let videoInfo = null;
|
| 174 |
if (!infoError) {
|
|
|
|
| 5 |
const path = require('path');
|
| 6 |
const crypto = require('crypto');
|
| 7 |
const os = require('os');
|
|
|
|
| 8 |
|
| 9 |
const app = express();
|
| 10 |
const PORT = process.env.PORT || 7860; // Hugging Face Spaces sử dụng port 7860
|
|
|
|
| 63 |
return res.status(400).json({ error: 'URL là bắt buộc' });
|
| 64 |
}
|
| 65 |
|
| 66 |
+
const command = `yt-dlp --dump-json "${url}"`;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
exec(command, (error, stdout, stderr) => {
|
| 69 |
if (error) {
|
|
|
|
| 105 |
const fileId = generateFileId();
|
| 106 |
const timestamp = Date.now();
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
let command;
|
| 109 |
let expectedExtension;
|
| 110 |
|
|
|
|
| 112 |
// Tải audio
|
| 113 |
expectedExtension = 'mp3';
|
| 114 |
const outputTemplate = path.join(downloadsDir, `${fileId}.%(ext)s`);
|
| 115 |
+
command = `yt-dlp -x --audio-format mp3 --audio-quality ${quality} -o "${outputTemplate}" "${url}"`;
|
| 116 |
} else {
|
| 117 |
// Tải video với format selection tối ưu
|
| 118 |
expectedExtension = 'mp4';
|
|
|
|
| 128 |
formatFlag = `-f "bestvideo[height<=${quality.replace('p', '')}]+bestaudio/best[height<=${quality.replace('p', '')}]"`;
|
| 129 |
}
|
| 130 |
|
| 131 |
+
command = `yt-dlp ${formatFlag} -o "${outputTemplate}" "${url}"`.replace(/\s+/g, ' ').trim();
|
| 132 |
}
|
| 133 |
|
| 134 |
+
console.log('Đang thực thi lệnh:', command);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
exec(command, (error, stdout, stderr) => {
|
| 137 |
if (error) {
|
|
|
|
| 155 |
scheduleFileCleanup(filePath);
|
| 156 |
|
| 157 |
// Lấy thông tin video để trả về
|
| 158 |
+
const getVideoInfoCommand = `yt-dlp --dump-json --no-download "${url}"`;
|
| 159 |
exec(getVideoInfoCommand, (infoError, infoStdout) => {
|
| 160 |
let videoInfo = null;
|
| 161 |
if (!infoError) {
|
config.json
CHANGED
|
@@ -25,19 +25,6 @@
|
|
| 25 |
"audioPlayer": true,
|
| 26 |
"directDownload": true,
|
| 27 |
"copyLink": true,
|
| 28 |
-
"fileIdSystem": true
|
| 29 |
-
"proxySupport": true
|
| 30 |
-
},
|
| 31 |
-
"proxy": {
|
| 32 |
-
"enabled": false,
|
| 33 |
-
"type": "socks5",
|
| 34 |
-
"host": "74.226.201.156",
|
| 35 |
-
"port": 1080,
|
| 36 |
-
"username": "dunn",
|
| 37 |
-
"password": "1234",
|
| 38 |
-
"poolEnabled": false,
|
| 39 |
-
"pool": [],
|
| 40 |
-
"platformSpecific": {},
|
| 41 |
-
"regions": {}
|
| 42 |
}
|
| 43 |
}
|
|
|
|
| 25 |
"audioPlayer": true,
|
| 26 |
"directDownload": true,
|
| 27 |
"copyLink": true,
|
| 28 |
+
"fileIdSystem": true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
}
|
| 30 |
}
|