0

我正在使用节点创建一个“迷你网站”,并通过带有模块 ytdl-core 的表单来表达下载歌曲(用于下载 youtube 视频并转换为 mp3),现在,我想集成下载所有视频的功能播放列表。我安装了 ytpl 并将每个视频的所有 URL 放入数组中,但在下载时我只收到了列表的最后一项。我想这是因为我的实施不好,有什么想法可以解决吗?

//ignoring the previous code for the server..
//trying with hardcoded playlist and cutting the id

var playlis = 'https://www.youtube.com/playlist?list=PLEqSdr9n_Ra0tsouu_LH82mADKPYq4Zg5'
var id = playlis.substring(playlis.indexOf('list=') + 5, playlis.length)

//im using a async function to get an array with the urls

async function call(){
    var objet = await ytpl(id)
    
    let urls = []

    for(let i=0; i < objet.items.length; i++){
        urls.push(objet.items[i].shortUrl)  
    }
    console.log(urls)
    return objet.items.length
}

//and in the app.get im using an for loop with each element of the array using this:

app.get('/download', (req,res) => {
   let lengthPlaylist = call()
   for(let i=0; i < lengthPlaylist; i++){
      var video = ytdl(url).pipe(res.header({"Content-Disposition": `attachment;filename="${i}nameSong.mp3"`, 'Content-Type':"audio/*"}))
   }
})


它不完全是我的代码,因为我正在修改它,但想法相似。

4

0 回答 0