Merge pull request #293 from eai04191/feature/resolver-xtube-fix
XtubeResolver 修正
This commit is contained in:
commit
9c101dfb7b
@ -11,10 +11,15 @@ class XtubeResolver implements Resolver
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
/**
|
||||
* @var OGPResolver
|
||||
*/
|
||||
private $ogpResolver;
|
||||
|
||||
public function __construct(Client $client)
|
||||
public function __construct(Client $client, OGPResolver $ogpResolver)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->ogpResolver = $ogpResolver;
|
||||
}
|
||||
|
||||
public function resolve(string $url): Metadata
|
||||
@ -25,17 +30,14 @@ class XtubeResolver implements Resolver
|
||||
|
||||
$res = $this->client->get($url);
|
||||
$html = (string) $res->getBody();
|
||||
$metadata = new Metadata();
|
||||
$metadata = $this->ogpResolver->parse($html);
|
||||
$crawler = new Crawler($html);
|
||||
|
||||
// poster URL抽出
|
||||
$playerConfig = explode("\n", trim($crawler->filter('#playerWrapper script')->last()->text()));
|
||||
preg_match('~https:\\\/\\\/cdn\d+-s-hw-e5\.xtube\.com\\\/m=(?P<size>.{8})\\\/videos\\\/\d{6}\\\/\d{2}\\\/.{5}-.{4}-\\\/original\\\/\d+\.jpg~', $playerConfig[0], $matches);
|
||||
$metadata->image = str_replace('\/', '/', $matches[0]);
|
||||
|
||||
$metadata->title = trim($crawler->filter('.underPlayerRateForm h1')->text(''));
|
||||
$metadata->description = trim($crawler->filter('.fullDescription ')->text(''));
|
||||
$metadata->tags = $crawler->filter('.tagsCategories a')->extract('_text');
|
||||
$metadata->image = str_replace('m=eSuQ8f', 'm=eaAaaEFb', $metadata->image);
|
||||
$metadata->image = str_replace('240X180', 'original', $metadata->image);
|
||||
$metadata->tags = array_map('trim', $crawler->filter('.tagsCategories a')->extract('_text'));
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
1031
tests/fixture/Xtube/video.html
vendored
1031
tests/fixture/Xtube/video.html
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user