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
Torrent api when uploading
Controls ·  Search New posts · Mark unread

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

Unknown User
2019-09-18 18:43:59
I rather create new from scratch such as a PHP 7 version of BDecode


<?php

namespace System\Protocol;

class Bdecode
{
   /**
    * Bencode.
    *
    * @var string
    */
   protected $bencode;

   /**
    * Length.
    *
    * @var integer
    */
   protected $length = 0;

   /**
    * Offset.
    *
    * @var integer
    */
   protected $offset = 0;

   /**
    * Decode.
    *
    * @param  string $bencode
    * @return mixed
    */
   public function decode(string $bencode = null)
   {
       if ($this->bencode === null) {
           if ($bencode !== null) {
               $this->bencode = $bencode;
               $this->length  = strlen($bencode);
           } else {
               return null;
           }
       }

       if ($this->offset >= $this->length) {
           return null;
       }

       $char = $this->bencode[$this->offset];
       if ($char === 'd') {
           return $this->decodeDict();
       } elseif ($char === 'l') {
           return $this->decodeList();
       } elseif ($char === 'i') {
           return $this->decodeInt();
       } elseif (is_numeric($char)) {
           return $this->decodeStr();
       } else {
           return null;
       }
   }

   /**
    * Decode dictionary.
    *
    * @return array|null
    */
   private function decodeDict()
   {
       $start = substr($this->bencode, $this->offset, 1);
       if ($start !== 'd') {
           return null;
       }

       $limit = substr($this->bencode, -1);
       if ($limit !== 'e') {
           return null;
       }

       $this->offset++;

       $dict = [];
       while ($this->bencode[$this->offset] !== 'e') {
           $index = $this->decodeStr();
           if ($index === null) {
               return null;
           }
           $value = $this->decode();
           if ($value === null) {
               return null;
           }
           $dict[$index] = $value;
       }

       $this->offset++;

       return $dict;
   }

   /**
    * Decode list.
    *
    * @return array|null
    */
   private function decodeList()
   {
       $start = substr($this->bencode, $this->offset, 1);
       if ($start !== 'l') {
           return null;
       }

       $limit = substr($this->bencode, -1);
       if ($limit !== 'e') {
           return null;
       }

       $this->offset++;

       $list = [];
       while ($this->bencode[$this->offset] !== 'e') {
           $value = $this->decode();
           if ($value === null) {
               return null;
           }
           $list[] = $value;
       }

       $this->offset++;

       return $list;
   }

   /**
    * Decode integer.
    *
    * @return string|null
    */
   private function decodeInt()
   {
       $start = substr($this->bencode, $this->offset, 1);
       if ($start !== 'i') {
           return null;
       }

       $limit = strpos($this->bencode, 'e', $this->offset);
       if ($limit === false) {
           return null;
       }

       $this->offset++;

       $buffer = '';
       while ($this->offset < $limit) {
           $buffer .= $this->bencode[$this->offset];
           $this->offset++;
       }

       $this->offset++;

       if (preg_match('@^([0]|[-]?[1-9][0-9]*)$@', $buffer)) {
           return 0 + $buffer;
       } else {
           return null;
       }
   }

   /**
    * Decode string.
    *
    * @return string|null
    */
   private function decodeStr()
   {
       $delimiter = strpos($this->bencode, ':', $this->offset);
       if ($delimiter === false) {
           return null;
       }

       $length = substr($this->bencode, $this->offset, $delimiter - $this->offset);
       if (! preg_match('@^([0]|[1-9][0-9]*)$@', $length)) {
           return null;
       }
       $this->offset = ++$delimiter;

       $buffer = substr($this->bencode, $this->offset, $length);
       $strlen = strlen($buffer);
       if ($strlen != $length) {
           return null;
       }
       $this->offset += $length;

       return $buffer;
   }
}
Unknown User
2019-09-18 18:58:26
so you plan to create it to host torrents on external server which will let users store torrents as hash
Unknown User
2019-09-18 19:25:18
Yes.
Unknown User
2019-09-18 19:29:00
sounds great
2020-01-27 00:33:56
"mostvotedplaya, post: 67198, member: 20335":

I would call that more of a mirroring service for torrents.

I made an actual API uploading service for TT some years ago, the core really needs this feature.


I remember that, you did it for me for a gaming site
Unknown User
2020-02-22 20:25:46
I almost finished the code for this project, to start with it will support a few methods:

GET /torrents
- Will allow people to iterate through the torrents held by the service, it will provide two pieces of info for each torrent held e.g: the name of the uploaded file and infohash.

GET /torrent/<infohash>
- Return the .torrent file for downloading if it exists.

GET /torrent/search/<query>
- Return name of uploaded .torrent file, infohash.

PUT /torrent
- Upload a .torrent

The service will have a api request limit, i am currently thinking of allowing 250 requests per hour.

There is a whole spectrum of things i had to think about whilst making this project whether to allow private torrents or not and i decided that these will be rejected.

Torrents could be trackerless and rely on DHT, these will be supported.

Once the project is finished i will post back here with the location, i need to come up with a name for the service. It will be possible for somebody to write a script in TT's backend to search / import .torrents
Screen Shot 2020-02-22 at 20.14.59.png
Screen Shot 2020-02-22 at 20.14.59.png
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