gpt4 book ai didi

javascript - 打开字幕字符编码

转载 作者:行者123 更新时间:2023-12-03 07:02:53 32 4
gpt4 key购买 nike

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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com