File Download on NodeJS with use opensubtitles API

0 votes

I'm a new NodeJS and JS user. For my Web API project, I'm utilising NodeJS. My project, which makes use of the opensubtitles API. The Opensubtitles API returns a URL for a.*gz file. I'd like to save this URL's file to a local folder. I tried a couple other approaches. I was not, however, successful. I saved the file locally, however some of the language characters were corrupted.

Sample file Url:

https://dl.opensubtitles.org/en/download/src-api/vrf-19ed0c61/filead/1954767944.gz

If I download it with a web browser, the characters are coming out properly.

My sample code:

const out = fs.createWriteStream('out.srt'); 
request(subtitle.getSubDownloadLink()).pipe(zlib.createGunzip()).pipe(out);
May 31, 2022 in Node-js by Vaani
• 7,070 points
991 views

1 answer to this question.

0 votes

The problem is the charset output (default utf8)

So you need to convert the strreamed file from iso-8859-5 (charset of the file in gz) to utf8.

This works:

const fs = require('fs')
const request = require('request')
const zlib = require('zlib')
const iconv = require('iconv-lite');

var converterStream = iconv.decodeStream('iso-8859-5');

const out = fs.createWriteStream('out.srt');
request(`https://dl.opensubtitles.org/en/download/src-api/vrf-19ed0c61/filead/1954767944.gz`)
  .pipe(zlib.createGunzip())
  .pipe(converterStream)
  .pipe(out);
answered Jun 7, 2022 by Neha
• 9,020 points

Related Questions In Node-js

0 votes
1 answer

How to create an Excel File with Nodejs?

Hello @kartik, Just create a file with Tabs ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,840 points
2,472 views
0 votes
1 answer

How to download a file with Node.js without using third-party libraries?

Hii, You can create an HTTP GET request and pipe ...READ MORE

answered Nov 24, 2020 in Node-js by Niroj
• 82,840 points
1,275 views
0 votes
1 answer

Can't Upload Image with Google Photos API using NodeJS

The Google Photos API requires binary-formatted material, ...READ MORE

answered Jun 10, 2022 in Node-js by Neha
• 9,020 points
1,635 views
0 votes
0 answers

NodeJS HTTPS API testing with mocha and super test -"DEPTH_ZERO_SELF_SIGNED_CERT"

I need to use mocha and supertest ...READ MORE

Jun 16, 2022 in Node-js by Vaani
• 7,070 points
1,058 views
0 votes
1 answer

Download a file from NodeJS Server using Express

Because the file's name is just 'download' ...READ MORE

answered Jun 13, 2022 in Node-js by Neha
• 9,020 points
7,593 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,922 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
0 votes
1 answer
0 votes
1 answer

How to host MEAN stack application with Angular and nodejs on windows IIS

It's fine that you're using Angular. Be ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
1,337 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP