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.  
  26.     /**
  27.     * File_Bittorrent Example
  28.     * Get Info from a .torrent file
  29.     *
  30.     * Usage:
  31.     *   # php torrentinfo.php -t file.torrent
  32.     *
  33.     * @author Markus Tacker <m@tacker.org>
  34.     * @version $Id: torrentinfo.php 55 2006-07-02 16:48:09Z m $
  35.     */
  36.  
  37.     // Includes
  38.     require_once 'File/Bittorrent/Decode.php';
  39.     require_once 'Console/Getargs.php';
  40.  
  41.     // Set error handling
  42.     PEAR::setErrorHandling(PEAR_ERROR_PRINT);
  43.  
  44.     // Get filename from command line
  45.     $args_config = array(
  46.         'torrent' => array(
  47.             'short' => 't',
  48.             'min' => 1,
  49.             'max' => 1,
  50.             'desc' => 'Filename of the torrent'
  51.         ),
  52.     );
  53.     $args =Console_Getargs::factory($args_config);
  54.     if (PEAR::isError($argsor !($torrent $args->getValue('torrent'))) {
  55.         echo Console_Getargs::getHelp($args_config)."\n";
  56.         exit;
  57.     }
  58.  
  59.     if (!is_readable($torrent)) {
  60.         echo 'ERROR: "' $torrent "\" is not readable.\n";
  61.         exit;
  62.     }
  63.  
  64.     $File_Bittorrent_Decode = new File_Bittorrent_Decode;
  65.     $info $File_Bittorrent_Decode->decodeFile($torrent);
  66.  
  67.     foreach ($info as $key => $val{
  68.         echo str_pad($key ': '20' 'STR_PAD_LEFT);
  69.         switch($key{
  70.         case 'files':
  71.             $n = 1;
  72.             $files_n count($val);
  73.             $n_length strlen($files_n);
  74.             echo '(' $files_n ")\n";
  75.             foreach ($val as $file{
  76.                 echo str_repeat(' '20'' str_pad($n$n_length' 'PAD_LEFT': ' $file['filename'"\n";
  77.                 $n++;
  78.             }
  79.             break;
  80.         case 'announce_list':
  81.             echo "\n";
  82.             foreach ($val as $list{
  83.                 echo str_repeat(' '20'- ' join(', '$list"\n";
  84.             }
  85.             break;
  86.         default:
  87.             echo $val "\n";
  88.         }
  89.     }
  90.  
  91.     echo "\n";
  92.  
  93. ?>

Documentation generated on Tue, 13 Mar 2007 10:00:15 -0500 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.