Requested by [USER=19833]@Botanicar[/USER] new scraper to replace broken base one. Pretty basic at minute ideally it should be added to upload as well instead you must refresh page for stats, maybe should be on automatic timer so only scrapes every three days if torrent viewed etc
Been meaning to do this for a while, using https://www.torrenttrader.xyz/index.php?threads/scrape-udp-trackers.9795/ and https://github.com/johannes85/PHP-Torrent-Scraper/tree/master/src
Writing for pdo but if any one wants to try on v3 feel free to post - for v3 you would need to add the classes to backend and require them at top of functions.php the rest would just be query's
I dont use this so please share any thoughts on improvement
Need tests on pdo before i add to base but seems to work fine
unzip classes folder
add the classes to the classes folder (scraper.php, scraperexception.php, updscraper.php)
in views/torrent/read.php find
Replace everything below with
Been meaning to do this for a while, using https://www.torrenttrader.xyz/index.php?threads/scrape-udp-trackers.9795/ and https://github.com/johannes85/PHP-Torrent-Scraper/tree/master/src
Writing for pdo but if any one wants to try on v3 feel free to post - for v3 you would need to add the classes to backend and require them at top of functions.php the rest would just be query's
I dont use this so please share any thoughts on improvement
Need tests on pdo before i add to base but seems to work fine
unzip classes folder
add the classes to the classes folder (scraper.php, scraperexception.php, updscraper.php)
in views/torrent/read.php find
<!--buttonsstart-->Replace everything below with
<!--buttonsstart-->
<td align="left"> <?php
/// Scrape code
/// Scrape code
//===| Scrape External Torrents
if ($row["external"] == 'yes') {
print("<td width='160' align='right' valign='top'><table><tr>");
if ($scrape == '1') {
print("<td class='table_col1' width='150' valign='middle'>
<div style='margin-top:5px; margin-bottom:10px; font:bold 16px Times' align='center'><font color='#FF2000'>" . T_("EXTERNAL_TORRENT") . "</font></div>");
$resu = DB::run("SELECT id, info_hash FROM torrents WHERE external = 'yes' AND id = $id");
while ($rowu = $resu->fetch(PDO::FETCH_ASSOC)) {
//parse torrent file
$torrent_dir = $config["torrent_dir"];
$TorrentInfo = array();
$TorrentInfo = ParseTorrent("$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 Udpscraper($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"]);
/*
$http = true;
try {
$timeout = 5;
$http = new HttpScraper($timeout);
$stats = $http->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 $exc) {
$exc->isConnectionError();
}
*/
}
if ($stats['seeds'] != -1) {
$seeders += $stats['seeds'];
$leechers += $stats['peers'];
$downloaded += $stats['downloaded'];
DB::run("
UPDATE `announce`
SET `online` = ?, `seeders` = ?, `leechers` = ?, `times_completed` = ?
WHERE `url` = ?
AND `torrent` = ?",
['yes', $stats['seeds'], $stats['peers'], $stats['downloaded'], $ann, $rowu['id']]);
} else {
DB::run("
UPDATE `announce`
SET `online` = ?
WHERE `url` = ?
AND `torrent` = ?",
['no', $ann, $rowu['id']]);
}
}
if ($seeders !== null) {
DB::run("
UPDATE torrents
SET leechers = ?, seeders = ?, times_completed = ?, last_action = ?, visible = ?
WHERE id = ?",
[$leechers, $seeders, $downloaded, get_date_time(), 'yes', $rowu['id']]);
} else {
DB::run("
UPDATE torrents
SET last_action = ?
WHERE id=?", [get_date_time(), $rowu['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'>" . $seeders . "</font></div>");
print("<div style='margin-left:20px'>" . T_("LEECHERS") . ": <font color='#FF2000'>" . $leechers . "</font></div>");
print("<div style='margin-left:20px'>" . T_("COMPLETED") . ": <font color='#0080FF'>" . $downloaded . "</font></div>");
print("</br>");
} else {
print("<div style='margin-top:10px; margin-bottom:5px' align='center'><b>" . T_("LIVE_STATS") . "</b>: </div>");
print("<div style='font:italic 14px Times' align='center'><font color='#FF2000'>" . T_("TRACKERS_OFFLINE") . "!</font></div>");
}
print("</td>");
} else {
print("<td class='table_col1' width='150' valign='middle' align='center'>
<div style='margin-top:5px; margin-bottom:10px; font:bold 16px Times' align='center'><font color='#FF2000'>" . T_("EXTERNAL_TORRENT") . "</font></div>
</div>
<form action='$config[SITEURL]/torrents/read?id=$id&scrape=1' method='post'>
<div style='margin-top:5px; margin-bottom:10px' align='center'><input type='submit' name='submit' value=" . T_("UPDATE_STATS") . " /></div>
</form>
</td>");
}
print("</tr></table></td>");
}
//===| End Scrape External Torrents
?>
</td>
</td>
</tr>
</table>
<?php
}
//DISPLAY NFO BLOCK
if ($row["nfo"] == "yes") {
$nfofilelocation = "$nfo_dir/$row[id].nfo";
$filegetcontents = file_get_contents($nfofilelocation);
// needs filtering better todo
// $nfo = htmlspecialchars($filegetcontents);
$nfo = $filegetcontents;
if ($nfo) {
$nfo = my_nfo_translate($nfo);
echo "<br /><br /><b>NFO:</b><br />";
print("<div><textarea class='nfo' style='width:98%;height:100%;' rows='20' cols='20' readonly='readonly'>" . stripslashes($nfo) . "</textarea></div>");
} else {
print(T_("ERROR") . " reading .nfo file!");
}
}
