【问题标题】:YTDL - Make file name video titleYTDL - 制作文件名视频标题
【发布时间】:2019-08-07 00:35:15
【问题描述】:

我正在设置一个用于下载 Youtube 视频的网络应用程序,我需要该应用程序来输出

我试过 filename={info.title}.mp4');, filename=${info.title}.mp4');

app.get('/download', (req,res) => {
var URL = req.query.URL;
var stream = ytdl(URL);
stream.on('info', (info) => {
    console.log(info.title);
    console.log(info.video_id);
res.header('Content-Disposition', 'attachment; filename=`{info.title}`.mp4');
ytdl(URL, {
    format: 'mp4'
    }).pipe(res);
})});

输出应该是从stream.on获取的标题,当文件下载时,文件名应该是视频标题 当前输出:{info.title}.mp4

【问题讨论】:

    标签: javascript html node.js


    【解决方案1】:

    您正在尝试在字符串中间使用string interpolation。您需要将整个字符串放在反引号中:

    res.header('Content-Disposition', `attachment; filename=${info.title}.mp4`);
    

    但是,如果您遇到问题,您总是可以只连接字符串吗?

    res.header('Content-Disposition', 'attachment; filename=' + info.title + '.mp4');
    

    【讨论】:

      猜你喜欢
      • 2016-12-13
      • 1970-01-01
      • 2018-03-09
      • 2019-09-23
      • 2020-05-05
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 2018-05-29
      相关资源
      最近更新 更多