diff --git a/app/MetadataResolver/MetadataResolver.php b/app/MetadataResolver/MetadataResolver.php index 8d25294..937c7f1 100644 --- a/app/MetadataResolver/MetadataResolver.php +++ b/app/MetadataResolver/MetadataResolver.php @@ -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 = [ diff --git a/app/MetadataResolver/PornHubResolver.php b/app/MetadataResolver/PornHubResolver.php new file mode 100644 index 0000000..4ff46a6 --- /dev/null +++ b/app/MetadataResolver/PornHubResolver.php @@ -0,0 +1,55 @@ +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"); + } + } +}