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

Source for file scrape.php

Documentation is available at scrape.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.     * Fetch the statistics for a torrent
  28.     *
  29.     * Usage:
  30.     *   # php scrape.php -t file
  31.     *
  32.     * @author Markus Tacker <m@tacker.org>
  33.     * @version $Id: scrape.php 48 2005-10-19 16:49:52Z m $
  34.     */
  35.  
  36.     // Includes
  37.     require_once 'File/Bittorrent/Decode.php';
  38.     require_once 'Console/Getargs.php';
  39.  
  40.     // Set error handling
  41.     PEAR::setErrorHandling(PEAR_ERROR_PRINT);
  42.  
  43.     // Get filename from command line
  44.     $args_config = array(
  45.         'torrent' => array(
  46.             'short' => 't',
  47.             'min' => 1,
  48.             'max' => 1,
  49.             'desc' => 'Filename of the torrent'
  50.         ),
  51.     );
  52.     $args =Console_Getargs::factory($args_config);
  53.     if (PEAR::isError($argsor !($torrent $args->getValue('torrent'))) {
  54.         echo Console_Getargs::getHelp($args_config)."\n";
  55.         exit;
  56.     }
  57.  
  58.     if (!is_readable($torrent)) {
  59.         echo 'ERROR: "' $torrent "\" is not readable.\n";
  60.         exit;
  61.     }
  62.  
  63.     // Decode the torrent
  64.     $File_Bittorrent_Decode = new File_Bittorrent_Decode;
  65.     $File_Bittorrent_Decode->decodeFile($torrent);
  66.  
  67.     echo "\nStatistics\n";
  68.     echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
  69.     echo 'Tracker:            ' $File_Bittorrent_Decode->announce . "\n";
  70.     echo 'info hash:          ' $File_Bittorrent_Decode->info_hash . "\n";
  71.     foreach ($File_Bittorrent_Decode->getStats(as $key => $val{
  72.         echo str_pad($key ':'20$val "\n";
  73.     }
  74.  
  75. ?>

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