|
1 | 1 | var http = require('http'),
|
| 2 | + request = require('request'), |
2 | 3 | path = require("path"),
|
3 | 4 | url = require("url"),
|
4 | 5 | fs = require("fs"),
|
@@ -63,25 +64,16 @@ Downloader.prototype.download = function _download(results, limit, movieFile, on
|
63 | 64 |
|
64 | 65 | // get the subtitle
|
65 | 66 | var scope = this;
|
66 |
| - var request = http.get(subtitleToDownload, function(response) { |
67 |
| - |
68 |
| - // download and extract the subtitle |
69 |
| - var gunzip = zlib.createGunzip(); |
70 |
| - dest = fs.createWriteStream(downloadFileName); |
71 |
| - response.pipe(gunzip).pipe(dest); |
72 |
| - |
73 |
| - dest.on("close", function() { |
74 |
| - |
75 |
| - response.unpipe(gunzip); |
76 |
| - response.unpipe(dest); |
77 |
| - |
78 |
| - // emit downloaded event |
79 |
| - scope.emit.call(scope, "downloaded", { url: subtitleToDownload, file: downloadFileName}); |
80 |
| - |
81 |
| - _download.call(scope, results, --limit, movieFile, onCompleted); |
82 |
| - }); |
83 |
| - |
84 |
| - }); |
| 67 | + // download and extract the subtitle |
| 68 | + dest = fs.createWriteStream(downloadFileName); |
| 69 | + gunzip = zlib.createGunzip() |
| 70 | + req = request({url:subtitleToDownload, jar:true, followAllRedirects:true}) |
| 71 | + req.pipe(gunzip).pipe(dest) |
| 72 | + dest.on("close", function() { |
| 73 | + // emit downloaded event |
| 74 | + scope.emit.call(scope, "downloaded", { url: subtitleToDownload, file: downloadFileName}); |
| 75 | + _download.call(scope, results, --limit, movieFile, onCompleted); |
| 76 | + }) |
85 | 77 |
|
86 | 78 | };
|
87 | 79 |
|
|
0 commit comments