diff --git a/src/Adapter/ThePirateBayAdapter.php b/src/Adapter/ThePirateBayAdapter.php index 7ca41d1..060627a 100644 --- a/src/Adapter/ThePirateBayAdapter.php +++ b/src/Adapter/ThePirateBayAdapter.php @@ -31,7 +31,7 @@ public function search($query) } catch (ClientException $e) { return []; } - + $crawler = new Crawler((string) $response->getBody()); $items = $crawler->filter('#searchResult tr'); $results = []; @@ -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; } diff --git a/src/Entity/SearchResult.php b/src/Entity/SearchResult.php index 8f6aa06..13684fc 100644 --- a/src/Entity/SearchResult.php +++ b/src/Entity/SearchResult.php @@ -29,6 +29,11 @@ class SearchResult */ protected $magnetUrl; + /** + * @var string + */ + protected $uploader; + /** * @param string $name */ @@ -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; + } } diff --git a/tests/Adapter/ThePirateBayAdapterTest.php b/tests/Adapter/ThePirateBayAdapterTest.php index 2852fc5..30f0253 100644 --- a/tests/Adapter/ThePirateBayAdapterTest.php +++ b/tests/Adapter/ThePirateBayAdapterTest.php @@ -41,6 +41,7 @@ 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); @@ -48,6 +49,7 @@ public function testIsPerformingSearch() $result2 = new SearchResult(); $result2->setName('elementaryos-beta2-amd64.20130506.iso'); + $result2->setUploader('ixcoder'); $result2->setSeeders(1); $result2->setLeechers(0); $result2->setTorrentUrl(null); @@ -55,6 +57,7 @@ public function testIsPerformingSearch() $result3 = new SearchResult(); $result3->setName('ElementaryOS 64-bit 20130810'); + $result3->setUploader(null); $result3->setSeeders(1); $result3->setLeechers(0); $result3->setTorrentUrl(null);