File_Bittorrent
[ class tree: File_Bittorrent ] [ index: File_Bittorrent ] [ all elements ]

Source for file torrentinfo.php

Documentation is available at torrentinfo.php

  1. <?php
  2.  
  3.     // +----------------------------------------------------------------------+
  4.     // | Decode and Encode data in Bittorrent format                          |
  5.     // +----------------------------------------------------------------------+
  6.     // | Copyright (C) 2004-2005 Markus Tacker <m@tacker.org>                 |
  7.     // +----------------------------------------------------------------------+
  8.     // | This library is free software; you can redistribute it and/or        |
  9.     // | modify it under the terms of the GNU Lesser General Public           |
  10.     // | License as published by the Free Software Foundation; either         |
  11.     // | version 2.1 of the License, or (at your option) any later version.   |
  12.     // |                                                                      |
  13.     // | This library is distributed in the hope that it will be useful,      |
  14.     // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  15.     // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
  16.     // | Lesser General Public License for more details.                      |
  17.     // |                                                                      |
  18.     // | You should have received a copy of the GNU Lesser General Public     |
  19.     // | License along with this library; if not, write to the                |
  20.     // | Free Software Foundation, Inc.                                       |
  21.     // | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA               |
  22.     // +----------------------------------------------------------------------+
  23.  
  24.     /**
  25.     * File_Bittorrent Example
  26.     * Get Info from a .torrent file
  27.     *
  28.     * Usage:
  29.     *   # php torrentinfo.php -t file.torrent
  30.     *
  31.     * @author Markus Tacker <m@tacker.org>
  32.     * @version $Id: torrentinfo.php 55 2006-07-02 16:48:09Z m $
  33.     */
  34.  
  35.     // Includes
  36.     require_once 'File/Bittorrent/Decode.php';
  37.     require_once 'Console/Getargs.php';
  38.  
  39.     // Set error handling
  40.     PEAR::setErrorHandling(PEAR_ERROR_PRINT);
  41.  
  42.     // Get filename from command line
  43.     $args_config = array(
  44.         'torrent' => array(
  45.             'short' => 't',
  46.             'min' => 1,
  47.             'max' => 1,
  48.             'desc' => 'Filename of the torrent'
  49.         ),
  50.     );
  51.     $args =Console_Getargs::factory($args_config);
  52.     if (PEAR::isError($argsor !($torrent $args->getValue('torrent'))) {
  53.         echo Console_Getargs::getHelp($args_config)."\n";
  54.         exit;
  55.     }
  56.  
  57.     if (!is_readable($torrent)) {
  58.         echo 'ERROR: "' $torrent "\" is not readable.\n";
  59.         exit;
  60.     }
  61.  
  62.     $File_Bittorrent_Decode = new File_Bittorrent_Decode;
  63.     $info $File_Bittorrent_Decode->decodeFile($torrent);
  64.  
  65.     foreach ($info as $key => $val{
  66.         echo str_pad($key ': '20' 'STR_PAD_LEFT);
  67.         switch($key{
  68.         case 'files':
  69.             $n = 1;
  70.             $files_n count($val);
  71.             $n_length strlen($files_n);
  72.             echo '(' $files_n ")\n";
  73.             foreach ($val as $file{
  74.                 echo str_repeat(' '20'' str_pad($n$n_length' 'PAD_LEFT': ' $file['filename'"\n";
  75.                 $n++;
  76.             }
  77.             break;
  78.         case 'announce_list':
  79.             echo "\n";
  80.             foreach ($val as $list{
  81.                 echo str_repeat(' '20'- ' join(', '$list"\n";
  82.             }
  83.             break;
  84.         default:
  85.             echo $val "\n";
  86.         }
  87.     }
  88.  
  89.     echo "\n";
  90.  
  91. ?>

Documentation generated on Mon, 11 Mar 2019 14:57:21 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.