-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (65 loc) · 1.82 KB
/
index.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
var md5pf = require('md5-part-file');
//var request = require('request');
var http = require('http');
var fs = require('fs');
var language = 'PL';
var np = function(file, cb) {
md5pf(file, 0, 10485760, function(err, hash){
var file = fs.createWriteStream('_TEMP');
var url = 'http://napiprojekt.pl/unit_napisy/dl.php?l=' +
language.toUpperCase() +
'&f='+hash +
'&t='+magic(hash)+
'&v=other&kolejka=false&nick=&pass=&napios=Linux';
http.get(url, function(resp){
resp.pipe(file);
file.on('finish', function(){
file.close(function(){
cb(null, 'file saved');
});
});
});
});
};
// This is magic
// \.
// \'. ;.
// \ '. ,--''-.~-~-'-,
// \,-' ,-. '.~-~-~~,
// ,-' (###) \-~'~=-.
// _,-' '-' \=~-'~~',
// /o \~-''~=-,
// \__ \=-,~'-~,
// '''===-----. \~=-'~-.
// \ \*=~-'
// \ '=====----
// \
// Thanks to Wojciech Ziniewicz (https://github.com/wzin) for helping me in
// understanding original python code in this part
var magic = function(hash){
var idx = [ 0xe, 0x3, 0x6, 0x8, 0x2 ];
var mul = [ 2, 2, 5, 4, 3 ];
var add = [ 0, 0xd, 0x10, 0xb, 0x5 ];
var b = [];
for (var ind = 0; ind < 5; ind++) {
var a = add[ind];
var m = mul[ind];
var i = idx[ind];
var t = a + parseInt(hash[i], 16);
var v = parseInt(hash.slice(t, t+2), 16);
b.push((v*m).toString(16).slice(-1));
}
return b.join('');
};
//somethingStrange('2c3f4866a6ff8a45c8e0a53f2cd12d28');
np(
'bardzo-legalny-film-za-ktory-nie-mozna-isc-siedziec.mkv',
function(err, hash){
if (err){
console.log(err);
return;
}
console.log(hash);
}
);