randydev commited on
Commit
6334995
·
verified ·
1 Parent(s): 7f822a4

Update plugins/alldownloader.js

Browse files
Files changed (1) hide show
  1. plugins/alldownloader.js +14 -4
plugins/alldownloader.js CHANGED
@@ -229,13 +229,23 @@ AllDlRoutes.get('/api/v1/dl/youtube', authenticateApiKey, apiLimiter, async (req
229
  if (!url) {
230
  return res.status(400).json({ error: "url parameter is required." });
231
  }
 
232
  const results = await youtubedl(url);
233
- for (const video of results.video) {
234
- video.url = await video.download();
 
 
 
 
 
235
  }
236
- for (const audio of results.audio) {
237
- audio.url = await audio.download();
 
 
 
238
  }
 
239
  res.json({ results });
240
  } catch (error) {
241
  res.status(500).json({ error: error.message });
 
229
  if (!url) {
230
  return res.status(400).json({ error: "url parameter is required." });
231
  }
232
+
233
  const results = await youtubedl(url);
234
+
235
+ const resolutions = Object.keys(results.video);
236
+ console.log(resolutions);
237
+
238
+ if (resolutions.length > 0) {
239
+ const videoUrl = await results.video[resolutions[0]].download();
240
+ results.video[resolutions[0]].url = videoUrl;
241
  }
242
+
243
+ const audioResolutions = Object.keys(results.audio);
244
+ if (audioResolutions.length > 0) {
245
+ const audioUrl = await results.audio[audioResolutions[0]].download();
246
+ results.audio[audioResolutions[0]].url = audioUrl;
247
  }
248
+
249
  res.json({ results });
250
  } catch (error) {
251
  res.status(500).json({ error: error.message });