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

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