42 lines
999 B
PHP
42 lines
999 B
PHP
<?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);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|