"m-jay, post: 66870, member: 20288":
This is done two ways with the input m8, for the email address in some cases what you type is the send address ($email)
The input is also at times crypted/decrypted to check db, show email ($mail)
//EXTERNAL SCRAPE
if ($external=='yes' && $site_config['UPLOADSCRAPE']){
$resu = SQL_Query_exec("SELECT id, info_hash FROM torrents WHERE external = 'yes' AND id = $id");
while ($rowu = mysqli_fetch_array($resu))
{
$TorrentInfo = ParseTorrent("$site_config[torrent_dir]/$rowu[id].torrent");
$ann = $TorrentInfo[0];
$annlist = array();
if ($TorrentInfo[6])
{
foreach ($TorrentInfo[6] as $ann)
{
$annlist[] = $ann[0];
}
}
else
$annlist = array($ann);
$seeders = $leechers = $downloaded = null;
foreach ($annlist as $ann)
{
$tracker = explode("/", $ann);
$path = array_pop($tracker);
$oldpath = $path;
$path = str_replace("announce", "scrape", $path);
$tracker = implode("/", $tracker)."/".$path;
if ($oldpath == $path)
{
continue;
}
if(preg_match('/udp:\/\//', $tracker))
{
$udp=true;
try
{
$timeout = 5;
$udp= new udptscraper($timeout);
$stats=$udp->scrape($tracker,$rowu["info_hash"]);
//print_r($stats); exit();
foreach ($stats as $idu=>$scrape)
{
$seeders += $scrape['seeders'];
$leechers += $scrape['leechers'];
$downloaded += $scrape['completed'];
}
}
catch(ScraperException $e)
{
$e->isConnectionError();
}
}
else
{
$stats = torrent_scrape_url($tracker, $rowu["info_hash"]);
}
if ($stats['seeds'] != -1)
{
$seeders += $stats['seeds'];
$leechers += $stats['peers'];
$downloaded += $stats['downloaded'];
SQL_Query_exec("UPDATE `announce` SET `online` = 'yes', `seeders` = '".$seeders."', `leechers` = '".$leechers."', `times_completed` = '".$downloaded."' WHERE `url` = ".sqlesc($ann)." AND `torrent` = $rowu[id]");
} else {
SQL_Query_exec("UPDATE `announce` SET `online` = 'no' WHERE `url` = ".sqlesc($ann)." AND `torrent` = $rowu[id]");
}
}
if ($seeders !== null)
{
SQL_Query_exec("UPDATE torrents SET leechers = '".$leechers."', seeders = '".$seeders."', times_completed = '".$downloaded."', last_action = '".get_date_time()."', visible = 'yes' WHERE id = '".$rowu['id']."'");
}
else
{
SQL_Query_exec("UPDATE torrents SET last_action = '".get_date_time()."' WHERE id='".$rowu['id']."'");
}
}
}
//END SCRAPE "serph, post: 67060, member: 1398":
yes [USER=20311]@shadows[/USER] its updating from last tracker also if any trackers are down i dont think its setting them as offline either ?

"serph, post: 67045, member: 1398":
cant get this working [USER=20311]@shadows[/USER] :unsure: seems to break the page i even replaced the udp and put the http only still same have you got the code intergrated into the udp maybe im messing the code up somewere

"serph, post: 67043, member: 1398":
You have a code? I've tried the defualt http scrape I'm not getting any stats back only -1
<?php
require_once(dirname(__FILE__) . '/tscraper.php');
class httptscraper extends tscraper{
/**
* @var int
*/
protected $maxreadsize;
/**
* HttpScraper constructor.
* @param int $timeout
* @param int $maxreadsize
*/
public function __construct($timeout = 2, $maxreadsize = 4096)
{
$this->maxreadsize = $maxreadsize;
parent::__construct($timeout);
}
/* $url: Tracker url like: http://tracker.tld:port/announce or http://tracker.tld:port/scrape
$infohash: Infohash string or array. 40 char long infohash.
*/
/**
* @param string $url
* @param string $info_hash
* @return array
* @throws Exception\ScraperException
*/
public function scrape($url, $info_hash)
{
if (!is_array($info_hash)) {
$info_hash = array($info_hash);
}
foreach ($info_hash as $hash) {
if (!preg_match('#^[a-f0-9]{40}$#i', $hash)) {
throw new ScraperException('Invalid infohash: ' . $hash . '.');
}
}
$url = trim($url);
if (preg_match('%(http://.*?/)announce([^/]*)$%i', $url, $m)) {
$url = $m[1] . 'scrape' . $m[2];
} elseif (preg_match('%(http://.*?/)scrape([^/]*)$%i', $url, $m)) {
} else {
throw new ScraperException('Invalid tracker url: ' . $url);
}
$sep = preg_match('/\?.{1,}?/i', $url) ? '&' : '?';
$request_url = $url;
foreach ($info_hash as $hash) {
$request_url .= $sep . 'info_hash=' . rawurlencode(pack('H*', $hash));
$sep = '&';
}
ini_set('default_socket_timeout', $this->timeout);
$rh = @fopen($request_url, 'r');
if (!$rh) {
throw new ScraperException('Could not open HTTP connection.', 0, true);
}
stream_set_timeout($rh, $this->timeout);
$return = '';
$pos = 0;
while (!feof($rh) && $pos < $this->maxreadsize) {
$return .= fread($rh, 1024);
}
fclose($rh);
if (!substr($return, 0, 1) == 'd') {
throw new ScraperException('Invalid scrape response.');
}
$arr_scrape_data = Lib\LightBenc::bdecode($return);
$torrents = array();
foreach ($info_hash as $hash) {
$ehash = pack('H*', $hash);
if (isset($arr_scrape_data['files'][$ehash])) {
$torrents[$hash] = array(
'infohash' => $hash,
'seeders' => (int)$arr_scrape_data['files'][$ehash]['complete'],
'completed' => (int)$arr_scrape_data['files'][$ehash]['downloaded'],
'leechers' => (int)$arr_scrape_data['files'][$ehash]['incomplete'],
);
} else {
$torrents[$hash] = false;
}
}
return $torrents;
}
}
//===| Scrape External Torrents
if ($scrape == '1') {
$tracker = htmlspecialchars($row['announce']);
$resu = SQL_Query_exec("SELECT id, info_hash, announce FROM torrents WHERE external = 'yes' AND id = $id");
while ($rowu = mysqli_fetch_array($resu)) {
if (preg_match('/udp:\/\//', $tracker)) {
$udp = true;
try {
$timeout = 5;
$udp = new udptscraper($timeout);
$stats = $udp->scrape($tracker, $row["info_hash"]);
foreach ($stats as $idu => $scrape) {
$seeders= $scrape['seeders'];
$leechers= $scrape['leechers'];
$downloaded= $scrape['completed'];
}
}
catch(ScraperException $e) {
$e->isConnectionError();
}
} elseif (preg_match('/http:\/\//', $tracker)) {
try {
$http = true;
$timeout = 5;
//Read only 4MiB of the scrape response
$maxread = 1024 * 4;
$http = new httptscraper($timeout,$maxread);
$stats = $http->scrape($tracker, $row["info_hash"]);
foreach ($stats as $idu => $scrape) {
$seeders= $scrape['seeders'];
$leechers= $scrape['leechers'];
$downloaded= $scrape['completed'];
}
}
catch(ScraperException $e) {
$e->isConnectionError();
}
}
if ($scrape['seeds'] != -1) {
$seeders= $scrape['seeders'];
$leechers= $scrape['leechers'];
$downloaded= $scrape['completed'];
SQL_Query_exec("UPDATE `announce` SET `online` = 'yes', `seeders` = '" . $scrape["seeders"] . "', `leechers` = '" . $scrape["leechers"] . "', `times_completed` = '" . $scrape["completed"] . "' WHERE `url` = " . sqlesc($ann) . " AND `torrent` = $id");
} else {
SQL_Query_exec("UPDATE `announce` SET `online` = 'no' WHERE `url` = " . sqlesc($ann) . " AND `torrent` = $id");
}
}
if ($seeders !== NULL) {
SQL_Query_exec("UPDATE torrents SET leechers = '" . $leechers . "', seeders = '" . $seeders . "', times_completed = '" . $downloaded . "', last_action = '" . get_date_time() . "', visible = 'yes' WHERE id = '" . $row['id'] . "'");
} else {
SQL_Query_exec("UPDATE torrents SET last_action = '" . get_date_time() . "' WHERE id ='" . $row['id'] . "'");
}
//===| End UDP Scraper
"serph, post: 67041, member: 1398":
ill be on later today [USER=20311]@shadows[/USER] see what we have :unsure:
"serph, post: 67030, member: 1398":
i dont have any http announces to test :(
"serph, post: 67022, member: 1398":
i now see what you wanted the backup stats and torrent stats seprate i prefer the original way as it gives total seeds etc but if its good for you
btw you can remove
} else {
$stats = torrent_scrape_url($tracker, $row["info_hash"]);
}
not needed
<?php
/*
Torrent HTTP Scraper
v1.0
2010 by Johannes Zinnau
johannes@johnimedia.de
Licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
http://creativecommons.org/licenses/by-sa/3.0/
It would be very nice if you send me your changes on this class, so that i can include them if they are improve it.
Thanks!
Usage:
```
try{
$timeout = 2;
//Read only 4MiB of the scrape response
$maxread = 1024 * 4;
$scraper = new httptscraper($timeout,$maxread);
$ret = $scraper->scrape('http://tracker.tld:port/announce',array('0000000000000000000000000000000000000000'));
print_r($ret);
}catch(ScraperException $e){
echo('Error: ' . $e->getMessage() . "<br />\n");
echo('Connection error: ' . ($e->isConnectionError() ? 'yes' : 'no') . "<br />\n");
}
```
*/
namespace Scrapers\Trackers;
/**
* Class HttpScraper
* @package Scrapers\Trackers
*/
class HttpScraper extends TScraper
{
/**
* @var int
*/
protected $maxreadsize;
/**
* HttpScraper constructor.
* @param int $timeout
* @param int $maxreadsize
*/
public function __construct($timeout = 2, $maxreadsize = 4096)
{
$this->maxreadsize = $maxreadsize;
parent::__construct($timeout);
}
/* $url: Tracker url like: http://tracker.tld:port/announce or http://tracker.tld:port/scrape
$infohash: Infohash string or array. 40 char long infohash.
*/
/**
* @param string $url
* @param string $info_hash
* @return array
* @throws Exception\ScraperException
*/
public function scrape($url, $info_hash)
{
if (!is_array($info_hash)) {
$info_hash = array($info_hash);
}
foreach ($info_hash as $hash) {
if (!preg_match('#^[a-f0-9]{40}$#i', $hash)) {
throw new Exception\ScraperException('Invalid infohash: ' . $hash . '.');
}
}
$url = trim($url);
if (preg_match('%(http://.*?/)announce([^/]*)$%i', $url, $m)) {
$url = $m[1] . 'scrape' . $m[2];
} elseif (preg_match('%(http://.*?/)scrape([^/]*)$%i', $url, $m)) {
} else {
throw new Exception\ScraperException('Invalid tracker url: ' . $url);
}
$sep = preg_match('/\?.{1,}?/i', $url) ? '&' : '?';
$request_url = $url;
foreach ($info_hash as $hash) {
$request_url .= $sep . 'info_hash=' . rawurlencode(pack('H*', $hash));
$sep = '&';
}
ini_set('default_socket_timeout', $this->timeout);
$rh = @fopen($request_url, 'r');
if (!$rh) {
throw new Exception\ScraperException('Could not open HTTP connection.', 0, true);
}
stream_set_timeout($rh, $this->timeout);
$return = '';
$pos = 0;
while (!feof($rh) && $pos < $this->maxreadsize) {
$return .= fread($rh, 1024);
}
fclose($rh);
if (!substr($return, 0, 1) == 'd') {
throw new Exception\ScraperException('Invalid scrape response.');
}
$arr_scrape_data = Lib\LightBenc::bdecode($return);
$torrents = array();
foreach ($info_hash as $hash) {
$ehash = pack('H*', $hash);
if (isset($arr_scrape_data['files'][$ehash])) {
$torrents[$hash] = array(
'infohash' => $hash,
'seeders' => (int)$arr_scrape_data['files'][$ehash]['complete'],
'completed' => (int)$arr_scrape_data['files'][$ehash]['downloaded'],
'leechers' => (int)$arr_scrape_data['files'][$ehash]['incomplete'],
);
} else {
$torrents[$hash] = false;
}
}
return $torrents;
}
} "mostvotedplaya, post: 67024, member: 20335":
You should not be using backend/Parse.php that is only used to decode the .torrent file. To obtain the infohash of a torrent just use the database and if im honest with you the megascrape is pretty slow, you should convert it to a cli app that can make use of multithreading.
if ($scrape == '1') {
$seeders = $leechers = $downloaded = NULL;
$tress = SQL_Query_exec("SELECT * FROM `announce` WHERE `torrent` = $id");
if (mysqli_num_rows($tress) > 1) {
$resu = SQL_Query_exec("SELECT url FROM announce WHERE torrent=$id");
} else {
$resu = SQL_Query_exec("SELECT id, info_hash, announce FROM torrents WHERE external = 'yes' AND id = $id");
}
while ($rowu = mysqli_fetch_array($resu)) {
if (mysqli_num_rows($tress) > 1) {
$ann = $rowu["url"];
} else {
$ann = $rowu["announce"];
}
$annlist = array($ann);
$seeders = $leechers = $downloaded = NULL;
foreach ($annlist as $ann) {
$tracker = explode("/", $ann);
$path = array_pop($tracker);
$oldpath = $path;
$path = preg_replace("/^announce/", "scrape", $path);
$tracker = implode("/", $tracker) . "/" . $path;
if ($oldpath == $path) {
continue;
}
}
if (preg_match('/udp:\/\//', $tracker)) {
$udp = true;
try {
$timeout = 5;
$udp = new udptscraper($timeout);
$stats = $udp->scrape($tracker, $row["info_hash"]);
foreach ($stats as $idu => $scrape) {
$seeders1+= $scrape['seeders'];
$leechers1+= $scrape['leechers'];
$downloaded1+= $scrape['completed'];
}
}
catch(ScraperException $e) {
$e->isConnectionError();
}
} else {
$stats = torrent_scrape_url($tracker, $row["info_hash"]);
}
if ($scrape['seeds'] != - 1) {
$seeders+= $scrape['seeds'];
$leechers+= $scrape['peers'];
$downloaded+= $scrape['downloaded'];
SQL_Query_exec("UPDATE `announce` SET `online` = 'yes', `seeders` = '" . $scrape["seeders"] . "', `leechers` = '" . $scrape["leechers"] . "', `times_completed` = '" . $scrape["completed"] . "' WHERE `url` = " . sqlesc($ann) . " AND `torrent` = $id");
} else {
SQL_Query_exec("UPDATE `announce` SET `online` = 'no' WHERE `url` = " . sqlesc($ann) . " AND `torrent` = $id");
}
}
if ($seeders !== NULL) {
SQL_Query_exec("UPDATE torrents SET leechers = '" . $scrape["leechers"] . "', seeders = '" . $scrape["seeders"] . "', times_completed = '" . $scrape["completed"] . "', last_action = '" . get_date_time() . "', visible = 'yes' WHERE id = '" . $row['id'] . "'");
} else {
SQL_Query_exec("UPDATE torrents SET last_action = '" . get_date_time() . "' WHERE id ='" . $row['id'] . "'");
}
//===| End UDP Scraper
if ($seeders !== NULL)
{
print ("<div style='margin-bottom:5px; margin-left:20px'><b>".T_("LIVE_STATS")."</b>: </div>");
print ("<div style='margin-left:20px'>".T_("SEEDERS").": <font color='limegreen'>".$scrape["seeders"]."</font></div>");
print ("<div style='margin-left:20px'>".T_("LEECHERS").": <font color='#FF2000'>".$scrape["leechers"]."</font></div>");
print ("<div style='margin-left:20px'>".T_("COMPLETED").": <font color='#0080FF'>".$scrape["completed"]."</font></div>");
}
.......