From 233a54eb3ecaed65a9181ac698ad95556712704c Mon Sep 17 00:00:00 2001 From: shibafu Date: Tue, 20 Nov 2018 23:31:57 +0900 Subject: [PATCH] =?UTF-8?q?Iwara=E3=81=AE=E3=82=AB=E3=83=BC=E3=83=89?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #12 --- app/MetadataResolver/IwaraResolver.php | 57 +++++++++++++++++++++++ app/MetadataResolver/MetadataResolver.php | 1 + 2 files changed, 58 insertions(+) create mode 100644 app/MetadataResolver/IwaraResolver.php diff --git a/app/MetadataResolver/IwaraResolver.php b/app/MetadataResolver/IwaraResolver.php new file mode 100644 index 0000000..d1bd8b9 --- /dev/null +++ b/app/MetadataResolver/IwaraResolver.php @@ -0,0 +1,57 @@ +get($url); + if ($res->getStatusCode() === 200) { + $dom = new \DOMDocument(); + @$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8')); + $xpath = new \DOMXPath($dom); + + $metadata = new Metadata(); + + // find title + foreach ($xpath->query('//title') as $node) { + $content = $node->textContent; + if (!empty($content)) { + $metadata->title = $content; + break; + } + } + + // find thumbnail + foreach ($xpath->query('//*[@id="video-player"]') as $node) { + $poster = $node->getAttribute('poster'); + if (!empty($poster)) { + if (strpos($poster, '//') === 0) { + $poster = 'https:' . $poster; + } + $metadata->image = $poster; + break; + } + } + if (empty($metadata->image)) { + // YouTube embedded? + foreach ($xpath->query('//div[@class="embedded-video"]//iframe') as $node) { + $src = $node->getAttribute('src'); + if (preg_match('~youtube\.com/embed/(\S+)\?~', $src, $matches) !== -1) { + $youtubeId = $matches[1]; + $iwaraThumbUrl = 'https://i.iwara.tv/sites/default/files/styles/thumbnail/public/video_embed_field_thumbnails/youtube/' . $youtubeId . '.jpg'; + + $metadata->image = $iwaraThumbUrl; + break; + } + } + } + + return $metadata; + } else { + throw new \RuntimeException("{$res->getStatusCode()}: $url"); + } + } +} \ No newline at end of file diff --git a/app/MetadataResolver/MetadataResolver.php b/app/MetadataResolver/MetadataResolver.php index fdb7061..80325e5 100644 --- a/app/MetadataResolver/MetadataResolver.php +++ b/app/MetadataResolver/MetadataResolver.php @@ -10,6 +10,7 @@ class MetadataResolver implements Resolver '~komiflo\.com(/#!)?/comics/(\\d+)~' => KomifloResolver::class, '~www\.melonbooks\.co\.jp/detail/detail\.php~' => MelonbooksResolver::class, '~ec\.toranoana\.jp/tora_r/ec/item/.*~' => ToranoanaResolver::class, + '~iwara\.tv/videos/.*~' => IwaraResolver::class, '/.*/' => OGPResolver::class ];