File_Bittorrent2
[ class tree: File_Bittorrent2 ] [ index: File_Bittorrent2 ] [ 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 77 2007-08-26 09:42:22Z m $
  32.     */
  33.  
  34.     // Includes
  35.     require_once 'File/Bittorrent2/Decode.php';
  36.     require_once 'Console/Getargs.php';
  37.  
  38.     // Get filename from command line
  39.     $args_config = array(
  40.         'torrent' => array(
  41.             'short' => 't',
  42.             'min' => 1,
  43.             'max' => 1,
  44.             'desc' => 'Filename of the torrent'
  45.         ),
  46.     );
  47.     $args =Console_Getargs::factory($args_config);
  48.     if (PEAR::isError($argsor !($torrent $args->getValue('torrent'))) {
  49.         echo Console_Getargs::getHelp($args_config)."\n";
  50.         exit;
  51.     }
  52.  
  53.     if (!is_readable($torrent)) {
  54.         echo 'ERROR: "' $torrent "\" is not readable.\n";
  55.         exit;
  56.     }
  57.  
  58.     // Decode the torrent
  59.     $File_Bittorrent2_Decode = new File_Bittorrent2_Decode;
  60.     $File_Bittorrent2_Decode->decodeFile($torrent);
  61.  
  62.     echo "\nStatistics\n";
  63.     echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
  64.     echo 'Tracker:            ' $File_Bittorrent2_Decode->getAnnounce("\n";
  65.     echo 'info hash:          ' $File_Bittorrent2_Decode->getInfoHash("\n";
  66.     foreach ($File_Bittorrent2_Decode->getStats(as $key => $val{
  67.         echo str_pad($key ':'20$val "\n";
  68.     }
  69.  
  70. ?>

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