-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyggtorrent_ratio.php
141 lines (75 loc) · 2.88 KB
/
yggtorrent_ratio.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
<?php
$YGGTORRENT_URL="yggtorrent.wtf";
$USER = "the_username";
$PASSWORD = "the_password";
// request 1
$ch = curl_init("https://$YGGTORRENT_URL/user/login");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("id"=>$USER,"pass"=>$PASSWORD));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo "curl error : ".curl_error($ch);
die();
}
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code == intval(200)){
// echo $response; // OK
}
else{
echo "Login echoué, ressource introuvable : " . $http_code;
die();
}
// GET COOKIE IN VARIABLE cookies
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
//echo "----header : ----- ".print_r($header)." -------<br/>";
preg_match_all("/^Set-cookie: (.*?);/ism", $header, $cookiesinfo);
$cookies=[];
foreach( $cookiesinfo[1] as $cookie ){
$buffer_explode = strpos($cookie, "=");
$cookies[ substr($cookie,0,$buffer_explode) ] = substr($cookie,$buffer_explode+1);
}
curl_close($ch);
// request 2
$ch = curl_init("https://$YGGTORRENT_URL/user/ajax_usermenu");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Reload cookie
$cookieBuffer = array();
foreach( $cookies as $k=>$c ) array_push($cookieBuffer, "$k=$c");//$cookieBuffer[] = "$k=$c";
curl_setopt($ch, CURLOPT_COOKIE, implode("; ",$cookieBuffer) );
$req2_response = curl_exec($ch);
if (curl_errno($ch)) {
echo "curl error : ".curl_error($ch);
die();
}
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code == intval(200)){
// echo $req2_response;
}
else{
echo "Error, ressource introuvable : " . $http_code;
}
curl_close($ch);
echo "<br><br>";
$r=get_string_between($req2_response, "Ratio : ", "<");
// without magic_quote
//$u=get_string_between($req2_response, "ico_upload\'><\/span> ", "<\/strong>");
//$d=get_string_between($req2_response, "ico_download\'><\/span> ", "<");
$u=get_string_between($req2_response, 'ico_upload\"><\/span> ', "<\/strong>");
$d=get_string_between($req2_response, 'ico_download\"><\/span> ', "<");
echo "Ratio: $r<br/> Upload: $u <br/> Download: $d";
//chdir(dirname(__FILE__));
//file_put_contents("ygg_stats.txt", date("Y/m/d"). " - r: $r\tu: $u\td: $d\n", FILE_APPEND );
function get_string_between($string, $start, $end){
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}