Closed chrisVillanueva closed 4 years ago
Have you modified the code in any way? if you have can you show me that?
Be careful with res.header('Content-Disposition', `attachment; filename="${title}.mp3"`);
, `attachment; filename="${title}.mp3"`
is wrapped around with ticks `
not '
Hi @Moorad
No, I have not modified the code. I pulled master
and started server, then the client html.
ok give me one min
Alright I messed around a little bit and I was able to replicate the same error
The problem seems to be related to the title of the video. On line 23 where you have res.header('Content-Disposition', `attachment; filename="${title}.mp3"`);
the name of the file is set to the title of the video. However, the filename cannot contain a character outside the ASCII range (for example an emoji) so if the video title contains a character outside the ASCII range it throws a TypeError
.
This might look weird but if you add title = title.replace(/[^\x00-\x7F]/g, "");
(which removes anything non ASCII) above res.header('Content-Disposition', `attachment; filename="${title}.mp3"`);
so the code looks something like
...
title = info.player_response.videoDetails.title;
});
title = title.replace(/[^\x00-\x7F]/g, "");
res.header('Content-Disposition', `attachment; filename="${title}.mp3"`);
ytdl(url, {
format: 'mp3',
filter: 'audioonly',
...
it should do the trick
Thanks @Moorad. I submitted a PR with the approach you mentioned.
Great, thank you for the PR. I just merged it to master
Hello.
I ran into an issue when testing a download. I encountered this server error:
Any ideas on how to resolve this?
Thanks!