Scrape external for seeder/leechers for v3
Scrape on torrents-upload.php & torrent-details.php
if internal with multiple trackers remove if here
SQL to store announcelist
in backend/functions.php
find
below add
add scrape function
in torents-upload.php
find
replace with
add $announcelist & add to torrent insert on end
in torrent-details.php find
replace with
add announcelist to big select query
eg
place scraper file in backend folder
Fully tested on v3
Scrape on torrents-upload.php & torrent-details.php
if internal with multiple trackers remove if here
if ($external=='yes' && $site_config['UPLOADSCRAPE']){
ScrapeId($id, $annlist, $infohash);
} SQL to store announcelist
ALTER TABLE `torrents` ADD `announcelist` longtext DEFAULT NULL;in backend/functions.php
find
require_once(BACKEND."/mysql.class.php");below add
require_once("backend/scraper.php");add scrape function
function ScrapeId($id, $annlist, $infohash)
{
$scraper = new Scraper();
try {
$scraped = $scraper->scrape($infohash, $annlist, 20, 4, true );
} catch (Exception $e) {
$json = json_encode($e);
show_error_msg(T_("ERROR"), $json, 1);
}
$myarray = array_shift($scraped);
$seeders = $leechers = $completed = 0;
if ($myarray['seeders'] > 0) {
$seeders = $myarray['seeders'];
}
if ($myarray['leechers'] > 0) {
$leechers = $myarray['leechers'];
}
if ($myarray['completed'] > 0) {
$completed = $myarray['completed'];
}
if ($seeders !== 0) {
SQL_Query_exec("UPDATE torrents SET leechers='".$leechers."', seeders='".$seeders."',times_completed='".$completed."',last_action= '".get_date_time()."',visible='yes' WHERE id='".$id."'");
} else {
show_error_msg(T_("ERROR"), 'error or dead torrent', 1);
}
return $myarray;
}in torents-upload.php
find
//EXTERNAL SCRAPE
if ($external=='yes' && $site_config['UPLOADSCRAPE']){
$tracker=str_replace("/announce","/scrape",$announce);
$stats = torrent_scrape_url($tracker, $infohash);
$seeders = (int) strip_tags($stats['seeds']);
$leechers = (int) strip_tags($stats['peers']);
$downloaded = (int) strip_tags($stats['downloaded']);
SQL_Query_exec("UPDATE torrents SET leechers='".$leechers."', seeders='".$seeders."',times_completed='".$downloaded."',last_action= '".get_date_time()."',visible='yes' WHERE id='".$id."'");
}
//END SCRAPEreplace with
//EXTERNAL SCRAPE
if ($external=='yes' && $site_config['UPLOADSCRAPE']){
ScrapeId($id, $annlist, $infohash);
}
//END SCRAPEadd $announcelist & add to torrent insert on end
$announce_list = serialize($annlist);
$ret = SQL_Query_exec("INSERT INTO torrents (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, announce, external, nfo, torrentlang, anon, last_action, announcelist) VALUES (".sqlesc($fname).", '".$CURUSER['id']."', ".sqlesc($name).", ".sqlesc($descr).", '".$inames[0]."', '".$inames[1]."', '".$catid."', '" . get_date_time() . "', '".$infohash."', '".$torrentsize."', '".$filecount."', ".sqlesc($fname).", '".$announce."', '".$external."', '".$nfo."', '".$langid."','$anon', '".get_date_time()."', '$announce_list')");
in torrent-details.php find
if ($scrape =='1'){
print("<td valign='top' align='right'><b>Tracked: </b>EXTERNAL<br /><br />");
$seeders1 = $leechers1 = $downloaded1 = null;
$tres = SQL_Query_exec("SELECT url FROM announce WHERE torrent=$id");
while ($trow = mysqli_fetch_assoc($tres)) {
$ann = $trow["url"];
$tracker = explode("/", $ann);
$path = array_pop($tracker);
$oldpath = $path;
$path = preg_replace("/^announce/", "scrape", $path);
$tracker = implode("/", $tracker)."/".$path;
if ($oldpath == $path) {
continue; // Scrape not supported, ignored
}
// TPB's tracker is dead. Use openbittorrent instead
if (preg_match("/thepiratebay.org/i", $tracker) || preg_match("/prq.to/", $tracker)) {
$tracker = "http://tracker.openbittorrent.com/scrape";
}
$stats = torrent_scrape_url($tracker, $row["info_hash"]);
if ($stats['seeds'] != -1) {
$seeders1 += $stats['seeds'];
$leechers1 += $stats['peers'];
$downloaded1 += $stats['downloaded'];
SQL_Query_exec("UPDATE `announce` SET `online` = 'yes', `seeders` = $stats[seeds], `leechers` = $stats[peers], `times_completed` = $stats[downloaded] WHERE `url` = ".sqlesc($ann)." AND `torrent` = $id");
} else {
SQL_Query_exec("UPDATE `announce` SET `online` = 'no' WHERE `url` = ".sqlesc($ann)." AND `torrent` = $id");
}
}
if ($seeders1 !== null){ //only update stats if data is received
print ("<b>".T_("LIVE_STATS").": </b><br />");
print ("Seeders: ".number_format($seeders1)."<br />");
print ("Leechers: ".number_format($leechers1)."<br />");
print (T_("COMPLETED").": ".number_format($downloaded1)."<br />");
SQL_Query_exec("UPDATE torrents SET leechers='".$leechers1."', seeders='".$seeders1."', times_completed='".$downloaded1."',last_action= '".get_date_time()."',visible='yes' WHERE id='".$row['id']."'");
}else{
print ("<b>".T_("LIVE_STATS").": </b><br />");
print ("<font color='#ff0000'>Tracker Timeout<br />Please retry later</font><br />");
}
print ("<form action='torrents-details.php?id=$id&scrape=1' method='post'><input type=\"submit\" name=\"submit\" value=\"Update Stats\" /></form></td>");
}else{
print ("<td valign='top' align='right'><b>Tracked:</b> EXTERNAL<br /><br /><form action='torrents-details.php?id=$id&scrape=1' method='post'><input type=\"submit\" name=\"submit\" value=\"Update Stats\" /></form></td>");
}replace with
if ($scrape =='1'){
print("<td valign='top' align='right'><b>Tracked: </b>EXTERNAL<br /><br />");
$annlist = unserialize($row['announcelist']);
$stat = ScrapeId($id, $annlist, $row['info_hash']);
$seeders1 = $stat['seeders'] ?? 0;
$completed1 = $stat['completed'] ?? 0;
$leechers1 = $stat['leechers'] ?? 0;
if ($stat['seeders'] !== null){ //only update stats if data is received
print ("<b>".T_("LIVE_STATS").": </b><br />");
print ("Seeders: ".number_format($seeders1)."<br />");
print ("Leechers: ".number_format($leechers1)."<br />");
SQL_Query_exec("UPDATE torrents SET leechers='".$leechers1."', seeders='".$seeders1."', times_completed='".$completed1."',last_action= '".get_date_time()."',visible='yes' WHERE id='".$row['id']."'");
}else{
print ("<b>".T_("LIVE_STATS").": </b><br />");
print ("<font color='#ff0000'>Tracker Timeout<br />Please retry later</font><br />");
}
print ("<form action='torrents-details.php?id=$id&scrape=1' method='post'><input type=\"submit\" name=\"submit\" value=\"Update Stats\" /></form></td>");
}else{
print ("<td valign='top' align='right'><b>Tracked:</b> EXTERNAL<br /><br /><form action='torrents-details.php?id=$id&scrape=1' method='post'><input type=\"submit\" name=\"submit\" value=\"Update Stats\" /></form></td>");
}add announcelist to big select query
eg
$res = SQL_Query_exec("SELECT torrents.announcelist, torrents.seeders, torrents.banned, torrents.leechers, torrents.info_hash, torrents.filename, torrents.nfo, torrents.last_action, torrents.numratings, torrents.name, torrents.owner, torrents.save_as, torrents.descr, torrents.visible, torrents.size, torrents.added, torrents.views, torrents.hits, torrents.times_completed, torrents.id, torrents.type, torrents.external, torrents.image1, torrents.image2, torrents.announce, torrents.numfiles, torrents.freeleech, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.numratings, categories.name AS cat_name, torrentlang.name AS lang_name, torrentlang.image AS lang_image, categories.parent_cat as cat_parent, users.username, users.privacy FROM torrents LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN torrentlang ON torrents.torrentlang = torrentlang.id LEFT JOIN users ON torrents.owner = users.id WHERE torrents.id = $id");place scraper file in backend folder
Fully tested on v3
Last edited by M-jay
on 2022-12-14 17:15:29
on 2022-12-14 17:15:29
