コード例 #1
0
 /**
  * Search for torrents.
  *
  * @param string $query
  * @param int    $category
  * @return array Array of torrents. Either empty or filled.
  */
 public function search($query, $category)
 {
     # Set single-cell view for torrents.
     $requestOptions = ['headers' => ['User-Agent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36']];
     try {
         $url = $this->makeUrl($query, $category);
         $response = $this->httpClient->get($url, $requestOptions);
         $crawler = new Crawler((string) $response->getBody());
     } catch (\Exception $e) {
         return [];
     }
     $items = $crawler->filterXpath('//channel/item');
     $torrents = [];
     foreach ($items as $item) {
         $torrent = new Torrent();
         $itemCrawler = new Crawler($item);
         // Set details for torrent.
         $torrent->setSite($this->tag);
         $torrent->setTitle($itemCrawler->filterXpath('//title')->text());
         $torrent->setSeeders((int) $itemCrawler->filterXpath('//torrent:seeds')->text());
         $torrent->setLeechers((int) $itemCrawler->filterXpath('//torrent:peers')->text());
         $torrent->setMagnet($itemCrawler->filterXpath('//torrent:magnetURI')->text());
         $torrent->setSize($this->formatBytes((int) $itemCrawler->filterXPath('//torrent:contentLength')->text()));
         $torrent->setAge($itemCrawler->filterXPath('//pubDate')->text());
         $torrent->setCategory($itemCrawler->filterXPath('//category')->text());
         $torrents[] = $torrent;
     }
     return $torrents;
 }
コード例 #2
0
 /**
  * Search for torrents.
  *
  * @param string $query
  * @param int    $category
  * @return array Array of torrents. Either empty or filled.
  */
 public function search($query, $category)
 {
     # Set single-cell view for torrents.
     $requestOptions = ['headers' => ['User-Agent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'], 'cookies' => ['lw' => 's']];
     try {
         $url = $this->makeUrl($query, $category);
         $response = $this->httpClient->get($url, $requestOptions);
         $crawler = new Crawler((string) $response->getBody());
     } catch (\Exception $e) {
         // TODO: Log error. Some error has occured.
         return [];
     }
     $items = $crawler->filter('#searchResult tr');
     $torrents = [];
     $firstRow = true;
     foreach ($items as $item) {
         // Ignore the first row.
         if ($firstRow) {
             $firstRow = false;
             continue;
         }
         $torrent = new Torrent();
         $itemCrawler = new Crawler($item);
         // Set details for torrent.
         $torrent->setSite($this->tag);
         $torrent->setTitle(trim($itemCrawler->filter('td')->eq(1)->text()));
         $torrent->setSeeders((int) $itemCrawler->filter('td')->eq(5)->text());
         $torrent->setLeechers((int) $itemCrawler->filter('td')->eq(6)->text());
         $torrent->setMagnet($itemCrawler->filterXpath('/td[3]/a[0]')->attr('href'));
         $torrent->setSize($itemCrawler->filter('td')->eq(4)->text());
         $torrent->setAge($itemCrawler->filterXPath('/td[2]')->text());
         $torrent->setCategory($itemCrawler->filterXPath('/td[0]')->text());
         $torrents[] = $torrent;
     }
     return $torrents;
 }