medariox/scrapeer

此包最新版本(dev-master)没有可用的许可证信息。

Scrapeer,一个小巧的PHP库,允许您抓取HTTP(S)和UDP追踪器以获取种子信息。

dev-master 2017-12-04 15:04 UTC

This package is not auto-updated.

Last update: 2024-09-21 15:45:18 UTC


README

Codacy Badge

Scrapeer,一个小巧的PHP库,允许您抓取HTTP(S)和UDP追踪器以获取种子信息。

特性

  • 检索种子、下载者和完成种子信息
  • 支持HTTP、HTTPS和UDP追踪器
  • 自动丢弃无效追踪器和info-hashes
  • 允许为每个追踪器设置超时和最大追踪器数量
  • 每个抓取支持多达64个info-hashes
  • 旨在尽可能轻量、直接和高效
  • 支持通过抓取(默认)和公告请求进行抓取 ✨

基本用法示例

单个info-hash和单个追踪器

require 'scraper.php';

$scraper = new Scrapeer\Scraper();

$tracker = array( 'udp://tracker.coppersurfer.tk:6969/announce' );
$hash = array( '4344503B7E797EBF31582327A5BAAE35B11BDA01' );

$info = $scraper->scrape( $hash, $tracker );
print_r( $info );

Array ( [4344503B7E797EBF31582327A5BAAE35B11BDA01] => Array ( [seeders] => 88 [completed] => 7737 [leechers] => 6 ) )

  • 如果未指定,端口将默认为HTTP/UDP的80,以及HTTPS的443。
  • 单个元素也可以是字符串而不是数组。

单个info-hash和多个追踪器(推荐用法)

$trackers = array( 'http://www.opentrackr.org/announce', 'udp://tracker.coppersurfer.tk:6969/announce' );
$hash = array( '4344503B7E797EBF31582327A5BAAE35B11BDA01' );

$info = $scraper->scrape( $hash, $trackers );
print_r( $info );

Array ( [4344503B7E797EBF31582327A5BAAE35B11BDA01] => Array ( [seeders] => 59 [completed] => 83 [leechers] => 3 ) )

  • 如果数组中的第一个追踪器失败(无效追踪器、无效info-hash或该追踪器的无效info-hash),则将使用第二个追踪器,依此类推。
  • 在这种情况下,我们从第一个追踪器获得了有效结果,注意我们获得了相同种子的不同信息 - 这是可以预料的,因为不同的追踪器可能比其他追踪器更新或不更新。

多个info-hashes和单个追踪器

$tracker = array( 'http://tracker.internetwarriors.net:1337/announce' );
$hashes = array( '699cda895af6fbd5a817fff4fe6fa8ab87e36f48', '4344503B7E797EBF31582327A5BAAE35B11BDA01' );

$info = $scraper->scrape( $hashes, $tracker );
print_r( $info );

Array ( [699cda895af6fbd5a817fff4fe6fa8ab87e36f48] => Array ( [seeders] => 4 [completed] => 236 [leechers] => 0 ) [4344503B7E797EBF31582327A5BAAE35B11BDA01] => Array ( [seeders] => 7 [completed] => 946 [leechers] => 3 ) )

  • info-hashes可以是大写或小写。

多个info-hashes和多个追踪器

$trackers = array( 'udp://tracker.coppersurfer.tk:6969/announce', 'http://explodie.org:6969/announce' );
$hashes = array( '699cda895af6fbd5a817fff4fe6fa8ab87e36f48', '4344503B7E797EBF31582327A5BAAE35B11BDA01' );

$info = $scraper->scrape( $hashes, $trackers );
print_r( $info );

Array ( [699cda895af6fbd5a817fff4fe6fa8ab87e36f48] => Array ( [seeders] => 52 [completed] => 2509 [leechers] => 1 ) [4344503B7E797EBF31582327A5BAAE35B11BDA01] => Array ( [seeders] => 97 [completed] => 7751 [leechers] => 11 ) )

高级用法示例

错误记录

$trackers = array( 'http://invalidtracker:6767/announce', 'udp://tracker.coppersurfer.tk:6969/announce' );
$hashes = array( '699cda895af6fbd5a817fff4fe6fa8ab87e36f48', '4344503B7E797EBF31582327A5BAAE35B11BDA01' );

$info = $scraper->scrape( $hashes, $trackers );

print_r( $info );

// Check if we have any errors.
if ( $scraper->has_errors() ) {
	// Get the errors and print them.
	print_r( $scraper->get_errors() );
}

Array ( [699cda895af6fbd5a817fff4fe6fa8ab87e36f48] => Array ( [seeders] => 49 [completed] => 2509 [leechers] => 1 ) [4344503B7E797EBF31582327A5BAAE35B11BDA01] => Array ( [seeders] => 99 [completed] => 7754 [leechers] => 7 ) ) Array ( [0] => Invalid scrape connection (invalidtracker:6767). )

  • 第一个追踪器无效,将被跳过,并将错误添加到错误记录器。
  • 抓取器将继续抓取,直到找到一个有效的追踪器或尝试了所有追踪器。
  • 无效的info-hashes将被记录并跳过。

高级选项

最大追踪器数量

$trackers = array( 'http://invalidtracker:6767/announce', 'udp://tracker.coppersurfer.tk:6969/announce' );
$hashes = array( '699cda895af6fbd5a817fff4fe6fa8ab87e36f48', '4344503B7E797EBF31582327A5BAAE35B11BDA01' );

// The max. amount of trackers to try is 1.
$info = $scraper->scrape( $hashes, $trackers, 1 );
  • 抓取器将在第一个追踪器后停止,无论其是否有效。
  • 默认:数组中的所有追踪器。

每个追踪器的超时时间

$trackers = array( 'http://invalidtracker:6767/announce', 'udp://tracker.coppersurfer.tk:6969/announce' );
$hashes = array( '699cda895af6fbd5a817fff4fe6fa8ab87e36f48', '4344503B7E797EBF31582327A5BAAE35B11BDA01' );

// The max. amount of trackers to try is 2 and timeout per tracker is 3s.
$info = $scraper->scrape( $hashes, $trackers, 2, 3 );
  • 每个追踪器将有3秒的超时时间(在这种情况下总超时时间为6秒)。
  • 默认:2秒(推荐)。

公告抓取

$trackers = array( 'udp://tracker.opentrackr.org:1337/announce', 'http://explodie.org:6969/announce' );
$hashes = array( '699cda895af6fbd5a817fff4fe6fa8ab87e36f48', '4344503B7E797EBF31582327A5BAAE35B11BDA01' );

$info = $scraper->scrape( $hashes, $trackers, 2, 3, true );
  • 默认:false。
  • 对于多个info-hashes,优先使用抓取请求而不是公告请求(通常更快)。
  • 注意: UDP追踪器只返回种子和下载者的信息。这是协议限制

常见问题解答

  • 什么是信息哈希?我如何获取它们?

来自 BitTorrent 协议规范

元信息文件中 info 值的 bencoded 形式的 20 字节 sha1 哈希值。注意,这仅是元信息文件的一个子串。信息哈希必须是 .torrent 文件中找到的编码形式的哈希值,无论其是否有效。这个值几乎肯定需要转义。

有很多方法可以从你的种子中检索信息哈希,例如,基于 PHP 的解决方案有 torrent-bencode

  • 我需要公共追踪器!我在哪里可以找到一些?

查看 newTrackontrackerslist