Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added uploader to Piratebay search results #5

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Adapter/ThePirateBayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function search($query)
} catch (ClientException $e) {
return [];
}

$crawler = new Crawler((string) $response->getBody());
$items = $crawler->filter('#searchResult tr');
$results = [];
Expand All @@ -50,6 +50,13 @@ public function search($query)
$result->setSeeders((int) $itemCrawler->filter('td')->eq(2)->text());
$result->setLeechers((int) $itemCrawler->filter('td')->eq(3)->text());
$result->setMagnetUrl($itemCrawler->filterXpath('//tr/td/a')->attr('href'));
$uploader = null;
try {
$uploader = $itemCrawler->filter('.detDesc a')->text();
} catch (\InvalidArgumentException $e) {
// Handle the current node list is empty..
}
$result->setUploader($uploader);

$results[] = $result;
}
Expand Down
21 changes: 21 additions & 0 deletions src/Entity/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class SearchResult
*/
protected $magnetUrl;

/**
* @var string
*/
protected $uploader;

/**
* @param string $name
*/
Expand Down Expand Up @@ -108,4 +113,20 @@ public function getMagnetUrl()
{
return $this->magnetUrl;
}

/**
* @param string $uploader
*/
public function setUploader($uploader)
{
$this->uploader = $uploader;
}

/**
* @return string
*/
public function getUploader()
{
return $this->uploader;
}
}
3 changes: 3 additions & 0 deletions tests/Adapter/ThePirateBayAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@ public function testIsPerformingSearch()
$adapter->setHttpClient(new Client(['handler' => $mockHandler]));
$result1 = new SearchResult();
$result1->setName('elementaryos-beta2-i386.20130506.iso');
$result1->setUploader('ixcoder');
$result1->setSeeders(1);
$result1->setLeechers(0);
$result1->setTorrentUrl(null);
$result1->setMagnetUrl('magnet:?xt=urn:btih:&dn=elementaryos-beta2-i386.20130506.iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969');

$result2 = new SearchResult();
$result2->setName('elementaryos-beta2-amd64.20130506.iso');
$result2->setUploader('ixcoder');
$result2->setSeeders(1);
$result2->setLeechers(0);
$result2->setTorrentUrl(null);
$result2->setMagnetUrl('magnet:?xt=urn:btih:&dn=elementaryos-beta2-amd64.20130506.iso&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969');

$result3 = new SearchResult();
$result3->setName('ElementaryOS 64-bit 20130810');
$result3->setUploader(null);
$result3->setSeeders(1);
$result3->setLeechers(0);
$result3->setTorrentUrl(null);
Expand Down