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-15 19:01:44
Checking if v1/v2/hybrid and provide correct hash


// Calculates Hashes - SHA1/SHA256
$torrentInfo['info_hash'] = in_array(2, $version) ? hash('sha256', Bencode::encode($info)) : hash('sha1', Bencode::encode($info));
$torrentInfo['version']   = $version[0];
if (isset($info['file tree']) && isset($info['pieces'])) {
   $torrentInfo['info_hash v1'] = hash('sha1', Bencode::encode($info));
   $torrentInfo['info_hash v2'] = hash('sha256', Bencode::encode($info));
   $torrentInfo['version']      = 'Hybrid';
   unset($torrentInfo['info_hash']);
}
2022-02-15 21:08:15
I think I got the array now. It matches libtorrents design perfectly, and smaller code than before. I think I'm happy with this now. I dont see a lot else to do for it other than adding to a class maybe


<?
function torr( ? string $filename = '') : mixed
{
   $torrentInfo = array();
   $array = array();
   $version = array();

   $torrent = explode(".", $filename);
   $fileend = strtolower(end($torrent));
   if ($fileend == "torrent")
   {
       $parse = file_get_contents("$filename");
       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();
                       $info = $array["info"];
                       $torrentInfo['name'] = $info['name'];
                       $torrentInfo['announce'] = isset($array["announce"]) ? $array["announce"] : null;
                       $torrentInfo["announce-list"] = (isset($array["announce-list"])) ? $array["announce-list"] : null;
                       $torrentInfo["creation date"] = isset($array["creation date"]) ? date('r', $array["creation date"]) : null;
                       $torrentInfo['info_hash'] = in_array(2, $version) ? hash('sha256', Bencode::encode($info)) : hash('sha1', Bencode::encode($info));
                       $torrentInfo['version'] = $version[0];

                       if (isset($info['file tree']) && isset($info['pieces']))
                       {
                           $torrentInfo['info_hash v1'] = hash('sha1', Bencode::encode($info));
                           $torrentInfo['info_hash v2'] = hash('sha256', Bencode::encode($info));
                           $torrentInfo['version'] = 'Hybrid';
                           unset($torrentInfo['info_hash']);
                           $torrentInfo['info_hash'] = $torrentInfo['info_hash v1'];
                       }

                       $tracker = !empty($array['announce']) ? array(
                           $array['announce']
                       ) : null;
                       foreach ((new Scrape())->scrape($torrentInfo['info_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();
                       }

                       $torrentInfo['files'] = $path;
                       if (in_array(2, $version))
                       {
                           unset($torrentInfo['files']);
                           array_push($path, $info);
                           $torrentInfo['file tree'] = $info['file tree'];
                       }

                       $filecount = 0;
                       $torrentsize = 0;
                       $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))
                       {
                           // Calc file counts
                           if (isset($info['files']) || $filecount > 1)
                           {
                               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;
                               }
                           }
                       }
                   }
               }
           }
       }
       return print_r($torrentInfo);
   }


The array produced from code above:

bittorrent-v1-test.torrent
Array
(
   [name] => Qubes-R4.1.0-x86_64
   [announce] => http://linuxtracker.org:2710/00000000000000000000000000000000/announce
   [announce-list] => Array
       (
           [0] => Array
               (
                   [0] => udp://tracker.openbittorrent.com:80
               )

           [1] => Array
               (
                   [0] => udp://tracker.coppersurfer.tk:6969
               )

           [2] => Array
               (
                   [0] => udp://tracker.torrent.eu.org:451
               )

           [3] => Array
               (
                   [0] => http://linuxtracker.org:2710/00000000000000000000000000000000/announce
               )

       )

   [creation date] =>
   [info_hash] => ec0397eceff415d9fba61399a1cd4efbd7406922
   [version] => 1
   [seeders] => 14
   [leechers] => 0
   [completed] => 33
   [files] => Array
       (
           [0] => Array
               (
                   [length] => 5954863104
                   [path] => Array
                       (
                           [0] => Qubes-R4.1.0-x86_64.iso
                       )

               )

           [1] => Array
               (
                   [length] => 1251
                   [path] => Array
                       (
                           [0] => Qubes-R4.1.0-x86_64.iso.DIGESTS
                       )

               )

           [2] => Array
               (
                   [length] => 833
                   [path] => Array
                       (
                           [0] => Qubes-R4.1.0-x86_64.iso.asc
                       )

               )

       )

   [length] => 5954865188
   [ttfilecount] => 3
   [private] => No
   [signed] => No
)
bittorrent-v2-test.torrent

Array
(
   [name] => bittorrent-v2-test
   [announce] =>
   [announce-list] =>
   [creation date] => Thu, 21 May 2020 14:40:57 -0700
   [info_hash] => caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e
   [version] => 2
   [file tree] => Array
       (
           [13.Popsy Team - ViP 2.vob.mp4] => Array
               (
                   [] => Array
                       (
                           [length] => 27551708
                           [pieces root] => ��?���Ý�V�|s�{��!F4��$��
                       )

               )

           [Chameleon by ASD (female voice).mov] => Array
               (
                   [] => Array
                       (
                           [length] => 91862892
                           [pieces root] => ��H�NA����H"뢂�@`e9��c=��N/
Array
               (
                   [] => Array
                       (
                           [length] => 6535405
                           [pieces root] => �1��%�3gh�x&ȩ��}��fD(��
                       )

               )

           [Struct by Outracks (FullHD 1080p HQ demoscene).mov] => Array
               (
                   [] => Array
                       (
                           [length] => 141132865
                           [pieces root] => M��!ķ5��x�9�����>�˯���kP%FE;
                       )

               )

           [asd-rupture.mp4] => Array
               (
                   [] => Array
                       (
                           [length] => 263671468
                           [pieces root] => �=�9�
��P�K�Ն.=z���5�״f�,
                       )

               )

           [cncd_fairlight-ceasefire_(all_falls_down)-1080p.mp4] => Array
               (
                   [] => Array
                       (
                           [length] => 342230630
                           [pieces root] => i}�S�a��~]�]�*~���l��ꪃ��D���
                       )

               )

           [crionics & silents - hardwired (1991, hpad, divx5).avi] => Array
               (
                   [] => Array
                       (
                           [length] => 135000064
                           [pieces root] => -�x�Y�diVK��9Ʉ������ ����~
                       )

               )

           [elevated_4000.avi] => Array
               (
                   [] => Array
                       (
                           [length] => 113274880
                           [pieces root] => ]� ��Xv&o^]ͫ(��k��K�?:&i`�ъ�\�
                       )

               )

           [luma - mercury _ 64k _ Final.mp4] => Array
               (
                   [] => Array
                       (
                           [length] => 183814243
                           [pieces root] => b�i�4ܝ�L� >c�(f�N�Oݻww��=�
                       )

               )

           [readme.txt] => Array
               (
                   [] => Array
                       (
                           [length] => 61
                           [pieces root] => ; Array
               (
                   [] => Array
                       (
                           [length] => 229148672
                           [pieces root] => �?�_θ��U�/!� 쬕qu�TJ��(e�Dz�
                       )

               )

       )

   [length] => 0
   [ttfilecount] => 0
   [private] => No
   [signed] => No
)

bittorrent-v2-hybrid-test.torrent

Array
(
   [name] => bittorrent-v1-v2-hybrid-test
   [announce] =>
   [announce-list] =>
   [creation date] => Wed, 03 Jun 2020 01:45:06 -0700
   [version] => Hybrid
   [info_hash v1] => 631a31dd0a46257d5078c0dee4e66e26f73e42ac
   [info_hash v2] => d8dd32ac93357c368556af3ac1d95c9d76bd0dff6fa9833ecdac3d53134efabb
   [info_hash] => 631a31dd0a46257d5078c0dee4e66e26f73e42ac
   [file tree] => Array
       (
           [Darkroom (Stellar, 1994, Amiga ECS) HQ.mp4] => Array
               (
                   [] => Array
                       (
                           [length] => 6535405
                           [pieces root] => �1��%�3gh�x&ȩ��}��fD(��
                       )

               )

           [Spaceballs-StateOfTheArt.avi] => Array
               (
                   [] => Array
                       (
                           [attr] => x
                           [length] => 20506624
                           [pieces root] => $���&=U݄�,�6o`����
֗��.�Q�
                       )

               )

           [cncd_fairlight-ceasefire_(all_falls_down)-1080p.mp4] => Array
               (
                   [] => Array
                       (
                           [length] => 342230630
                           [pieces root] => i}�S�a��~]�]�*~���l��ꪃ��D���
                       )

               )

           [eld-dust.mkv] => Array
               (
                   [] => Array
                       (
                           [length] => 61638604
                           [pieces root] => ǩj� �2��a��X��:�����@��
                       )

               )

           [fairlight_cncd-agenda_circling_forth-1080p30lq.mp4] => Array
               (
                   [] => Array
                       (
                           [length] => 277889766
                           [pieces root] => � k�6�853���
|����'�g���8�r
                       )

               )

           [meet the deadline - Still _ Evoke 2014.mp4] => Array
               (
                   [] => Array
                       (
                           [length] => 44577773
                           [pieces root] => ϩOGyj�θ�n�HCPC���K"�7�-U��
                       )

               )

           [readme.txt] => Array
               (
                   [] => Array
                       (
                           [attr] => x
                           [length] => 61
                           [pieces root] => ; Array
               (
                   [] => Array
                       (
                           [attr] => x
                           [length] => 26296320
                           [pieces root] => �D�<�����"�F��P��wO����÷���Q
                       )

               )

           [tbl-tint.mpg] => Array
               (
                   [] => Array
                       (
                           [length] => 115869700
                           [pieces root] => w�<�(���B=�����Z�/��Z)�=]ë��B

                       )

               )

       )

   [length] => 898631684
   [ttfilecount] => 1
   [private] => No
   [signed] => No
   [files] => Array
       (
           [0] => Array
               (
                   [length] => 6535405
                   [path] => Array
                       (
                           [0] => Darkroom (Stellar, 1994, Amiga ECS) HQ.mp4
                       )

               )

           [1] => Array
               (
                   [attr] => p
                   [length] => 280339
                   [path] => Array
                       (
                           [0] => .pad
                           [1] => 280339
                       )

               )

           [2] => Array
               (
                   [attr] => x
                   [length] => 20506624
                   [path] => Array
                       (
                           [0] => Spaceballs-StateOfTheArt.avi
                       )

               )

           [3] => Array
               (
                   [attr] => p
                   [length] => 464896
                   [path] => Array
                       (
                           [0] => .pad
                           [1] => 464896
                       )

               )

           [4] => Array
               (
                   [length] => 342230630
                   [path] => Array
                       (
                           [0] => cncd_fairlight-ceasefire_(all_falls_down)-1080p.mp4
                       )

               )

           [5] => Array
               (
                   [attr] => p
                   [length] => 129434
                   [path] => Array
                       (
                           [0] => .pad
                           [1] => 129434
                       )

               )

           [6] => Array
               (
                   [length] => 61638604
                   [path] => Array
                       (
                           [0] => eld-dust.mkv
                       )

               )

           [7] => Array
               (
                   [attr] => p
                   [length] => 227380
                   [path] => Array
                       (
                           [0] => .pad
                           [1] => 227380
                       )

               )

           [8] => Array
               (
                   [length] => 277889766
                   [path] => Array
                       (
                           [0] => fairlight_cncd-agenda_circling_forth-1080p30lq.mp4
                       )

               )

           [9] => Array
               (
                   [attr] => p
                   [length] => 507162
                   [path] => Array
                       (
                           [0] => .pad
                           [1] => 507162
                       )

               )

           [10] => Array
               (
                   [length] => 44577773
                   [path] => Array
                       (
                           [0] => meet the deadline - Still _ Evoke 2014.mp4
                       )

               )

           [11] => Array
               (
                   [attr] => p
                   [length] => 510995
                   [path] => Array
                       (
                           [0] => .pad
                           [1] => 510995
                       )

               )

           [12] => Array
               (
                   [attr] => x
                   [length] => 61
                   [path] => Array
                       (
                           [0] => readme.txt
                       )

               )

           [13] => Array
               (
                   [attr] => p
                   [length] => 524227
                   [path] => Array
                       (
                           [0] => .pad
                           [1] => 524227
                       )

               )

           [14] => Array
               (
                   [attr] => x
                   [length] => 26296320
                   [path] => Array
                       (
                           [0] => tbl-goa.avi
                       )

               )

           [15] => Array
               (
                   [attr] => p
                   [length] => 442368
                   [path] => Array
                       (
                           [0] => .pad
                           [1] => 442368
                       )

               )

           [16] => Array
               (
                   [length] => 115869700
                   [path] => Array
                       (
                           [0] => tbl-tint.mpg
                       )

               )

       )

)
Last edited by STorrents2020 on 2022-02-15 21:51:30
2022-02-16 06:11:34
2022-02-16 22:18:32
Now for the file list work within directories


// Detect if item is within a directory (v1)
foreach ($torrentInfo['files'] as $file)
{
  if (strstr(implode('/', $file['path']), '/')) {
     echo "I am in a folder";
  }
}

Last edited by STorrents2020 on 2022-02-16 22:19:42
2022-02-22 14:44:29
better use file tree instead of this
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
2022-02-24 03:16:17
Not for display purposes, no.

Who wants to read through and wonder what a “pad file” is? Only after they decide that this “pad” file must not be what they are looking for, therefor it becomes a strange and confusing torrent to almost all users.

Your statement also held no reason or explanation for perfectly good code. Enjoy lol
2022-02-27 20:18:59
but most of the torrent sites use file tree still they are fine
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
2022-02-28 04:46:54
I noticed the piratebay shows all this, I wasn't really sure why
2022-02-28 12:20:50
TPB is huge and they want to run the site using less resources. even they disabled comments and registration too.

i mean look at others like 1337x, kickass they have been using file tree long before.
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
2022-02-28 20:25:11
I have beyond what any of those sites have, I can’t say I am too concerned about a fully populated file tree - TPB disabled registrations because of legal and new ownership, it’s a miracle it’s still online. Most use their Tor address now anyway so maybe it’s different on their onion address
2022-03-19 13:21:07
i mean checkout others 1337x - they use filetree / you remember kickass? even they used filetree
TPB is running on less resources, that is why they are not adding any new/old stuff(comments)
follow the thread for updates
checkout my project: https://bvlist.com/showthread.php?t=12349
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