root/trunk/scrape.php

Revision 84, 3.0 KB (checked in by m, 5 months ago)

Tagging 2.2.0 release

  • Property svn:keywords set to Id Rev
Line 
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$
32    */
33
34    // Includes
35    require_once 'File/Bittorrent/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($args) or !($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_Bittorrent_Decode = new File_Bittorrent_Decode;
60    $File_Bittorrent_Decode->decodeFile($torrent);
61
62    echo "\nStatistics\n";
63    echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
64    echo 'Tracker:            ' . $File_Bittorrent_Decode->getAnnounce() . "\n";
65    echo 'info hash:          ' . $File_Bittorrent_Decode->getInfoHash() . "\n";
66    foreach ($File_Bittorrent_Decode->getStats() as $key => $val) {
67        echo str_pad($key . ':', 20) . $val . "\n";
68    }
69
70?>
Note: See TracBrowser for help on using the browser.