Update plugins/alldownloader.js
Browse files- plugins/alldownloader.js +23 -25
plugins/alldownloader.js
CHANGED
@@ -9,6 +9,27 @@ import { youtubedl } from '../lib/youtube/youtube.js';
|
|
9 |
import { authenticateApiKey, apiLimiter } from '../middleware/midware.js';
|
10 |
const AllDlRoutes = express.Router();
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
/**
|
13 |
* @swagger
|
14 |
* /api/v1/dl/tiktok:
|
@@ -231,31 +252,8 @@ AllDlRoutes.get('/api/v1/dl/youtube', authenticateApiKey, apiLimiter, async (req
|
|
231 |
}
|
232 |
|
233 |
const results = await youtubedl(url);
|
234 |
-
|
235 |
-
|
236 |
-
console.log(resolutions);
|
237 |
-
const video_url = await results.video[resolutions[0]].download()
|
238 |
-
/*
|
239 |
-
if (resolutions.length > 0) {
|
240 |
-
const videoDownload = await results.video[resolutions[0]].download();
|
241 |
-
if (videoDownload) {
|
242 |
-
results.video[resolutions[0]].url = videoDownload;
|
243 |
-
} else {
|
244 |
-
console.error("Download link is missing for video:", resolutions[0]);
|
245 |
-
}
|
246 |
-
}
|
247 |
-
|
248 |
-
const audioResolutions = Object.keys(results.audio);
|
249 |
-
if (audioResolutions.length > 0) {
|
250 |
-
const audioDownload = await results.audio[audioResolutions[0]].download();
|
251 |
-
if (audioDownload) {
|
252 |
-
results.audio[audioResolutions[0]].url = audioDownload;
|
253 |
-
} else {
|
254 |
-
console.error("Download link is missing for audio:", audioResolutions[0]);
|
255 |
-
}
|
256 |
-
}*/
|
257 |
-
|
258 |
-
res.json({ video_url });
|
259 |
} catch (error) {
|
260 |
res.status(500).json({ error: error.message });
|
261 |
}
|
|
|
9 |
import { authenticateApiKey, apiLimiter } from '../middleware/midware.js';
|
10 |
const AllDlRoutes = express.Router();
|
11 |
|
12 |
+
async function downloadMedia(media) {
|
13 |
+
try {
|
14 |
+
const videoResolutions = Object.keys(media.video);
|
15 |
+
if (videoResolutions.length > 0) {
|
16 |
+
const firstVideoQuality = videoResolutions[0];
|
17 |
+
const videoDownloadUrl = await media.video[firstVideoQuality].download();
|
18 |
+
console.log(`Download URL for ${firstVideoQuality}:`, videoDownloadUrl);
|
19 |
+
}
|
20 |
+
|
21 |
+
const audioResolutions = Object.keys(media.audio);
|
22 |
+
if (audioResolutions.length > 0) {
|
23 |
+
const firstAudioQuality = audioResolutions[0]; // e.g., '128kbps'
|
24 |
+
const audioDownloadUrl = await media.audio[firstAudioQuality].download();
|
25 |
+
console.log(`Download URL for ${firstAudioQuality}:`, audioDownloadUrl);
|
26 |
+
}
|
27 |
+
} catch (error) {
|
28 |
+
console.error("Error downloading media:", error);
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
|
33 |
/**
|
34 |
* @swagger
|
35 |
* /api/v1/dl/tiktok:
|
|
|
252 |
}
|
253 |
|
254 |
const results = await youtubedl(url);
|
255 |
+
await downloadMedia(results):
|
256 |
+
res.json({ results });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
} catch (error) {
|
258 |
res.status(500).json({ error: error.message });
|
259 |
}
|