var request = require("request");
var options = { method: 'GET', url:'http://dl.opensubtitles.org/en/download/filead/src-api/vrf-19af0c55/sid-ste0uene5gb0jh8dsrma7tcq15/1955127527.srt'};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
使用浏览器进行正常下载会产生正确的文件编码。使用 postman 下载文件时,我得到了编码不正确的损坏文档。
示例:Je suis d�sol�e。我说
没有成功,我尝试将“Content-Type” header 设置为 utf8...
最佳答案
http.get(sub.url, function(res) {
res.pipe(iconv.decodeStream('win1252')).collect(function(err, decodedBody) {
srt2vtt(decodedBody, function(err, vttData) {
if (err) throw new Error(err)
let filename = 'sub-' + sub.lang + 'vtt'
let vttPath = path.join(dir, filename)
fs.writeFileSync(vttPath, vttData)
cb(vttPath)
})
});
});
https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding 我使用流支持来使其正常工作。
关于javascript - 打开字幕字符编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36954866/