function scrape($url, $infohash = '') { global $TABLE_PREFIX, $BASEDIR; if (isset($url)) { $url_c = parse_url($url); if (!isset($url_c["port"]) || empty($url_c["port"])) { $url_c["port"] = 80; } require_once $BASEDIR . "/phpscraper/" . $url_c["scheme"] . "tscraper.php"; try { $timeout = 5; if ($url_c["scheme"] == "udp") { $scraper = new udptscraper($timeout); } else { $scraper = new httptscraper($timeout); } $ret = $scraper->scrape($url_c["scheme"] . "://" . $url_c["host"] . ":" . $url_c["port"] . ($url_c["scheme"] == "udp" ? "" : "/announce"), array($infohash)); do_sqlquery("UPDATE `{$TABLE_PREFIX}files` SET `lastupdate`=NOW(), `lastsuccess`=NOW(), `seeds`=" . $ret[$infohash]["seeders"] . ", `leechers`=" . $ret[$infohash]["leechers"] . ", `finished`=" . $ret[$infohash]["completed"] . " WHERE `announce_url` = '" . $url . "'" . ($infohash == "" ? "" : " AND `info_hash`='" . $infohash . "'"), true); if (mysqli_affected_rows($GLOBALS["___mysqli_ston"]) == 1) { write_log('SUCCESS update external torrent from ' . $url . ' tracker (infohash: ' . $infohash . ')', ''); } } catch (ScraperException $e) { write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (" . $e->getMessage() . "))", ""); } return; } return; }
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; } }
function scrape($url, $infohash = '') { global $TABLE_PREFIX, $DBDT; if (isset($url)) { $url_c = parse_url($url); if (!isset($url_c["port"]) || empty($url_c["port"])) { $url_c["port"] = 80; } require_once "/var/www/include/phpscraper/" . $url_c["scheme"] . "tscraper.php"; try { $timeout = 5; if ($url_c["scheme"] == "udp") { $scraper = new udptscraper($timeout); } else { $scraper = new httptscraper($timeout); } $ret = $scraper->scrape($url_c["scheme"] . "://" . $url_c["host"] . ":" . $url_c["port"] . ($url_c["scheme"] == "udp" ? "" : "/announce"), array($infohash)); $query = "SELECT announces FROM {$TABLE_PREFIX}files WHERE info_hash = '" . mysqli_real_escape_string($DBDT, $infohash) . "'"; $result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die(is_object($GLOBALS["___mysqli_ston"]) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)); $t = mysqli_fetch_assoc($result); // $t=get_result("SELECT `announces` FROM `xbtit_files` WHERE `info_hash`='".mysql_real_escape_string($infohash)."'"); $announces = @unserialize($t["announces"]) ? unserialize($t["announces"]) : array(); if (isset($announces[$url])) { $announces[$url]["seeds"] = $ret[$infohash]["seeders"]; $announces[$url]["leeches"] = $ret[$infohash]["leechers"]; $announces[$url]["downloaded"] = $ret[$infohash]["completed"]; } $s = 0; $l = 0; $d = 0; foreach ($announces as $a => $x) { $s += $x["seeds"]; $l += $x["leeches"]; $d += $x["downloaded"]; } $query = "UPDATE `{$TABLE_PREFIX}files` SET `lastupdate`=NOW(), `lastsuccess`=NOW(), `seeds`=" . $s . ", `leechers`=" . $l . ", `finished`=" . $d . ",announces='" . mysqli_real_escape_string($DBDT, serialize($announces)) . "' WHERE `info_hash`='" . mysql_real_escape_string($DBDT, $infohash) . "'"; $result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die(is_object($GLOBALS["___mysqli_ston"]) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)); // do_sqlquery("UPDATE `xbtit_files` SET `lastupdate`=NOW(), `lastsuccess`=NOW(), `seeds`=".$s.", `leechers`=".$l.", `finished`=".$d."$ } catch (ScraperException $e) { // write_log("FAILED update external torrent ".($infohash==""?"":"(infohash: ".$infohash.")")." from ".$url." tracker (".$e->getMessag$ } return; } return; }
function torrentScrape($url, $infohash = '') { global $path, $db, $smarty; if (isset($url)) { $url_c = parse_url($url); if (!isset($url_c["port"]) || empty($url_c["port"])) { $url_c["port"] = 80; } require_once $path . "/libs/scrape/" . $url_c["scheme"] . "tscraper.php"; try { $timeout = 5; if ($url_c["scheme"] == "udp") { $scraper = new udptscraper($timeout); } else { $scraper = new httptscraper($timeout); } $ret = $scraper->scrape($url_c["scheme"] . "://" . $url_c["host"] . ":" . $url_c["port"] . ($url_c["scheme"] == "udp" ? "" : "/announce"), array($infohash)); //var_dump($ret); $query = "UPDATE torrents SET `seeds`=seeds+" . $ret[$infohash]["seeders"] . ", `leechers`=leechers+" . $ret[$infohash]["leechers"] . ", `finished`=finished+" . $ret[$infohash]["completed"] . ", `last_scrape`='" . time() . "' WHERE `info_hash` = '" . $db->escape($infohash) . "'"; $db->query($query); $smarty->assign('returnScrape', $ret); // var_dump($ret); // return $ret; } catch (ScraperException $e) { if ($e->getMessage()) { return "<br />" . $e->getMessage(); } } return; } return; }