Compare commits
1 Commits
GoToコヅクリ~お
...
feature/re
Author | SHA1 | Date | |
---|---|---|---|
|
7dac5df24b |
@ -33,6 +33,7 @@ class MetadataResolver implements Resolver
|
||||
'~store\.steampowered\.com/app/\d+~' => SteamResolver::class,
|
||||
'~www\.xtube\.com/video-watch/.*-\d+$~'=> XtubeResolver::class,
|
||||
'~ss\.kb10uy\.org/posts/\d+$~' => Kb10uyShortStoryServerResolver::class,
|
||||
'~(..|www)\.pornhub\.com/view_video\.php\?viewkey=.+$~'=> PornHubResolver::class,
|
||||
];
|
||||
|
||||
public $mimeTypes = [
|
||||
|
55
app/MetadataResolver/PornHubResolver.php
Normal file
55
app/MetadataResolver/PornHubResolver.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\MetadataResolver;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class PornHubResolver implements Resolver
|
||||
{
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
/**
|
||||
* @var OGPResolver
|
||||
*/
|
||||
private $ogpResolver;
|
||||
|
||||
public function __construct(Client $client, OGPResolver $ogpResolver)
|
||||
{
|
||||
$this->client = $client;
|
||||
$this->ogpResolver = $ogpResolver;
|
||||
}
|
||||
|
||||
public function resolve(string $url): Metadata
|
||||
{
|
||||
// if (preg_match('~www\.xtube\.com/video-watch/.*-(\d+)$~', $url, $matches) !== 1) {
|
||||
// throw new \RuntimeException("Unmatched URL Pattern: $url");
|
||||
// }
|
||||
// $videoid = $matches[1];
|
||||
|
||||
$res = $this->client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$html = (string) $res->getBody();
|
||||
$metadata = $this->ogpResolver->parse($html);
|
||||
$crawler = new Crawler($html);
|
||||
|
||||
$js = $crawler->filter('#player script')->text();
|
||||
if (preg_match('~({.+});~', $js, $matches)) {
|
||||
$json = $matches[1];
|
||||
$data = json_decode($json, true);
|
||||
|
||||
$metadata->title = $data['video_title'];
|
||||
$metadata->image = $data['image_url'];
|
||||
}
|
||||
|
||||
$metadata->tags = $crawler->filter('.video-detailed-info a:not(.add-btn-small)')->extract('_text');
|
||||
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user