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
BT v1/v2 parser Work
Controls ·  Search New posts · Mark unread

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

2022-02-06 09:00:34
Changelog - Feb 11/22:

- Shorter code
- Fixed hash detection using version array check (confirmed - qBittorrent v4.4.0)
- Fixed incorrect count caused by extra padding data
- Reduced long checks with shorter logic
- Correctly check version using 'meta version' tree item (specification)
- Checks correct version for file list iteration to handle all cases
- Replaced file_get_contents with low-level and binary-safe file reading


<?
function torr(string $filename = ''): mixed
{
   // Array storage
   $torrentInfo = array();
   $array       = array();
   // Torrent Version
   $version     = array();
   // Torrent filename
   $torrent     = explode(".", $filename);
   $fileend     = strtolower(end($torrent));
   if ($fileend == "torrent") {
       $fp    = fopen($filename, 'rb');
       $parse = '';
       while (!feof($fp)) {
           $parse .= fread($fp, 8192);
       }
       fclose($fp);
       // If Parse Lets Read It
       if ($parse === false) {
           echo "Error Getting Torrent file";
       } else {
           // Decode File Array
           $array = Bencode::decode($parse);
           // Push version to Array
           array_push($version, (array_key_exists('meta version', $array['info']) ? intval($array['info']['meta version']) : 1));
           // If Array Lets Read It
           if (empty($array)) {
               die('Unable to decode metadata.');
           } else {
               if (array_key_exists('info', $array) !== true) {
                   die('Error opening torrent');
               } else {
                   // Get Announce URL
                   $torrentInfo['announce']      = isset($array["announce"]) ? $array["announce"] : null;
                   // Get Announce List Array
                   $torrentInfo["announce-list"] = (isset($array["announce-list"])) ? $array["announce-list"] : null;
                   // Calculates date from UNIX Epoch - You want to return NULL on this if empty to pass parse validation
                   $torrentInfo["creation date"] = isset($array["creation date"]) ? date('r', $array["creation date"]) : null;
                   // Get torrents comment
                   $torrentInfo['comment']       = (isset($array['comment'])) ? $array['comment'] : null;
                   // Read info - files
                   $info                         = $array["info"];
                   // The name of the torrents is different to the file name
                   $torrentInfo['name']          = $info['name'];
                   // Read the torrent version stored in array previously
                   $torrentInfo['type']          = $version[0];
                   // Calculate Size/Count
                   $filecount                    = 0;
                   $torrentsize                  = 0;
                   // Calculates Hashes - SHA1/SHA256
                   $torrentInfo['hash']          = in_array(2, $version) ? hash('sha256', Bencode::encode($info)) : hash('sha1', Bencode::encode($info));
                   $path                         = array();
                   // File List
                   $struct                       = in_array(2, $version) ? $info['file tree'] : $info['files'];
                   if (array_key_exists('file tree', $info)) {
                       foreach ($struct as $key => $value) {
                           foreach ($value as $detail) {
                               $filecount = ++$filecount;
                               $torrentsize += $detail['length'];
                               array_merge($path, array(
                                   'length' => $detail['length']
                               ));
                           }
                           array_push($path, array(
                               'length' => $detail['length'],
                               'path' => array(
                                   sizeof($value) - 1 => $key
                               )
                           ));
                       }
                       $torrentInfo['files']       = $path;
                       $torrentInfo['length']      = $torrentsize;
                       $torrentInfo['ttfilecount'] = $filecount;
                   }
                   if (array_key_exists('file tree', $info) || array_key_exists('files', $info)) {
                       if (isset($info['files']) || $filecount > 1) {
                           // Multi File
                           if (isset($info['files']) && is_array($info['files'])) {
                               $torrentInfo['files'] = $info['files'];
                               foreach ($info['files'] as $file) {
                                   $filecount = ++$filecount;
                                   $torrentsize += $file['length'];
                               }
                               $torrentInfo['length']      = $torrentsize;
                               $torrentInfo['ttfilecount'] = !empty($path) ? count($path) : $filecount;
                           }
                       } else {
                           if ($filecount === 1) {
                               // Single File - Remove or Use
                           }
                       }
                   }
               }
           }
       }
   }
   return $torrentInfo;
}
Last edited by STorrents2020 on 2022-02-12 06:20:22
2022-02-06 10:20:55
this is what ive got returning so far https://torrenttrader.uk/atest with this,
although for hybrid it should do both and return array(v1hash, v2hash) and array merge both files structures thats where pain comes, ill post any progress mate  πŸ‘
2022-02-06 10:45:50
Sorry I didn't see this before the shoutbox posts. Sounds good! Disregard the posts, I see progress
2022-02-06 11:09:48
As far as I can tell, the code should be complete. Confirm with your own torrents. I've established plenty of checks in all different types of scenarios to handle any case, it passed every test.

I want to give a big thank you to @M-Jay for his work on this, and the opportunity for me plug to this in to my own site in a light-weight manner - without the need for heavy third-party libraries. Thanks!! It was fun.

Enjoy. πŸ˜‰
Last edited by STorrents2020 on 2022-02-07 02:13:21
2022-02-12 11:32:01
BEP_35 - This extracts the certificate info out of a signed .torrent file, and separates the certificate fields into their own keys to merge into $torrentInfo fast and efficiently - no slow Reggex!

This will pull any info out of the file signed by any certificate authority, for example:
Let's Encrypt, Verisign, ZeroSSL, Cloudflare Origin, etc etc.

This extracts all you need to use and display on torrent pages by getting into the secure RSA-2048 encrypted dictionary.
It was not easy, took me almost 3 hours. You wont find this code anywhere, because it quite simply does not exist.

Proudly coded for the ST Tracker πŸ˜‰ Enjoy~

I hope we can get past the requirements of the compiled binary and passthru() requirement, and somehow find a way to do this with OpenSSL natively in PHP. Anyway.. in the meantime, I share my work:


$torrentInfo['signed']  = array_key_exists('signatures', $array) ? 'Yes' : 'No';
if (array_key_exists('signatures', $array)) {
   foreach ($array['signatures'] as $value => $key) {
       $torrentInfo['authority'] = $value;
       foreach ($key as $certinfo) {
           $filter                     = array('' => '', '' => '', '' => '', '' => '', '' => '', ' ' => '', '' => '', 'U' => '', '6' => '', '/' => ' ', '0x06' => '', '' => '', '' => '', '1' => '', '8' => '', '0' => '', '' => '', '2' => '', '4' => '', '9' => '', 'Z' => '', '3' => '', 'b' => '');
           $alloc                      = strtr($certinfo, $filter);
           $torrentInfo['certificate'] = explode (' ',  trim(explode("\n", $alloc)[3]), 3)[2];
           $split = explode("\n", $alloc)[3];
           $sep                        = preg_split('/[\s,]+/', $split, 3);
           $torrentInfo['issuer']      = implode(', ', array($sep[0], $sep[1]));
           break;
       }
   }
}


Result:

Array
(
   [announce] => https://domain.com/announce?token=aTRYNWZUZVNwWnl2S2lEa3JaWVJNMGEyNkthWGNCUXRUOFhQZDlMUThacEMycVFZNEtEYmNTdXduYjdYWjBOcg==
   [announce-list] =>
   [creation date] => Wed, 09 Feb 2022 17:39:46 -0800
   [comment] => Yessir - Proudly UP'd
   [name] => Haven Park [NSZ]
   [type] => 1
   [hash] => 744ef0c8087409d6c6948b95cbe75276be86ffb4
   [private] => Yes
   [signed] => Yes
   [authority] => CloudFlare Origin Certificate
   [certificate] => CloudFlare Origin SSL ECC Certificate Authority
   [issuer] => CloudFlare, Inc.
   [files] => Array
       (
           [0] => Array
               (
                   [length] => 120592155
                   [path] => Array
                       (
                           [0] => Haven Park [0100E390155E4000][v0].nsz
                       )

               )

           [1] => Array
               (
                   [length] => 136364215
                   [path] => Array
                       (
                           [0] => Haven Park [0100E390155E4800][v720896].nsz
                       )

               )

       )

   [length] => 256956370
   [ttfilecount] => 2
)
Last edited by STorrents2020 on 2022-02-12 11:38:56
2022-02-12 12:56:20
great work, still seem to have issue with file tree, if you look at the subs folder in each array you see the v2 isnt been picked up,  https://torrenttrader.uk/atest
hybrid seems to be wrong size, my understanding is we only need the torrent file detail bits for db so for hybrid we dont need to run through both file tree & path.

Last edited by M-jay warn on 2022-02-12 13:01:49
2022-02-12 19:41:56
Yah its pretty confusing, in my case its reading LONGBLOB so I right click on row and "Save BLOB as file" => .torrent file to desktop and open with uTorrent, but its all wrong all the time. Its a challange for sure! - I have to remind myself to not rely on uTorrent lol

Hybrid - Are we just defaulting to V1 if client does not support? How do we know? I mean, we can create a table of user agents and version and track that will a field describing V1/V2 capabilities (qBittorrent 4.4.4 for example), even dumping the clients from peers table to a new table in cleanup class, but thats a dirty solution - we 'could' decide decoder based on that.  
2022-02-12 19:43:54
Track updates here:

https://bit.ly/3GMPh4v
2022-02-14 03:28:01
Okay uploading works perfectly. What I made the mistake with, was:

Bencode::encode($torrentInfo) - Wrong! It has no clue what to do, and does its best with the array it see's.

We use the class to read the key values to assist in field population in torrent table (name, hash, size, etc)

Now when actually saving the .torrent to file, we must do this:

TorrentTrader - put_file_contents('uploads/somename.torrent', file_get_contents($_FILES['torrent']['tmp_name']))
BLOB Field - get_file_contents($_FILES['torrent']['tmp_name'])

Replace somename.torrent with $_POST['name'] for example - the form torrent name field.

Now its working perfectly. All data shows up in my index and provides the exact results I expected. Lesson learned here lol
2022-02-14 05:46:49
seem to get errors on subfolders have you tried a few v2 torrents, i managed to get something to go through the new file tree and can get paths & length ($torrentinfo['files']) array working better - but still not getting the subfolder as it should

progress so far - this is where i check extension - if no dot exist i assume its a folder - i just skip at minute but that should be placed somewhere
i just need same array for both so close i can use $path = $file['path'][1] ?? $file['path'][0]; to alter v1 to match but again that removes the subfolder i hate multiarrays 😈

https://torrenttrader.uk/atest look at the subfolder/subtitles

    public function torr($filename = "")
   {
       // First Check File Is Torrent
       $torrent = explode(".", $filename);
       $fileend = strtolower(end($torrent));
       if ($fileend != "torrent") {
           die('this is not a torrent');
       }

       // Set Arrays
       $torrentInfo = array();
       $array = array();

       // Read The File
       $parse = file_get_contents("$filename");
       if (!isset($parse)) {
           die("Error Getting Torrent file");
       }

       // Decode File Array
       $array = Bencode::decode($parse);

       // If Array Lets Read It
       if ($array === false) {
           die("Unable to decode file.");
       }

       // Check Info Is There
       if (array_key_exists("info", $array) === false) {
           die("Error opening torrent.<br>");
       }

       // Read info
       $info = $array["info"];
       if (isset($info["file tree"]) && isset($info["files"])) {
           die('We do not allow hybrid, we except v1 while others catch up but use v2 when possible');
       }

       // Get Announce URL
       $torrentInfo['announce'] = $array["announce"];

       // Get Announce List Array
       if (isset($array["announce-list"])) {
           $torrentInfo["announce-list"] = $array["announce-list"];
       }

       // Calculates date from UNIX Epoch
       $torrentInfo["creation date"] = date('r', $array["creation date"]);

       // Get torrents comment
       if (isset($array['comment'])) {
           $torrentInfo['comment'] = $array['comment'];
       }

       // The name of the torrents is different to the file name
       $torrentInfo['name'] = $info['name'];

       // Calculate Size/Count
       $filecount = 0;
       $torrentsize = 0;

       // Get The Hash
       if (isset($info["file tree"])) {
           // Calculates SHA256 Hash
           $hash = hash('sha256', Bencode::encode($info));
           $torrentInfo['hash'] = substr($hash, 0, 40);
           // Return Marker To identify as v2
           $torrentInfo['type'] = '2';
       } else {
           // Calculates SHA1 Hash
           $torrentInfo['hash'] = hash('sha1', Bencode::encode($info));
           // Return Marker To identify as v1
           $torrentInfo['type'] = '1';
       }

       // V2 Get file list
       if (isset($info["file tree"]) && is_array($info["file tree"])) {
           // For Now Dont Allow V2
           //unlink("$filename");
           //die("We Dont Except V2 Torrents Just Yet.");

           $Iterator = new RecursiveIteratorIterator(
               new RecursiveArrayIterator($info["file tree"]),
               RecursiveIteratorIterator::SELF_FIRST
           );
           foreach ($Iterator as $key => $val) {
               if ($key != 'pieces root' && $key != 'length' && !empty($key)) {
                   $subfolder = substr($key, -4, 1);
                   if($subfolder === '.') {
                       $keys = $key;
                   }
                   $filecount = ++$filecount;
               }
               if ($val > 1 && is_int($val)) {
                   $vals = $val;
                   $torrentsize += $val;
               }
               if ($val > 1 && is_int($val)) {
                   $paths[] = [
                       'length' => $vals,
                       'path' => $keys,
                   ];
               }
           }

           $torrentInfo['files'] = $paths;
           $torrentInfo['length'] = $torrentsize;
           $torrentInfo['ttfilecount'] = $filecount;

       } elseif (isset($info["files"]) && is_array($info["files"])) {

           // V1 Get file list
           foreach ($info["files"] as $file) {
               $filecount = ++$filecount;
               $torrentsize += $file['length'];
               $path = $file['path'];
               //$path = $file['path'][1] ?? $file['path'][0]; // subfolder?
               $length = $file['length'];
               $paths[] = [
                   'length' => $length,
                   'path' => $path
               ];
           }

           $torrentInfo['files'] = $paths;
           $torrentInfo['length'] = $torrentsize;
           $torrentInfo['ttfilecount'] = $filecount;
       } else {
           // Single File Torrent
           $torrentInfo['name'] = $info['name'];
           $torrentInfo['length'] = $info['length'];
           $torrentInfo['ttfilecount'] = 1;
       }

       return $torrentInfo;
       //var_dump($torrentInfo);
   }
 
2022-02-14 10:32:21
incorrect - post. delete this.
Last edited by STorrents2020 on 2022-02-14 10:47:38
2022-02-14 10:34:00
Try this. I think this is all we need because we are just reading keys for the database. We are actually just copying the file to /uploads and ignoring almost all of this (we just need the sizes, name, announce and info_hash).

Most of this is just getting it to pull up files on the details page, which I will do tomorrow in my format and push the code over here.

This is I have so far.

BEPs Supported: 27, 35, 48, 52


function torr( ?string $filename = '') : mixed
{
   // Array storage
   $torrentInfo = array();
   $array = array();
   // Torrent Version
   $version = array();
   // Torrent filename
   $torrent = explode(".", $filename);
   $fileend = strtolower(end($torrent));
   if ($fileend == "torrent")
   {
       $parse = file_get_contents("$filename");
       // If Parse Lets Read It
       if ($parse === false)
       {
           echo "Error Getting Torrent file";
       }
       else
       {
           // Decode File Array
           $array = Bencode::decode($parse, bigInt:
               BigInt::INTERNAL);
               // Push version to Array
               array_push($version, (array_key_exists('meta version', $array['info']) ? intval($array['info']['meta version']) : 1));
               // If Array Lets Read It
               if (empty($array))
               {
                   die('Unable to decode metadata.');
               }
               else
               {
                   if (array_key_exists('info', $array) !== true)
                   {
                       die('Error opening torrent');
                   }
                   else
                   {
                       $path = array();
                       $data['announce'] = isset($array["announce"]) ? $array["announce"] : null;
                       // Get Announce URL
                       $torrentInfo['announce'] = isset($array["announce"]) ? $array["announce"] : null;
                       // Get Announce List Array
                       $torrentInfo["announce-list"] = (isset($array["announce-list"])) ? $array["announce-list"] : null;
                       // Calculates date from UNIX Epoch - You want to return NULL on this if empty to pass parse validation
                       $torrentInfo["creation date"] = isset($array["creation date"]) ? date('r', $array["creation date"]) : null;
                       // Get torrents comment
                       $torrentInfo['comment'] = (isset($array['comment'])) ? $array['comment'] : null;
                       // Read info - files
                       $info = $array["info"];
                       // The name of the torrents is different to the file name
                       $torrentInfo['name'] = $info['name'];
                       // Read the torrent version stored in array previously
                       $torrentInfo['version'] = $version[0];
                       // Calculate Size/Count
                       $filecount = 0;
                       $torrentsize = 0;
                       // Calculates Hashes - SHA1/SHA256
                       $torrentInfo['hash'] = in_array(2, $version) ? hash('sha256', Bencode::encode($info)) : hash('sha1', Bencode::encode($info));
                       $torrentInfo['info_hash v1'] = hash('sha1', Bencode::encode($info));
                       $torrentInfo['info_hash v2'] = hash('sha256', Bencode::encode($info));

                       // Scrape
                       $tracker = !empty($array['announce']) ? array(
                           $array['announce']
                       ) : null;
                       $hash = array(
                           hash('sha1', Bencode::encode($info))
                       );
                       foreach ((new Scrape())->scrape($hash, $tracker) as $value)
                       {
                           $torrentInfo['seeders'] = intval($value['seeders']);
                           $torrentInfo['leechers'] = intval($value['leechers']);
                           $torrentInfo['completed'] = intval($value['completed']);
                       }
                       if ((new Scrape())->has_errors())
                       {
                           $torrentInfo['scrape error'] = (new Scrape())->get_errors();
                       }

                       // File List
                       $struct = in_array(2, $version) ? $info['file tree'] : $info['files'];
                       if (array_key_exists('file tree', $info))
                       {
                           foreach ($struct as $key => $value)
                           {
                               foreach ($value as $detail)
                               {
                                   $filecount = ++$filecount;
                                   $torrentsize += $detail['length'];
                                   array_merge($path, array(
                                       'length' => $detail['length']
                                   ));
                               }
                               array_push($path, array(
                                   'length' => $detail['length'],
                                   'path' => array(
                                       sizeof($value) - 1 => $key
                                   )
                               ));
                           }
                           $torrentInfo['files'] = $path;
                           $torrentInfo['length'] = $torrentsize;
                           $torrentInfo['ttfilecount'] = $filecount;
                       }

                       $torrentInfo['private'] = array_key_exists('private', $info) ? 'Yes' : 'No';
                       $torrentInfo['signed'] = array_key_exists('signatures', $array) ? 'Yes' : 'No';
                       if (array_key_exists('signatures', $array))
                       {
                           foreach ($array['signatures'] as $value => $key)
                           {
                               $torrentInfo['authority'] = $value;
                               foreach ($key as $certinfo)
                               {
                                   $filter = array(
                                       '' => '',
                                       '' => '',
                                       '' => '',
                                       '' => '',
                                       '' => '',
                                       ' ' => '',
                                       '' => '',
                                       'U' => '',
                                       '6' => '',
                                       '/' => ' ',
                                       '0x06' => '',
                                       '' => '',
                                       '' => '',
                                       '1' => '',
                                       '8' => '',
                                       '0' => '',
                                       '' => '',
                                       '2' => '',
                                       '4' => '',
                                       '9' => '',
                                       'Z' => '',
                                       '3' => '',
                                       'b' => ''
                                   );
                                   $alloc = strtr($certinfo, $filter);
                                   $torrentInfo['certificate'] = explode(' ', trim(explode("\n", $alloc) [3]) , 3) [2];
                                   $split = explode("\n", $alloc) [3];
                                   $sep = preg_split('/[\s,]+/', $split, 3);
                                   $torrentInfo['issuer'] = implode(', ', array(
                                       $sep[0],
                                       $sep[1]
                                   ));
                                   break;
                               }
                           }
                       }

                       if (array_key_exists('file tree', $info) || array_key_exists('files', $info))
                       {
                           if (isset($info['files']) || $filecount > 1)
                           {
                               // Multi File
                               if (isset($info['files']) && is_array($info['files']))
                               {
                                   $torrentInfo['files'] = $info['files'];
                                   foreach ($info['files'] as $file)
                                   {
                                       $filecount = ++$filecount;
                                       $torrentsize += $file['length'];
                                   }
                                   $torrentInfo['length'] = $torrentsize;
                                   $torrentInfo['ttfilecount'] = !empty($path) ? count($path) : $filecount;
                               }
                           }
                           else
                           {
                               if ($filecount === 1)
                               {
                                   // Single File - Remove or Use
                                   
                               }
                           }
                       }
                   }
               }
           }
       }
       return print_r($torrentInfo);
   }


require 'Scraper.php';


It works fine for me, only issue I have now is getting download.php to accept anything aside from signed and thats a wrap. I'll know more once I construct the file/icon layout for the file tree on my torrent details page tomorrow. Busy week ahead, hope I have evening time to work on it.
Scrape.zip
File missing
Last edited by STorrents2020 on 2022-02-14 10:46:49
2022-02-14 15:59:58
The SPL iterator classes are great! Nice choice. I’ll try your code there, I like how it looks and I used it for the entire blob migration (the migrator forum post a while back), it works really nicely but definitely avoid calling multiple object references to the same object, it’s a performance impact. But I do t think it matters for parsing data in our case.

Just adding a big block of if/else’s to check my form fields slowed down my code considerably, not sure how to improve that, it must be at least a 5ms increase on page load - no big deal but is preventable.
2022-02-14 16:51:58
my final code blocking hybrid - they seem pointless but we need v1, finally got the class displaying all return parse info array the same - nice work adding scraper

needs some fine tuning but running perfectly - the only other thing i edited except the parse function was this line on torrents-upload
this was because i switched the values to get subfolders so just changed order before db insert
                        if (($i + 1) == $count) {
                           $fname = $file["path"][$i] . $dir ;
                       } else {
                           $dir .= "/" . $file["path"][$i];
                       }


parse function with correct results https://torrenttrader.uk/atest
<?php

class Parse
{

   public function torr($filename = "")
   {
       // First Check File Is Torrent
       $torrent = explode(".", $filename);
       $fileend = strtolower(end($torrent));
       if ($fileend != "torrent") {
           die('this is not a torrent');
       }

       // Set Arrays
       $torrentInfo = array();
       $array = array();

       // Read The File
       $parse = file_get_contents("$filename");
       if (!isset($parse)) {
           die("Error Getting Torrent file");
       }

       // Decode File Array
       $array = Bencode::decode($parse);

       // If Array Lets Read It
       if ($array === false) {
           die("Unable to decode file.");
       }

       // Check Info Is There
       if (array_key_exists("info", $array) === false) {
           die("Error opening torrent.<br>");
       }

       // Read info
       $info = $array["info"];
       if (isset($info["file tree"]) && isset($info["files"])) {
           die('We do not allow hybrid, we except v1 while others catch up but use v2 when possible');
       }

       // Get Announce URL
       $torrentInfo['announce'] = $array["announce"];

       // Get Announce List Array
       if (isset($array["announce-list"])) {
           $torrentInfo["announce-list"] = $array["announce-list"];
       }

       // Calculates date from UNIX Epoch
       $torrentInfo["creation date"] = date('r', $array["creation date"]);

       // Get torrents comment
       if (isset($array['comment'])) {
           $torrentInfo['comment'] = $array['comment'];
       }

       // The name of the torrents is different to the file name
       $torrentInfo['name'] = $info['name'];

       // Calculate Size/Count
       $filecount = 0;
       $torrentsize = 0;

       // Get The Hash
       if (isset($info["file tree"])) {
           // Calculates SHA256 Hash
           $hash = hash('sha256', Bencode::encode($info));
           $torrentInfo['hash'] = substr($hash, 0, 40);
           // Return Marker To identify as v2
           $torrentInfo['type'] = '2';
       } else {
           // Calculates SHA1 Hash
           $torrentInfo['hash'] = hash('sha1', Bencode::encode($info));
           // Return Marker To identify as v1
           $torrentInfo['type'] = '1';
       }

       // V2 Get file list
       if (isset($info["file tree"]) && is_array($info["file tree"])) {
           // For Now Dont Allow V2
           //unlink("$filename");
           //die("We Dont Except V2 Torrents Just Yet.");

           $Iterator = new RecursiveIteratorIterator(
               new RecursiveArrayIterator($info["file tree"]),
               RecursiveIteratorIterator::SELF_FIRST
           );
           foreach ($Iterator as $key => $val) {
               if ($key != 'pieces root' && $key != 'length' && !empty($key)) {
                   $subfolder = substr($key, -4, 1);
                   if($subfolder === '.') {
                       $keys[0] = $key;
                       $filecount = ++$filecount;
                   } else {
                       $keys[1] = $key;
                   }
               }
               if ($val > 1 && is_int($val)) {
                   $vals = $val;
                   $torrentsize += $val;
               }
               if ($val > 1 && is_int($val)) {
                   $paths[] = [
                       'length' => $vals,
                       'path' => $keys,
                   ];
               }
           }
   
           $torrentInfo['files'] = $paths;
           $torrentInfo['length'] = $torrentsize;
           $torrentInfo['ttfilecount'] = $filecount;

       } elseif (isset($info["files"]) && is_array($info["files"])) {

           // V1 Get file list
           foreach ($info["files"] as $file) {
               $filecount = ++$filecount;
               $torrentsize += $file['length'];

               $path[0] = $file['path'][1] ?? $file['path'][0];
               if ($file['path'][1] ===  $path[0]) {
                   $path[1] = $file['path'][0];
               }
               
               $length = $file['length'];
               $paths[] = [
                   'length' => $length,
                   'path' => $path
               ];
           }

           $torrentInfo['files'] = $paths;
           $torrentInfo['length'] = $torrentsize;
           $torrentInfo['ttfilecount'] = $filecount;
       } else {
           // Single File Torrent
           $torrentInfo['name'] = $info['name'];
           $torrentInfo['length'] = $info['length'];
           $torrentInfo['ttfilecount'] = 1;
       }

       return $torrentInfo;
       //var_dump($torrentInfo);
   }
}


although im not sure if clients can do v2 except qbit at least we have the ground work  πŸ˜‚ its a bit shocking how little there is to interacting with torrent - get data from file & a announce array for the client - thanks for helping out dont get many members helping out playing with this kind of stuff  πŸ‘
Last edited by M-jay warn on 2022-02-14 17:05:05
2022-02-15 05:51:40
I love this stuff haha I'll do it for hours honestly - awesome looking good! I got the upload page finished and its all collected. scraping, file count, hash, etc

I ignore ignore v2 hash for hybrid, because that I think is just up to the client... it has a file tree so we know already lol

That's what they added that 'meta version' field, I think to help clients pick up the .torrent file type more easily as long as parsers catch up reading it - really up to the bittorrent codebase I guess - or libtorrent/rtorrent

Stay lit, stay high!  πŸ”₯
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