Magnetic link package download
KeyWord = $ keyWord; $ this-> saveFile = $ saveFile; $ this-> minSize = $ minSize; $ this-> page = $ pageRange [0]; $ this-> maxPage = $ pageRange [1];} public function run () {while ($ this-> flag & $ this-> maxPage> $ this-> page) {$ this-> timestamp = $ this-> microtimeFloat (); $ this-> _ execute (); $ this-> page ++; $ this-> _ notice () ;}/ *** execute */protected function _ execute () {$ this-> _ getUrl (); $ this-> _ getHtmlPage (); $ this-> _ parseHtml (); if ($ this-> _ c UrrentMagnetCount) {// save $ this-> _ save () ;}} public function microtimeFloat () {list ($ usec, $ sec) when there is a magnetic link) = explode ("", microtime (); return sprintf ('% 01.2f', (float) $ usec + (float) $ sec );} /*** notification */protected function _ notice () {$ currentTime = $ this-> microtimeFloat (); $ useTime = sprintf ('% 01.2f ', $ currentTime-$ this-> timestamp); $ this-> timestamp = $ currentTime; echo 'quarter '. $ this-> page. 'page stored '. $ this-> _ current MagnetCount. 'magnetic link, time consumed '. $ useTime. "seconds \ r \ n"; if (! ($ This-> flag & $ this-> maxPage> $ this-> page) {echo 'total stored '. $ this-> _ magnetCount. 'magnetic links '. "\ r \ n" ;}}/*** set url */protected function _ getUrl () {$ this-> _ url = $ this-> host. 'search? Q = '. rawurlencode ($ this-> keyWord ). '& p = '. $ this-> page;}/*** get html file content */protected function _ getHtmlPage () {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_HEADER, false); curl_setopt ($ ch, CURLOPT_TIMEOUT, $ this-> timeout); curl_setopt ($ ch, CURLOPT_URL, $ this-> _ url); curl_setopt ($ ch, CURLOPT_SSLVERSION, 3); $ result = curl_exec ($ ch); if ($ result = false) {// echo 'curl error :'. curl_errno ($ ch ). ':'. curl _ Error ($ ch); $ opts = array ('https' => array ('method' => "GET", 'timeout' => $ this-> timeout, // unit: Seconds); $ context = stream_context_create ($ opts); $ this-> _ html = @ file_get_contents ($ this-> _ url, false, $ context );} else {$ this-> _ html = $ result;} curl_close ($ ch);}/*** capture magnetic link */protected function _ parseHtml () {preg_match_all ('/href = "(magnet \:\? Xt = urn \: btih \:. + ?) "/', $ This-> _ html, $ magnet); preg_match_all ('/attr_val"> (\ d +? \.? \ D *? [G | M | K] B)/', $ this-> _ html, $ size); if (empty ($ size [1]) {$ this-> flag = false; // when the magnetic link is not obtained, stop turning pages} foreach ($ size [1] as $ key => $ val) {if ($ this-> _ compareSize ($ val) {$ this-> _ magnet [] = $ magnet [1] [$ key];} $ this-> _ currentMagnetCount = count ($ this-> _ magnet); $ this-> _ magnetCount + = count ($ this-> _ magnet );} /*** compare the size of the magnetic link file */protected function _ compareSize ($ size) {$ number = substr ($ size, 0, strpos ($ size, ''); $ unit = substr ($ size, strpos ($ size,'') + 6); $ n = ''; switch ($ unit) {case 'GB': $ n = 1; break; case 'mb': $ n = 1024; break; case 'KB': $ n = 1048576; break; default: $ n = false;} if ($ n = false) {try {throw new Exception ("failed to identify file size units \ n");} catch (Exception $ e) {echo $ e-> getMessage (); return false ;}} return ($ this-> minSize <($ number/$ n ));} /*** save the magnetic link to the file */protected function _ save () {$ data = ''; foreach ($ this-> _ magnet as $ val) {$ data. = $ val. "\ n"; $ this-> magnetNum ++; if (0 ==$ this-> magnetNum % 15) $ data. = "\ n";} file_put_contents ($ this-> saveFile, $ data, FILE_APPEND); $ this-> _ magnet = array ();}} // example $ s = new Magnet ('Lol ', 'Magnet. log', 2, array (0, 10); $ s-> run ();