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 in Node-js by Vaani
• 7,020 points
110 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 by Neha
• 8,740 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,740 points
1,162 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,740 points
459 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 in Node-js by Neha
• 8,740 points
62 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 in Node-js by Vaani
• 7,020 points
48 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 in Node-js by Neha
• 8,740 points
105 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,009 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP