-
Notifications
You must be signed in to change notification settings - Fork 0
/
t-tor.js
executable file
·127 lines (113 loc) · 3.24 KB
/
t-tor.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
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
125
126
127
#!/usr/bin/env node
var express = require('express'),
request = require('request'),
cheerio = require('cheerio'),
open = require("open"),
inquirer = require('inquirer'),
program = require('commander'),
https = require('https');
var hydra = ['https://thepiratebay.se/',
'https://thepiratebay.la/',
'https://thepiratebay.mn/',
'https://thepiratebay.gd/'];
//make sure that we go to a working pirate bay address
Promise.race(hydra.map(function(url) {
return new Promise(function(resolve, reject) {
https.get(url, function(res) {
resolve(url);
}).on('error', function(err) {
});
});
})).then(function (besturl) {
var test = 'https://thepiratebay.se/';
makeUrl(test);
});
//list t-tor options and get input option ready to search
program
.option('-a, --audio', '100')
.option('-v, --video', '200')
.option('-A, --applications', '300')
.option('-g, --games', '400')
.option('-p, --porn', '500')
.option('-o, --other', '600')
.parse(process.argv);
function parseSearch (index) {
var search = [];
for (i in program.args) {
search[i] = program.args[i].replace(/ /g, '%20');
}
return search;
}
//make final url to get list
function makeUrl(url, index){
var searchOptions = '',
finalUrl = '';
if (program.audio) searchOptions = searchOptions + '100,';
if (program.video) searchOptions = searchOptions + '200,';
if (program.applications) searchOptions = searchOptions + '300,';
if (program.games) searchOptions = searchOptions + '400,';
if (program.porn) searchOptions = searchOptions + '500,';
if (program.other) searchOptions = searchOptions + '600,';
finalUrl = url + 'search/' + parseSearch() + '/0/99/' + searchOptions;
finalUrl = finalUrl.substring(0, finalUrl.length - 1);
torList(finalUrl);
}
//get list of torrents
function torList (url) {
request(url, function (error, respsonse, html){
var title = [],
date = [],
type = [],
magnet = [],
seeds = [],
leech = [],
options = [];
if (!error) {
var $ = cheerio.load(html, {
normalizeWhitespace: true
});
for (i = 0; i < $('#searchResult').children().length; i++){
$('#searchResult').children().eq(i + 1).filter(function(){
var data = $(this).children();
magnet[i] = magnetSlice(data.eq(1).html());
seeds[i] = data.eq(2).html();
leech[i] = data.eq(3).html();
title[i] = data.eq(1).children().first().text().replace(/ /g, '');
date[i] = data.eq(1).children().last().text().replace(/ /g, '');
type[i] = data.eq(0).text().replace(/ /g, '');
options[i] = title[i] + ' ' + type[i] + ' le:' + leech[i] + ' se:' + seeds[i] + ' ' + date[i];
})
}
console.log(url);
genList (options, magnet);
}
})
}
//slice out the magnetic link
function magnetSlice (str){
if (str != null) {
var start = str.indexOf('magnet'),
end = str.indexOf('" ', start),
link = str.slice(start, end);
return link;
}
}
//generate the list
function genList (choices, magnet) {
inquirer.prompt([
{
type : "list",
name : "tor",
message : "Results",
paginated : true,
choices : choices,
}
], function(answer) {
for (i in choices) {
if (answer.tor == choices[i]) {
open(magnet[i]);
{ break; }
}
}
});
}