This commit is contained in:
shibafu
2019-01-15 00:05:01 +09:00
parent a2f797cbbe
commit faf0755ebd
44 changed files with 87 additions and 68 deletions

View File

@@ -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");
}
}
}
}

View File

@@ -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];

View File

@@ -54,4 +54,4 @@ class IwaraResolver implements Resolver
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
}
}
}

View File

@@ -27,4 +27,4 @@ class KomifloResolver implements Resolver
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
}
}
}

View File

@@ -26,4 +26,4 @@ class MelonbooksResolver implements Resolver
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
}
}
}

View File

@@ -7,4 +7,4 @@ class Metadata
public $title = '';
public $description = '';
public $image = '';
}
}

View File

@@ -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.');
}
}
}

View File

@@ -21,4 +21,4 @@ class NicoSeigaResolver implements Resolver
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
}
}
}

View File

@@ -37,4 +37,4 @@ class NijieResolver implements Resolver
throw new \RuntimeException("{$res->getStatusCode()}: $url");
}
}
}
}

View File

@@ -41,6 +41,7 @@ class OGPResolver implements Resolver
}
}
}
return '';
}
}
}

View File

@@ -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);
}

View File

@@ -5,4 +5,4 @@ namespace App\MetadataResolver;
interface Resolver
{
public function resolve(string $url): Metadata;
}
}

View File

@@ -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");
}
}
}
}