Refactored classes and functionality, added more data caching, working on topic parser.
This commit is contained in:
41
src/Traits/TopicTrait.php
Normal file
41
src/Traits/TopicTrait.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Toloka\PhpApi\Traits;
|
||||
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
use Toloka\PhpApi\Exception\Topic\TopicNotFound;
|
||||
use Toloka\PhpApi\TopicInterface;
|
||||
|
||||
trait TopicTrait {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getTopic(int $id): TopicInterface {
|
||||
$response = $this->makeRequest('GET', "/t{$id}?spmode=full&dl=names");
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
throw new TopicNotFound();
|
||||
}
|
||||
$crawler = new Crawler($response->getBody()->getContents());
|
||||
|
||||
$title = $crawler->filter('a.maintitle')->first()->text();
|
||||
|
||||
$crumbs = $crawler->filter('.bodyline td.nav > span, .bodyline td.nav > h2');
|
||||
if ($crumbs->eq(1)->text() === 'Відео') {
|
||||
|
||||
}
|
||||
|
||||
$g = 1;
|
||||
|
||||
$imdb_id = NULL;
|
||||
$imdb_link = $crawler->filter('a[href*="imdb.com"]');
|
||||
if ($imdb_link->count() > 0) {
|
||||
preg_match("/tt\\d{7,8}/", $imdb_link->first()->attr('href'), $imdb_ids);
|
||||
if (!empty($imdb_ids)) {
|
||||
$imdb_id = reset($imdb_ids);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user