Loggingの削除・メソッドの説明をまともに
This commit is contained in:
parent
a645cb497f
commit
b0a7504691
@ -2,19 +2,31 @@
|
||||
|
||||
namespace App\MetadataResolver;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PixivResolver implements Resolver
|
||||
{
|
||||
public function thumbnail_to_master_url(string $url):string {
|
||||
// 最大長辺 1200 の画像に変換
|
||||
|
||||
/**
|
||||
* サムネイル画像 URL から最大長辺 1200px の画像 URL に変換する
|
||||
*
|
||||
* @param string サムネイル画像 URL
|
||||
* @return string 1200px の画像 URL
|
||||
*/
|
||||
public function thumbnail_to_master_url(string $url):string
|
||||
{
|
||||
$url = str_replace("/c/128x128", "", $url);
|
||||
$url = str_replace("square1200.jpg", "master1200.jpg", $url);
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function proxize(string $url):string {
|
||||
// pixiv.cat のプロキシ URL に変換する HUGE THANKS TO PIXIV.CAT!
|
||||
/**
|
||||
* 直リン可能な pixiv.cat のプロキシ URL に変換する
|
||||
* HUGE THANKS TO PIXIV.CAT!
|
||||
*
|
||||
* @param string i.pximg URL
|
||||
* @return string i.pixiv.cat URL
|
||||
*/
|
||||
public function proxize(string $url):string
|
||||
{
|
||||
$url = str_replace("i.pximg.net", "i.pixiv.cat", $url);
|
||||
return $url;
|
||||
}
|
||||
@ -30,9 +42,7 @@ class PixivResolver implements Resolver
|
||||
$page = $match[1];
|
||||
|
||||
// 未ログインでは漫画ページを開けないため、URL を作品ページに変換する
|
||||
Log::debug($url);
|
||||
$url = str_replace("mode=manga_big", "mode=medium", $url);
|
||||
Log::debug($url);
|
||||
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$res = $client->get($url);
|
||||
@ -42,22 +52,20 @@ class PixivResolver implements Resolver
|
||||
|
||||
preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}_p0_square1200\.jpg~", $res->getBody(), $match);
|
||||
$illust_thumbnail_url = $match[0];
|
||||
Log::debug($illust_thumbnail_url);
|
||||
|
||||
$illust_url = $this->thumbnail_to_master_url($illust_thumbnail_url);
|
||||
Log::debug($illust_url);
|
||||
|
||||
// 指定ページに変換
|
||||
$illust_url = str_replace("p0_master", "p{$page}_master", $illust_url);
|
||||
Log::debug($illust_url);
|
||||
|
||||
$metadata->image = $this->proxize($illust_url);;
|
||||
$metadata->image = $this->proxize($illust_url);
|
||||
;
|
||||
|
||||
return $metadata;
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$res = $client->get($url);
|
||||
if ($res->getStatusCode() === 200) {
|
||||
@ -68,13 +76,14 @@ class PixivResolver implements Resolver
|
||||
if (strpos($metadata->image, "pixiv_logo.gif") || strpos($metadata->image, "pictures.jpg")) {
|
||||
|
||||
// 作品ページの場合のみ対応
|
||||
if(strpos(parse_url($url)["query"], "mode=medium")){
|
||||
if (strpos(parse_url($url)["query"], "mode=medium")) {
|
||||
preg_match("~https://i\.pximg\.net/c/128x128/img-master/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/{$illust_id}(_p0)?_square1200\.jpg~", $res->getBody(), $match);
|
||||
$illust_thumbnail_url = $match[0];
|
||||
|
||||
$illust_url = $this->thumbnail_to_master_url($illust_thumbnail_url);
|
||||
|
||||
$metadata->image = $this->proxize($illust_url);;
|
||||
$metadata->image = $this->proxize($illust_url);
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +91,6 @@ class PixivResolver implements Resolver
|
||||
} else {
|
||||
throw new \RuntimeException("{$res->getStatusCode()}: $url");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user