randydev commited on
Commit
0565bbd
·
verified ·
1 Parent(s): ed2c43b

Update plugins/alldownloader.js

Browse files
Files changed (1) hide show
  1. plugins/alldownloader.js +21 -10
plugins/alldownloader.js CHANGED
@@ -9,23 +9,34 @@ import { youtubedl } from '../lib/youtube/youtube.js';
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
 
 
9
  import { authenticateApiKey, apiLimiter } from '../middleware/midware.js';
10
  const AllDlRoutes = express.Router();
11
 
12
+
13
  async function downloadMedia(media) {
14
+ const downloadResults = {};
15
  try {
16
+ if (media.video && media.video['720p']) {
17
+ const videoQuality = '720p';
18
+ const videoDownloadUrl = await media.video[videoQuality].download();
19
+ downloadResults.video = {
20
+ quality: videoQuality,
21
+ url: videoDownloadUrl
22
+ };
23
+ } else {
24
+ console.error("720p video quality is not available.");
25
  }
26
 
27
+ if (media.audio && Object.keys(media.audio).length > 0) {
28
+ const audioQuality = Object.keys(media.audio)[0];
29
+ const audioDownloadUrl = await media.audio[audioQuality].download();
30
+ downloadResults.audio = {
31
+ quality: audioQuality,
32
+ url: audioDownloadUrl
33
+ };
34
  }
35
+
36
+ return downloadResults;
37
  } catch (error) {
38
  console.error("Error downloading media:", error);
39
+ throw new Error("Failed to download media");
40
  }
41
  }
42