Merge pull request #293 from eai04191/feature/resolver-xtube-fix

XtubeResolver 修正
This commit is contained in:
shibafu 2019-11-05 08:17:34 +09:00 committed by GitHub
commit 9c101dfb7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 805 additions and 254 deletions

View File

@ -11,10 +11,15 @@ class XtubeResolver implements Resolver
* @var Client * @var Client
*/ */
private $client; private $client;
/**
* @var OGPResolver
*/
private $ogpResolver;
public function __construct(Client $client) public function __construct(Client $client, OGPResolver $ogpResolver)
{ {
$this->client = $client; $this->client = $client;
$this->ogpResolver = $ogpResolver;
} }
public function resolve(string $url): Metadata public function resolve(string $url): Metadata
@ -25,17 +30,14 @@ class XtubeResolver implements Resolver
$res = $this->client->get($url); $res = $this->client->get($url);
$html = (string) $res->getBody(); $html = (string) $res->getBody();
$metadata = new Metadata(); $metadata = $this->ogpResolver->parse($html);
$crawler = new Crawler($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->title = trim($crawler->filter('.underPlayerRateForm h1')->text(''));
$metadata->description = trim($crawler->filter('.fullDescription ')->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; return $metadata;
} }

File diff suppressed because one or more lines are too long