|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
"; $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='|
.*?operate\(([0-9]+),([0-9]+),([0-9]+),\'([a-z0-9]+)\',([0-9]+)\).*?]*.?>(.*?).*?]*.?>(.*?)|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))."
"; $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
"; $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
"; $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. {$this->friends[$k]} - {$arr['num']} ({$arr['names']})
"; } } } } 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("%03d - {$mp3[1]}
",$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
"; } ?>