darkalchemy/scrapeer

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

0.6.4 2021-05-01 13:51 UTC

This package is auto-updated.

Last update: 2024-09-29 05:42:46 UTC


README

Codacy Badge

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

功能

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

基本用法示例

单个信息哈希和单个追踪器

使用Composer安装

composer require darkalchemy/scrapeer
use App\Scraper;

require __DIR__ . '/vendor/autoload.php';

$scraper = new 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。
  • 单个元素也可以是字符串,而不是数组。

单个信息哈希和多个追踪器(推荐用法)

$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 ) )
  • 如果数组中的第一个追踪器失败(无效追踪器、无效信息哈希或该追踪器的无效信息哈希),则将使用第二个追踪器,依此类推。
  • 在这种情况下,我们从第一个追踪器获得了有效的结果,请注意,对于相同的种子我们获得了不同的信息 - 这是预期的,因为不同的追踪器可能比其他追踪器更新或更旧。

多个信息哈希和单个追踪器

$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 ) )
  • 信息哈希可以是大写或小写。

多个信息哈希和多个追踪器

$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)." )
  • 第一个追踪器无效,它将被跳过,并将错误添加到错误记录器中。
  • 刮削器将继续刮削,直到找到一个有效的追踪器或没有更多追踪器要尝试。
  • 无效的信息哈希将被记录并跳过。

高级选项

最大追踪器数量

$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。
  • 对于多个信息哈希,优先使用抓取请求而不是公告请求(通常更快)。
  • 注意: UDP追踪器只返回种子和下载者信息。这是协议限制

常见问题解答

  • 什么是信息哈希?我怎样才能获得它们?

来自比特Torrent协议规范

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

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

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

查看newTrackontrackerslist