html head title title head body php set_time_limit class friends_vkont

  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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<html>
<head>
<title></title>
</head>
<body>
<?php
set_time_limit(0);
class friends_vkontakte{
public $my_friends=array();
public $friends=array();
public $pop_list=array();
public $avatars=array();
public $cookie='xxxxxxx';
public $id=1276027;
function get_data($data){
if(preg_match("|list:\[(\[.*?\])\]|ims",$data,$matches))
return $matches[1];
}
function get_avatars($data){
if(preg_match_all("|href=\"profile.php.*?\"><img src='(.*?)' alt='' />|ims",$data,$matches))
return $matches[0];
}
function parse_page($data){
if(preg_match_all("|\[([0-9]+), {f:'(.*?)', l:'(.*?)'.*?\]|ims",$data,$matches,PREG_SET_ORDER)){
$tmp=array();
foreach($matches as $v){
$tmp[$v[1]]=$v[2].' '.$v[3];
}
return $tmp;
}
return array();
}
private function get_music_page($id){
$url="http://vkontakte.ru/audio.php?id=$id";
print "download $url<br/>";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $this->cookie);
$data=curl_exec($ch);
return $data;
}
function get_music($id){
$data=$this->get_music_page($id);
$pattern='|<div .*? id="audio.*?">.*?operate\(([0-9]+),([0-9]+),([0-9]+),\'([a-z0-9]+)\',([0-9]+)\).*?<b[^>]*.?>(.*?)</b>.*?<span[^>]*.?>(.*?)</span>|ims';
if(preg_match_all($pattern,$data,$matches,PREG_SET_ORDER)){
$tmp=array();
foreach($matches as $file){
$tmp[]=array(
"http://cs{$file[2]}.vkontakte.ru/u{$file[3]}/audio/{$file[4]}.mp3",
$file[6].' - '.strip_tags($file[7]));
}
}
return $tmp;
}
function get_my_music(){
return $this->get_music($this->id);
}
function get_friends($id){
$url="http://vkontakte.ru/friend.php?id=$id";
$path="friends/$id.dat";
if(is_readable($path)!=false/* && filemtime($path)<24*60*60*7*/){
$data=file_get_contents($path);
}
else{
$i=2;
do{
print "#".(log($i)/log(2))."<br>";
$i*=2;
$ch = curl_init($url);
print "download $url";
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $this->cookie);
$data=curl_exec($ch);
sleep($i);
flush();
}while(stripos($data,"Location: blank.php") && stripos($data,"Страница скрыта"));
// print $data;
$data=$this->get_data($data);
// print $data;
file_put_contents($path,$data);
}
return $this->parse_page($data);
}
function add_to_black_list($id){
$url="http://vkontakte.ru/settings.php?act=addToBlackList&id=$id";
print "download $url<br />";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $this->cookie);
$data=curl_exec($ch);
flush();
}
function del_from_black_list($id){
$url="http://vkontakte.ru/settings.php?act=delFromBlackList&id=$id";
print "download $url<br />";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $this->cookie);
$data=curl_exec($ch);
flush();
}
function form_list($fr,$fr_id){
foreach($fr as $k=>$name){
if(isset($this->my_friends[$k]) || $k==$this->id )continue;
if(isset($this->pop_list[$k])){
$this->pop_list[$k]['num']++;
$this->pop_list[$k]['names'].=", ". $this->my_friends[$fr_id];
}
else{
$this->pop_list[$k]['num']=1;
$this->pop_list[$k]['names']=$this->my_friends[$fr_id];
}
}
}
function get_maybe_friends(){
$this->friends=$this->get_friends($this->id);
$this->my_friends=$this->friends;
$i=0;
foreach ($this->my_friends as $fr_id=>$name){
$i++;
$fr=$this->get_friends($fr_id);
$this->form_list($fr,$fr_id);
foreach($fr as $k=>$name){
if(!isset($this->friends[$k])){$this->friends[$k]=$name;}
}
}
uasort($this->pop_list,"compar_num");
// arsort($this->pop_list);
$i=0;
foreach($this->pop_list as $k=>$arr){
if($arr['num']>=1){
$i++;
print "$i. <a href='http://vkontakte.ru/profile.php?id=$k'>{$this->friends[$k]}</a> - {$arr['num']} ({$arr['names']}) <br>";
}
}
}
}
function compar_num($a, $b){
if ($a['num'] == $b['num']) {
return 0;
}
return ($a['num'] < $b['num']) ? 1 : -1;
}
$obj= new friends_vkontakte;
//print $obj->get_maybe_friends(); //получение друзей друзей
$mp3s=$obj->get_my_music();
$path='C:\downloads\Музыка\vkon\\';
$num=count($mp3s);
$max=9999;
$ind=$max-$num;
foreach($mp3s as $k=>$mp3){
printf("<a href={$mp3[0]}>%03d - {$mp3[1]}</a><br />",$k+1); //печать ссылок
//переименование
$filename=basename($mp3[0]);
$title=sprintf("%03d - {$mp3[1]}.mp3",($k+1)+$ind);
$title=str_replace('\\','',$title);
$title=str_replace('/','',$title);
$title=str_replace(':','',$title);
if(!is_file($path.$filename))
copy($mp3[0],$path.$filename);
copy($path.$filename,$path.'sorted\\'.$title);
print "$title <br />";
}
?>
</body>
</html>