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
New Base Scraper [In Progress]
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / M-BiTsy / M-BiTsy Support

2020-10-17 14:56:22
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

<!--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&amp;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!");
   }
}
classes.zip
Download
2020-10-17 15:10:12
if this tests well i wll add scrape controller (scraper & mega-scraper)
make sure in config you allow external and here is a upd torrent
updtorrent.zip
Download
2020-10-18 13:15:17
Before update:

[ATTACH type="full"]5941[/ATTACH]

after Update:

[ATTACH type="full"]5942[/ATTACH]

[ATTACH type="full"]5943[/ATTACH]
1603026825334.png
1603026825334.png
1603026853004.png
1603026853004.png
1603026900875.png
1603026900875.png



www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
2020-10-19 13:43:52
Seem to have broken something lol got so many things on at once
Luckily I made a couple of backups so I'll look through them and update post before weekend  (y)
2020-10-19 15:34:26
"m-jay, post: 69473, member: 20288":

Seem to have broken something lol got so many things on at once
Luckily I made a couple of backups so I'll look through them and update post before weekend  (y)

Thanks [USER=20288]@m-jay[/USER] I know you have a many things to do right now so no rush, take it easy mate


www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
2020-10-20 02:46:02
Dont rely too heavily on that old code, it wont keep up with new interpreter versions. Also, it deals with arrays poorly. Just a note.
2020-10-25 10:30:06
"STorrents2020, post: 69478, member: 20382":

Dont rely too heavily on that old code, it wont keep up with new interpreter versions. Also, it deals with arrays poorly. Just a note.


Hi M8, do you have some idea how to resolve that "thing" so it works properly on this version,
thanks a lot

Regards to all of you


www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
2020-10-25 17:34:28
"Botanicar, post: 69483, member: 19833":

Hi M8, do you have some idea how to resolve that "thing" so it works properly on this version,
thanks a lot

Regards to all of you


a universal class that converts the connection requests => any other dB. I’ll get at this in about a week as I am moving in real life lol
2020-11-01 06:13:05
[USER=19833]@Botanicar[/USER] i think its working again, try this

in classes folder create these two files (names are important)

Tscraper.php

<?php
   class ScraperException extends Exception
   {
       private $connectionerror;
     
       public function __construct($message,$code=0,$connectionerror=false)
       {
           $this->connectionerror = $connectionerror;
           parent::__construct($message, $code);
       }
     
       public function isConnectionError()
       {
           return($this->connectionerror);
       }
   }
 
   abstract class Tscraper
   {
       protected $timeout;
     
       public function __construct($timeout=2)
       {
           $this->timeout = $timeout;
       }
   }
?>


Udptscraper.php

<?php
class Udptscraper extends Tscraper
{
   public function scrape($url, $infohash)
   {
       if (!is_array($infohash)) {$infohash = array($infohash);}
       foreach ($infohash as $hash) {
           if (!preg_match('#^[a-f0-9]{40}$#i', $hash)) {throw new ScraperException('Invalid infohash: ' . $hash . '.');}
       }
       if (count($infohash) > 74) {throw new ScraperException('Too many infohashes provided.');}
       if (!preg_match('%udp://([^:/]*)(?::([0-9]*))?(?:/)?%si', $url, $m)) {throw new ScraperException('Invalid tracker url.');}
       $tracker = 'udp://' . $m[1];
       $port = isset($m[2]) ? $m[2] : 80;
       $transaction_id = mt_rand(0, 65535);
       $fp = fsockopen($tracker, $port, $errno, $errstr);
       if (!$fp) {throw new ScraperException('Could not open UDP connection: ' . $errno . ' - ' . $errstr, 0, true);}
       stream_set_timeout($fp, $this->timeout);
       $current_connid = "\x00\x00\x04\x17\x27\x10\x19\x80";
       //Connection request
       $packet = $current_connid . pack("N", 0) . pack("N", $transaction_id);
       fwrite($fp, $packet);
       //Connection response
       $ret = fread($fp, 16);
       if (strlen($ret) < 1) {throw new ScraperException('No connection response.', 0, true);}
       if (strlen($ret) < 16) {throw new ScraperException('Too short connection response.');}
       $retd = unpack("Naction/Ntransid", $ret);
       if ($retd['action'] != 0 || $retd['transid'] != $transaction_id) {
           throw new ScraperException('Invalid connection response.');
       }
       $current_connid = substr($ret, 8, 8);
       //Scrape request
       $hashes = '';
       foreach ($infohash as $hash) {$hashes .= pack('H*', $hash);}
       $packet = $current_connid . pack("N", 2) . pack("N", $transaction_id) . $hashes;
       fwrite($fp, $packet);
       //Scrape response
       $readlength = 8 + (12 * count($infohash));
       $ret = fread($fp, $readlength);
       if (strlen($ret) < 1) {throw new ScraperException('No scrape response.', 0, true);}
       if (strlen($ret) < 8) {throw new ScraperException('Too short scrape response.');}
       $retd = unpack("Naction/Ntransid", $ret);
       // Todo check for error string if response = 3
       if ($retd['action'] != 2 || $retd['transid'] != $transaction_id) {
           throw new ScraperException('Invalid scrape response.');
       }
       if (strlen($ret) < $readlength) {throw new ScraperException('Too short scrape response.');}
       $torrents = array();
       $index = 8;
       foreach ($infohash as $hash) {
           $retd = unpack("Nseeders/Ncompleted/Nleechers", substr($ret, $index, 12));
           $retd['infohash'] = $hash;
           $torrents[$hash] = $retd;
           $index = $index + 12;
       }
       return ($torrents);
   }
}


in views/torrent/read.php find
<!--buttonsstart-->
<td align="left"> <?php


replace everything below with
// 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>");

       //===| UDP Scraper
       $resu = $pdo->run("SELECT id, info_hash FROM torrents WHERE external = 'yes' AND id = $id");
       while ($rowu = $resu->fetch(PDO::FETCH_ASSOC))
       {
           // if broke try play with path - site_config url
           $TorrentInfo = ParseTorrent("uploads/$rowu[id].torrent");
           $ann = $TorrentInfo[0];
//var_dump($ann);
           $annlist = array();

           if ($TorrentInfo[6])
           {
               foreach ($TorrentInfo[6] as $ann)
               {
                   $annlist[] = $ann[0];
               }
           }
           else
               $annlist = array($ann);
//var_dump($annlist);

           $seeders = $leechers = $downloaded = null;
           foreach ($annlist as $ann)
           {
               $tracker = explode("/", $ann);
               $path = array_pop($tracker);
               $path = str_replace("announce", "scrape", $path);
               $tracker = implode("/", $tracker)."/".$path;
//var_dump($tracker);
               if(preg_match('/udp:\/\//', $tracker))
               {
                   $udp=true;
                   try
                   {
                       $timeout = 5;
                       $udp= new Udptscraper($timeout);
                       $stats=$udp->scrape($tracker, $rowu["info_hash"]);
                       //var_dump($udp->scrape($tracker, $rowu["info_hash"]));
                       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'];

                   $pdo->run("UPDATE `announce` SET `online` = 'yes', `seeders` = '".$stats['seeds']."', `leechers` = '".$stats['peers']."', `times_completed` = '".$stats['downloaded']."' WHERE `url` = ".sqlesc($ann)." AND `torrent` = $rowu[id]");
               }
               else
               {
                   $pdo->run("UPDATE `announce` SET `online` = 'no' WHERE `url` = ".sqlesc($ann)." AND `torrent` = $rowu[id]");
               }
           }

           if ($seeders !== null)
           {
               $pdo->run("UPDATE torrents SET leechers = '".$leechers."', seeders = '".$seeders."', times_completed = '".$downloaded."', last_action = '".get_date_time()."', visible = 'yes' WHERE id = '".$rowu['id']."'");
           }
           else
           {
               $pdo->run("UPDATE torrents SET last_action = '".get_date_time()."' WHERE id='".$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&amp;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
///END SCRAPE
   }?>
           </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!");
   }
}
2020-11-01 19:37:14
Thanks mate for all job you make and help oss.
This "hack" seams not work on my page, it sabs appearance on the page after I press the button "UPDATE STATS"

[ATTACH type="full"]5947[/ATTACH]

After klick on button comming that

[ATTACH type="full"]5948[/ATTACH]

no footer and no blocks on the right side, even not updated statistic on page

files is in the folder classess

[ATTACH type="full"]5949[/ATTACH]
1604259259297.png
1604259259297.png
1604259304134.png
1604259304134.png
1604259393215.png
1604259393215.png



www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
2020-11-03 16:25:42
oops the bottom file should be named Udptscraper.php (missing r) - see if that works
on xampp its perfect -  but on live server causing me bit of a headache :unsure:
Untitled.png
Untitled.png
2020-11-04 15:13:57
"m-jay, post: 69502, member: 20288":

oops the bottom file should be named Udptscraper.php (missing r) - see if that works
on xampp its perfect -  but on live server causing me bit of a headache :unsure:

[USER=20288]@m-jay[/USER] it is same thing, not working
if you need something from my server just hit me a PM, I send you all data you need


www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
2020-11-04 17:25:54
This is the error causing the issue  ? it's fine on xampp so I'll check the phpinfo
Quote:

Notice: fwrite(): send of 16 bytes failed with errno=1 Operation not permitted in /home/torrentt/public_html/classes/Udptscraper.php on line 21


This is the line
$current_connid = "\x00\x00\x04\x17\x27\x10\x19\x80";
2020-11-10 17:59:19
[USER=20288]@m-jay[/USER] my phpinfo is here:

[URL unfurl="true"]http://probne-stvari.tk/phpinfo.php[/url]

so I hope you find solution to resolve that problem


www.exyusubs.com
TorrentTrader V3.8.3 (SE)
OS: AlmaLinux 9.9 (BC)
Apache version: 2.4.71
PHP version: 8.5.13 (PHP-FPM)
MySQL version: 10.11.18-MariaDB
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: 9
  • Members: 0
  • Guests online: 9
  • Comments: 3
  • Messages: 1,728