* * @package StealThisTracker * @author StealThisShow <*****@*****.**> * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause */ use StealThisShow\StealThisTracker\Core; use StealThisShow\StealThisTracker\Torrent; use StealThisShow\StealThisTracker\Persistence\Pdo; use StealThisShow\StealThisTracker\File\File; // ----------------------------------------------------------- // This is how to create a .torrent file from a physical file. // ----------------------------------------------------------- // Composer autoloader require dirname(__FILE__) . '/../vendor/autoload.php'; // Persistence object implementing PersistenceInterface. // We use Pdo here. $persistence = new Pdo('sqlite:sqlite_example.db'); // Core class managing creating the file. $core = new Core($persistence); // The torrent file $file = new File('/path/to/file.ext'); // The first parameters is the file. $torrent = new Torrent($file); $torrent->setAnnounceList(array('http://announce'))->setSizePiece(262144); // Setting appropriate HTTP header and sending back the .torrrent file. // This is VERY inefficient to do! SAVE the .torrent file on your server and // serve the saved copy! header('Content-Type: application/x-bittorrent'); header('Content-Disposition: attachment; filename="test.torrent"'); // Outputs torrent content echo (string) $core->addTorrent($torrent);
/** * Given a 20 bytes info hash, returns an initialized Torrent object. * * Must return null if the info hash is not found. * * @param string $info_hash Info hash * * @return Torrent */ public function getTorrent($info_hash) { $sql = <<<SQL SELECT `info_hash`, `length`, `pieces_length`, `pieces`, `name`, `path`, `private`, `announce_list`, `nodes`, `url_list`, `created_by` FROM `stealthistracker_torrents` WHERE `info_hash` = :info_hash AND `status` = 'active' SQL; $statement = $this->query($sql, array(':info_hash' => $info_hash)); $row = $statement->fetch(); if ($row) { $torrent = new Torrent(new File($row['path']), $row['pieces_length']); return $torrent->setFilePath($row['path'])->setName($row['name'])->setLength($row['length'])->setPieces($row['pieces'])->setPrivate($row['private'])->setAnnounceList(unserialize($row['announce_list']))->setNodes(unserialize($row['nodes']))->setUrlList(unserialize($row['url_list']))->setCreatedBy($row['created_by'])->setInfoHash($row['info_hash']); } return null; }