medariox / scrapeer

Essential PHP library that scrapes HTTP(S) and UDP trackers for torrent information.
93 stars 29 forks source link

Error: Scrapeer\Scraper::try_scrape() must be an instance of Scrapeer\string #10

Closed RonnyDT closed 7 years ago

RonnyDT commented 7 years ago

Hi I'm pretty new to this and tried your library today as it can scrape udp but whenever i'm trying to scrape I get this error:

Catchable fatal error: Argument 1 passed to Scrapeer\Scraper::try_scrape() must be an instance of Scrapeer\string, string given, called in scraper.php on line 87 and defined in scraper.php on line 108

Tested with Driverpack torrent:

Used hash array: Array ( [0] => a694ac1c039393e709de9979a7e7a176d6c0d809 )
Tracker array: Array ( [0] => http://tracker.trackerfix.com:80/announce [1] => udp://9.rarbg.me:2710/announce [2] => udp://9.rarbg.to:2710/announce [3] => udp://9.rarbg.com:2710/announce [4] => udp://tracker.trackerfix.com:80/announce ) 
PHP Version: 5.4.17

Basically copy pasted a basic usage example. Am I doing something wrong?

Thanks!

medariox commented 7 years ago

Can you share the code please?

RonnyDT commented 7 years ago

At the top of my upload.php:

require 'scraper.php';

Then I use torrent-rw by adriengibrat and fix it's array to match what Scrapeer needs.

$scraper = new Scrapeer\Scraper();
$hash = array($torrent->hash_info());
$trackers = array(); $announcelist = $torrent->announce();
foreach ($announcelist as $key => $value) {
    array_push($trackers, $value[0]);
}
$info = $scraper->scrape($hash, $trackers, 5, 2);
medariox commented 7 years ago

Just tried to reproduce here.

Using this code:

<?php

require_once 'scraper.php';
require_once 'torrents.php';

$scraper = new Scrapeer\Scraper();
$torrent = new Torrent( './my.torrent' );

$hash = array( $torrent->hash_info() );

$trackers = array();
$announcelist = $torrent->announce();

foreach ( $announcelist as $key => $value ) {
    array_push( $trackers, $value[0] );
}
$info = $scraper->scrape( $hash, $trackers, 5, 2 );

print_r( $info );

It works as expected. The only difference is that I'm using PHP 7.0. Can you try the code above a see if it works? Otherwise the issue must be somewhere else.

medariox commented 7 years ago

Turns out PHP doesn't support type hints for strings prior to version 7.0. I just pushed a new version that should work with any version of PHP >= 5.4.0. Please let me know how it goes.

RonnyDT commented 7 years ago

I'm now getting the following error when trying to get scrape data from an UDP tracker: Fatal error: Call to undefined function Scrapeer\random_int() in scraper.php on line 324

Checked the php_manual and the random_int() function is also phpv7.0.

medariox commented 7 years ago

You are right of course. Switched to mt_rand() instead. Thanks for the feedback!

RonnyDT commented 7 years ago

No problem, thank you for the fast responses and fixes!