Reformat
This commit is contained in:
@@ -12,9 +12,10 @@ class DLsiteResolver implements Resolver
|
||||
$ogpResolver = new OGPResolver();
|
||||
$metadata = $ogpResolver->parse($res->getBody());
|
||||
$metadata->image = str_replace("img_sam.jpg", "img_main.jpg", $metadata->image);
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ class FantiaResolver implements Resolver
|
||||
$ogpUrl = $node->getAttribute('content');
|
||||
|
||||
// 投稿に画像がない場合(ogp.jpgでない場合)のみ大きい画像に変換する
|
||||
if($ogpUrl != "http://fantia.jp/images/ogp.jpg"){
|
||||
if ($ogpUrl != "http://fantia.jp/images/ogp.jpg") {
|
||||
preg_match("~https://fantia\.s3\.amazonaws\.com/uploads/post/file/{$postId}/ogp_(.*?)\.(jpg|png)~", $ogpUrl, $match);
|
||||
$uuid = $match[1];
|
||||
$extension = $match[2];
|
||||
|
@@ -54,4 +54,4 @@ class IwaraResolver implements Resolver
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -27,4 +27,4 @@ class KomifloResolver implements Resolver
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,4 +26,4 @@ class MelonbooksResolver implements Resolver
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,4 +7,4 @@ class Metadata
|
||||
public $title = '';
|
||||
public $description = '';
|
||||
public $image = '';
|
||||
}
|
||||
}
|
||||
|
@@ -21,11 +21,12 @@ class MetadataResolver implements Resolver
|
||||
{
|
||||
foreach ($this->rules as $pattern => $class) {
|
||||
if (preg_match($pattern, $url) === 1) {
|
||||
$resolver = new $class;
|
||||
$resolver = new $class();
|
||||
|
||||
return $resolver->resolve($url);
|
||||
}
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException('URL not matched.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,4 +21,4 @@ class NicoSeigaResolver implements Resolver
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,4 +37,4 @@ class NijieResolver implements Resolver
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -41,6 +41,7 @@ class OGPResolver implements Resolver
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,17 +4,17 @@ namespace App\MetadataResolver;
|
||||
|
||||
class PixivResolver implements Resolver
|
||||
{
|
||||
|
||||
/**
|
||||
* サムネイル画像 URL から最大長辺 1200px の画像 URL に変換する
|
||||
*
|
||||
* @param string $thumbnailUrl サムネイル画像 URL
|
||||
* @return string 1200px の画像 URL
|
||||
*/
|
||||
public function thumbnailToMasterUrl(string $thumbnailUrl):string
|
||||
public function thumbnailToMasterUrl(string $thumbnailUrl): string
|
||||
{
|
||||
$temp = str_replace("/c/128x128", "", $thumbnailUrl);
|
||||
$largeUrl = str_replace("square1200.jpg", "master1200.jpg", $temp);
|
||||
|
||||
return $largeUrl;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class PixivResolver implements Resolver
|
||||
* @param string $pixivUrl i.pximg URL
|
||||
* @return string i.pixiv.cat URL
|
||||
*/
|
||||
public function proxize(string $pixivUrl):string
|
||||
public function proxize(string $pixivUrl): string
|
||||
{
|
||||
return str_replace("i.pximg.net", "i.pixiv.cat", $pixivUrl);
|
||||
}
|
||||
|
@@ -5,4 +5,4 @@ namespace App\MetadataResolver;
|
||||
interface Resolver
|
||||
{
|
||||
public function resolve(string $url): Metadata;
|
||||
}
|
||||
}
|
||||
|
@@ -14,9 +14,10 @@ class ToranoanaResolver implements Resolver
|
||||
$res = $client->get($url, ['cookies' => $cookieJar]);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
$ogpResolver = new OGPResolver();
|
||||
|
||||
return $ogpResolver->parse($res->getBody());
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user