Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Scrape UDP trackers
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Mods in Progress

Unknown User
2019-07-28 16:58:29
"serph, post: 67014, member: 1398":

its working on my main tracker whats the annonce url your trying to scrape ?
can someone else try this script before i start debugging it all just to make sure it isnt an issue at shadows end

i've tried to add a specific tracker on $tracker, it shows all stats as 0 on localhost. Someone should test it as well.
Unknown User
2019-07-28 19:33:45
this is the entire code as i have it in torrent-details


//===| Scrape External Torrents
   if ($row["external"]=='yes')
   {
       print ("<td width='160' border='0' align='right' valign='top'><table><tr>");
       if ($scrape =='1')
       {
           $seeders = $leechers = $downloaded = NULL;
           print("<td class='table_col1' border'0' width='150' valign='middle'>
           <div style='margin-top:5px; border='0' margin-bottom:10px; font:bold 16px Times' align='center'><font color='#FF2000'>".T_("EXTERNAL_TORRENT")."</font></div>");

         //===| UDP Scraper

$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 ($openbittorrent_done){
continue;
}
if (preg_match("/thepiratebay.org/i", $tracker) || preg_match("/tracker.tfile/", $tracker)){
$tracker = "udp://tracker.openbittorrent.com:80/scrape";
$openbittorrent_done = 1;
}
if(preg_match('/udp:\/\//', $tracker)){
$udp=true;
try
{
$timeout = 5;
$udp= new udptscraper($timeout);
$stats=$udp->scrape($tracker,$row["info_hash"]);
//print_r($stats); exit();
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 = '".$leechers1."', seeders = '".$seeders1."', times_completed = '".$downloaded1."', 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'>".$seeders1."</font></div>");
               print ("<div style='margin-left:20px'>".T_("LEECHERS").": <font color='#FF2000'>".$leechers1."</font></div>");
               print ("<div style='margin-left:20px'>".T_("COMPLETED").": <font color='#0080FF'>".$downloaded1."</font></div>");
           }
           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 ("<div style='margin-top:10px; margin-bottom:10px' align='center'>
               <a href='torrents-details.php?id=".$id."'><input type='submit' name='submit' value=".T_("SUBMIT")."></a>
           </div>");
           print ("</td>");
       }
       else
       {
           print ("<td class='table_col1' width='150' border='0' 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 style='font:normal 12px Times' align='center'>".T_("UPDATE_STATS")."</div></div>
                   <form action='torrents-details.php?id=$id&amp;scrape=1' method='post'>
                       <div style='margin-top:5px; margin-bottom:10px' align='center'><input type='submit' name='submit' value=".T_("UPDATE")." /></div>
                   </form>
               </td>");
       }
       print ("</tr></table></td>");
   }
   //===| End Scrape External Torrents
Unknown User
2019-07-28 21:01:19
[USER=1398]@serph[/USER] i got it to work , but it counts all announces together and adds total seeds based on announces. 30 announces with 5 seeders = 30 * 5 = 1500+ seeds
Unknown User
2019-07-28 22:23:21
On the backup trackers that's what's its suposeed to do gets total seeds leech and completed adds them all together and gives total for each how did you get it to work what did you change.? And what is it you want it to do instead of what it's doing now.?
Unknown User
2019-07-29 05:17:03
To fix this ststs merging you should replace in update torrents seeders1 to $scrape['seeders'], etc and it will work as supposed. I added manually trackers into announce via sql on localhost for trsting purpose to see how it will react until i fix importing announces
Unknown User
2019-07-29 05:43:02
post your code [USER=20311]@shadows[/USER]  changing to what you said gives me 0 stats
Unknown User
2019-07-29 06:13:52
Removed some unnecessary parts from your code which weren't needed to improve speed.
Add rest of your html code below the '.....' part.

[color=rgb(250, 197, 28)]Important: [/color]
array_pop($tracker) will only scrape the last announce in additional trackers and show stats for it (It will also update all other additional trackers, but will take stats only from last one). So stats might look very low.


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>");
           }
.......
         
Unknown User
2019-07-29 13:38:29
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
Unknown User
2019-07-29 13:55:06
? Need more people to test this so it can be moved to completed
Unknown User
2019-07-30 22:10:13
"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

We can just include http scraper there from github :D

<?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;
   }
}
Unknown User
2019-07-31 05:30:52
could just figure out why the original isnt working


function escape_url($url) {
   $ret = '';
   for($i = 0; $i < strlen($url); $i+=2)
   $ret .= '%'.$url[$i].$url[$i + 1];
   return $ret;
}

/**
* Scrape torrent and return stats
*
* @param $scrape
*   string: Scrape URL
* @param $hash
*   string: SHA1 hash (info_hash) of torrent
* @return
*   array:
*     All -1 if failed
*     - seeds: integer - number of seeders
*     - leechers: integer - number of leechers
*     - downloaded: integer - number of complete downloads
*
*/
function torrent_scrape_url($scrape, $hash) {
   if (function_exists("curl_exec")) {
       $ch = curl_init();
       $timeout = 5;
       curl_setopt ($ch, CURLOPT_URL, $scrape.'?info_hash='.escape_url($hash));
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
       curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
       curl_setopt ($ch, CURLOPT_HEADER, false);
       $fp = curl_exec($ch);
       curl_close($ch);
   } else {
       ini_set('default_socket_timeout',10);
       $fp = @file_get_contents($scrape.'?info_hash='.escape_url($hash));
   }
   $ret = array();
   if ($fp) {
       $stats = BDecode($fp);
       $binhash = pack("H*", $hash);
       $binhash = addslashes($binhash);
       $seeds = $stats['files'][$binhash]['complete'];
       $peers = $stats['files'][$binhash]['incomplete'];
       $downloaded = $stats['files'][$binhash]['downloaded'];
       $ret['seeds'] = $seeds;
       $ret['peers'] = $peers;
       $ret['downloaded'] = $downloaded;
   }

   if ($ret['seeds'] === null) {
       $ret['seeds'] = -1;
       $ret['peers'] = -1;
       $ret['downloaded'] = -1;
   }

   return $ret;
}
Unknown User
2019-07-31 07:22:22
Wrong naming. We need to use seeders instead seeds. We use scrape[seeders] to enter values into db
Unknown User
2019-07-31 07:55:03
i dont have any http announces to test :(
Unknown User
2019-07-31 15:06:23
"serph, post: 67030, member: 1398":

i dont have any http announces to test :(

Download any rarbg torrent. They use http tracker as 1st tracker
2019-07-31 21:27:08
test any ubuntu torrent, like https://ubuntu.com/download/alternative-downloads
Are you guys gunna post a final code so it makes sense and is easy to use when you are done? Thanks for working on this everyone :)
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 1
  • Members: 0
  • Guests online: 1
  • Comments: 3
  • Messages: 1,728