if (strlen($ret) < $readlength) { throw new ScraperException('Too short scrape response.'); } $torrents = array(); $index = 8; foreach ($infohash as $hash) { $retd = unpack("Nseeders/Ncompleted/Nleechers", substr($ret, $index, 12)); $retd['infohash'] = $hash; $torrents[$hash] = $retd; $index = $index + 12; } return $torrents; } } #udptscraper End #Test code By Sharon try { $timeout = 2; $scraper = new udptscraper($timeout); $ret = $scraper->scrape('udp://tracker.openbittorrent.com:80', array('D6525C8CB07CBC6CE001A97541DAD408D4F1FFF0')); //print_r($ret); //for debug foreach ($ret as $key => $value) { echo 'INFO HASH :' . $value['infohash'] . '<br />'; echo 'SEEDS :' . $value['seeders'] . '<br />'; echo 'LEECHES :' . $value['leechers'] . '<br />'; echo 'COMPLETED :' . $value['completed'] . '<br />'; } } catch (ScraperException $e) { echo 'Error: ' . $e->getMessage() . "<br />\n"; echo 'Connection error: ' . ($e->isConnectionError() ? 'yes' : 'no') . "<br />\n"; }
function scrape($tid, $url, $info_hash) { $timeout = 5; $udp = new udptscraper($timeout); $http = new httptscraper($timeout); try { if (substr($url, 0, 6) == 'udp://') { $data = $udp->scrape($url, $info_hash); } else { $data = $http->scrape($url, $info_hash); } $data = $data[$info_hash]; sql_query('UPDATE torrents_scrape SET state = "ok", error = "", seeders = ' . intval($data['seeders']) . ', leechers = ' . intval($data['leechers']) . ' WHERE tid = ' . $tid . ' AND url = ' . sqlesc($url)) or print mysql_error() . "\n"; return true; } catch (ScraperException $e) { sql_query('UPDATE torrents_scrape SET state = "error", error = ' . sqlesc($e->getMessage()) . ', seeders = 0, leechers = 0 WHERE tid = ' . $tid . ' AND url = ' . sqlesc($url)) or print mysql_error() . "\n"; return false; } }
echo "<BR><B>{$ann}</B>: Scrape not supported.<BR>"; continue; } // TPB's tracker is dead. Use openbittorrent instead if ($openbittorrent_done) { continue; } if (preg_match("/thepiratebay.org/i", $tracker) || preg_match("/prq.to/", $tracker)) { $tracker = "http://tracker.openbittorrent.com/scrape"; $openbittorrent_done = 1; } if (preg_match('%udp://([^:/]*)(?::([0-9]*))?(?:/)?%si', $tracker)) { $udp = true; try { $timeout = 5; $udp = new udptscraper($timeout); $stats = $udp->scrape($tracker, $row["info_hash"]); foreach ($stats as $id => $scrape) { $seeders += $scrape['seeders']; $leechers += $scrape['leechers']; $downloaded += $scrape['completed']; } } catch (ScraperException $e) { echo 'Error: ' . $e->getMessage() . "\n"; //echo('Connection error: ' . ($e->isConnectionError() ? 'yes' : 'no') . "\n"); } } else { $stats = torrent_scrape_url($tracker, $row["info_hash"]); } if ($stats['seeds'] != -1) { $seeders += $stats['seeds'];
$trackers = array('udp://tracker.openbittorrent.com:80', 'udp://tracker.coppersurfer.tk:6969', 'udp://9.rarbg.com:2710', 'udp://9.rarbg.me:2710', 'udp://glotorrents.pw:6969', 'udp://tracker.trackerfix.com:80', 'udp://tracker.leechers-paradise.org:6969'); $from = 0; $query = $db->query("SELECT DISTINCT(hash) FROM rtindex WHERE hash!='' LIMIT {$from}, 73;"); $num = $query->num_rows; while ($num) { unset($hashes); unset($seeds); unset($leech); while ($data = $query->fetch_assoc()) { $hashes[] = $data['hash']; } foreach ($trackers as $tracker) { unset($scraper); try { $timeout = 2; $scraper = new udptscraper($timeout); $ret = $scraper->scrape($tracker, $hashes); foreach ($ret as $hash => $val) { $seeds[$hash] = max($val['seeders'], $seeds[$hash]); $leech[$hash] = max($val['leechers'], $leech[$hash]); } } catch (ScraperException $e) { } } foreach ($hashes as $hash) { $db->query("UPDATE rtindex SET seeds = {$seeds[$hash]}, peers = {$leech[$hash]} WHERE hash = '{$hash}';"); $sdb->query("UPDATE rtindex0,rtindex1,rtindex2,rtindex3 SET seeds = {$seeds[$hash]}, peers = {$leech[$hash]} WHERE hash = '{$hash}';"); } $from += 73; $query = $db->query("SELECT DISTINCT(hash) FROM rtindex WHERE hash!='' LIMIT {$from}, 73;"); $num = $query->num_rows;