-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (46 loc) · 1.29 KB
/
Copy pathindex.js
File metadata and controls
55 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
var request = require('request');
var async = require('async');
var host = 'http://www.generalfil.es/';
var url = host + 'files-a/';
var options = '/?filter=_Video_';
var getFile = function(link, cb){
request(host + link, function(err, response, body) {
try {
var finalLink = JSON.parse(body).link;
cb(null, finalLink);
} catch (e) {
cb(new Error('Error on response parsing for ' + host+link));
}
});
};
var gf = function(title, cb) {
var finalLinks = [];
title = title.replace(/[^(\w)]+/gi, '-').toLowerCase();
request(url+title+options, function (error, response, body) {
if (!error && response.statusCode == 200) {
var links = body.match(/gf_ShowDownloadLink\([\w',?=\/&]+/gi);
if (!links || links.length === 0) {
cb(new Error('No files found'));
return;
}
links = links.map(function(link){
return link.split(',').pop().replace(/'/gi, '');
});
async.each(links, function(el, next) {
getFile(el, function(err, result) {
if (err) {
next(err);
return;
}
finalLinks.push(result);
next();
});
}, function(err) {
// Alles klar
cb(err, finalLinks);
});
}
});
};
module.exports = gf;