-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimproved.func.php
145 lines (117 loc) · 4.38 KB
/
improved.func.php
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
function ScriptTimings($start){
return round((microtime(true) - $start),2);
}
function ChooseProxySite(){
$sites = array(
"https://gameofbay.org/",
"https://ukpirate.click/",
"https://unblockedbay.info/",
"https://tpbunblocked.org/"
);
$total = count($sites)-1;
$server = $sites[rand(0,$total)];
return [$server, $server . "torrent/"];
}
function TorrentId($server){
if (isset($_COOKIE["position"])) {
$x = $_COOKIE["position"];
$value = $x + 1;
} else {
// Earliest torrent code found = 3220833
$value = 8337550; //8325365 Error at 8328043 && 8337550 ?? 8333560
}
setcookie("position",$value,time()+31556926,"/");
echo "<div style='text-align:center;font-family:sans-serif;font-weight:100;'><span style='font-size:1.3em'>Using Server: $server</span><br /><br />";
return $value;
}
function GetPageById($id, $proxy){
$response = array("id"=>$id, "html"=>false, "code"=> 200);
try {
$c = curl_init($proxy . $id);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
$response["html"] = curl_exec($c);
$response["code"] = curl_getinfo($c, CURLINFO_HTTP_CODE);
if ($c === FALSE)
throw new Exception('cURL couldn\'t initialise');
if ($response["html"] === FALSE)
throw new Exception(curl_error($c), curl_errno($c));
curl_close($c);
return $response;
} catch(Exception $e) {
trigger_error(sprintf('cURL failed with error #%d: %s', $e->getCode(), $e->getMessage()), E_USER_ERROR);
return false;
}
}
function CheckStatusCode($response){
$killCodes = [400,401,402,403,405,406,500,502,503,504,520,521,522,523,524,525];
$skipCodes = [204,205,206,307,404];
$contCodes = [100,101,200,201,202,207,301,302,304,308];
if (in_array($response["code"], $killCodes)) AllowRetry($response, 1);
if (in_array($response["code"], $skipCodes)) SkipToNextTorrent($response["id"]);
if (in_array($response["code"], $contCodes)) return true;
AllowRetry($response, 1);
}
function AllowRetry($response, $type){
if ($type == 1){
setcookie("position",$response["id"],time()+31556926,"/");
die("Error(" . $response["code"] . ") with torrent id " . $response["id"] . ", <a onclick='window.reload()' href='#'>Retry?</a>");
} else {
setcookie("position",$response["id"],time()+31556926,"/");
die("Unknown Error (" . $response["code"] . ") with torrent id " . $response["id"] . ", <a onclick='window.reload()' href='#'>Retry?</a>");
}
}
function SkipToNextTorrent($id){
die('<script type="text/javascript"> window.location.reload(); </script>');
}
function GetDataFromHTML($response, $start){
$data = array();
$html = str_get_html($response["html"]);
if ($html->find("div[id=err]") || $html->find("div[class=searchfield]")) {
echo "Error->(" . $response["id"] . ") in " . ScriptTimings($start) . "s";
SkipToNextTorrent($response["id"]);
}
if (!$html->find("div[id=title]", 0)) {
echo "Error->(" . $response["id"] . ") in " . ScriptTimings($start) . "s";
SkipToNextTorrent($response["id"]);
}
$data["title"] = $html->find("div[id=title]", 0)->plaintext;
$data["type"] = $html->find("div[id=details] a", 0)->plaintext;
$data["filecount"] = $html->find("div[id=details] a", 1)->plaintext;
$data["user"] = $html->find("div[id=details] a", 2)->plaintext;
$data["details"] = $html->find("div[class=nfo] pre", 0)->plaintext;
$data["magnet"] = $html->find("div[class=download] a", 0)->href;
return $data;
}
function LoadResultStore(){
$db = new SQLite3("tpb_magnet_db.sqlite3");
return $db;
}
function EscapeData($data){
return SQLite3::escapeString($data);
}
function SaveResult($save, $db, $response){
$query = "INSERT INTO Links (TorrentID, Name, Type, Files, Uploader, Magnet) VALUES(
'".EscapeData($response['id'])."',
'".EscapeData($save['title'])."',
'".EscapeData($save['type'])."',
'".EscapeData($save['filecount'])."',
'".EscapeData($save['user'])."',
'".EscapeData($save['magnet'])."')";
$r = @$db->exec($query);
if (!$r) {
if ($db->lastErrorMsg() != "UNIQUE constraint failed: Links.TorrentID") {
die("Failed to write result for " . $response["id"]);
} else {
echo "Result for torrent " . $response["id"] . " is already in database, skipping<br />";
}
}
return true;
}
function NextTorrent($db, $response, $start){
echo "Done->(" . $response["id"] . ") in " . ScriptTimings($start) . "s";
$db->close();
SkipToNextTorrent($response["id"]);
}