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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
"use strict";
function getTrackers()
{
let tr = '&tr=' + encodeURIComponent('udp://tracker.coppersurfer.tk:6969/announce');
tr += '&tr=' + encodeURIComponent('udp://tracker.openbittorrent.com:6969/announce');
tr += '&tr=' + encodeURIComponent('udp://9.rarbg.to:2710/announce');
tr += '&tr=' + encodeURIComponent('udp://9.rarbg.me:2780/announce');
tr += '&tr=' + encodeURIComponent('udp://9.rarbg.to:2730/announce');
tr += '&tr=' + encodeURIComponent('udp://tracker.opentrackr.org:1337');
tr += '&tr=' + encodeURIComponent('http://p4p.arenabg.com:1337/announce');
tr += '&tr=' + encodeURIComponent('udp://tracker.torrent.eu.org:451/announce');
tr += '&tr=' + encodeURIComponent('udp://tracker.tiny-vps.com:6969/announce');
tr += '&tr=' + encodeURIComponent('udp://open.stealth.si:80/announce');
return tr;
}
function makeMagnet(info_hash, name)
{
return 'magnet:?xt=urn:btih:' + info_hash + '&dn=' + encodeURIComponent(name) + getTrackers();
}
function round_to_precision(x, precision)
{
let y = +x + (precision === undefined ? 0.5 : precision / 2);
let sz = y - (y % (precision === undefined ? 1 : +precision)) + '';
if (sz.indexOf('.') == -1) return sz;
else return sz.substring(0, sz.indexOf('.') + 3);
}
function bytesToSize(size)
{
if (size >= 1125899906842624) return round_to_precision(size / 1125899906842624, 0.01) + ' PiB';
if (size >= 1099511627776) return round_to_precision(size / 1099511627776, 0.01) + ' TiB';
if (size >= 1073741824) return round_to_precision(size / 1073741824, 0.01) + ' GiB';
if (size >= 1048576) return round_to_precision(size / 1048576, 0.01) + ' MiB';
if (size >= 1024) return round_to_precision(size / 1024, 0.01) + ' KiB';
return size + ' B';
}
function getDate(date)
{
let dateObj = new Date(date * 1000);
let m = dateObj.getUTCMonth() + 1;
let d = dateObj.getUTCDate();
let mm;
let dd;
if (m < 10) mm = '0' + m
else mm = m;
if (d < 10) dd = '0' + d
else dd = d;
return dateObj.getUTCFullYear() + '-' + mm + '-' + dd;
}
function getCategory(cat)
{
let category = "";
if (cat > 100 && cat < 200)
{
category = "audio";
} else if (cat > 200 && cat < 300) {
category = "video";
} else if (cat > 300 && cat < 400) {
category = "apps";
} else if (cat > 400 && cat < 500) {
category = "games";
} else if (cat > 500 && cat < 600) {
category = "porn";
} else {
category = "other";
}
let subcategory = {
101: 'music',
102: 'audio books',
103: 'sound clips',
104: 'flac',
199: 'other',
201: 'movies',
202: 'movies dvdr',
203: 'music videos',
204: 'movie clips',
205: 'tv-shows',
206: 'handheld',
207: 'hd movies',
208: 'hd tv-shows',
209: '3d',
299: 'other',
301: 'windows',
302: 'mac/apple',
303: 'unix',
304: 'handheld',
305: 'ios(ipad/iphone)',
306: 'android',
399: 'other os',
401: 'pc',
402: 'mac/apple',
403: 'psx',
404: 'xbox360',
405: 'wii',
406: 'handheld',
407: 'ios(ipad/iphone)',
408: 'android',
499: 'other os',
501: 'movies',
502: 'movies dvdr',
503: 'pictures',
504: 'games',
505: 'hd movies',
506: 'movie clips',
599: 'other',
601: 'e-books',
602: 'comics',
603: 'pictures',
604: 'covers',
605: 'physibles',
699: 'other'
}[cat];
return category + " / " + ((subcategory) ? subcategory : "unavailable");
}
module.exports = {makeMagnet, bytesToSize, getDate, getCategory};
|