FC2ContentsResolver OGP以上の情報が取れなくなったため削除

This commit is contained in:
Irie Aoi 2020-12-11 02:31:55 +09:00
parent a667767858
commit c73141c1d3
5 changed files with 0 additions and 625 deletions

View File

@ -1,40 +0,0 @@
<?php
namespace App\MetadataResolver;
use GuzzleHttp\Client;
class FC2ContentsResolver implements Resolver
{
/**
* @var Client
*/
private $client;
/**
* @var OGPResolver
*/
private $ogpResolver;
public function __construct(Client $client, OGPResolver $ogpResolver)
{
$this->client = $client;
$this->ogpResolver = $ogpResolver;
}
public function resolve(string $url): Metadata
{
$res = $this->client->get($url);
$metadata = $this->ogpResolver->parse($res->getBody());
$dom = new \DOMDocument();
@$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8'));
$xpath = new \DOMXPath($dom);
$thumbnailNode = $xpath->query('//*[@class="main_thum_img"]/a')->item(0);
if ($thumbnailNode) {
$metadata->image = preg_replace('~^http:~', 'https:', $thumbnailNode->getAttribute('href'));
}
return $metadata;
}
}

View File

@ -29,7 +29,6 @@ class MetadataResolver implements Resolver
'~\.syosetu\.com/n\d+[a-z]+~' => NarouResolver::class,
'~ci-en\.(jp|net|dlsite\.com)/creator/\d+/article/\d+~' => CienResolver::class,
'~www\.plurk\.com\/p\/.*~' => PlurkResolver::class,
'~(adult\.)?contents\.fc2\.com\/article_search\.php\?id=\d+~' => FC2ContentsResolver::class,
'~store\.steampowered\.com/app/\d+~' => SteamResolver::class,
'~www\.xtube\.com/video-watch/.*-\d+$~'=> XtubeResolver::class,
'~ss\.kb10uy\.org/posts/\d+$~' => Kb10uyShortStoryServerResolver::class,

View File

@ -1,50 +0,0 @@
<?php
namespace Tests\Unit\MetadataResolver;
use App\MetadataResolver\FC2ContentsResolver;
use Tests\TestCase;
class FC2ContentsResolverTest extends TestCase
{
use CreateMockedResolver;
public function setUp(): void
{
parent::setUp();
if (!$this->shouldUseMock()) {
sleep(1);
}
}
public function testAdult()
{
$responseText = $this->fetchSnapshot(__DIR__ . '/../../fixture/FC2Contents/adult.html');
$this->createResolver(FC2ContentsResolver::class, $responseText);
$metadata = $this->resolver->resolve('https://adult.contents.fc2.com/article_search.php?id=401545');
$this->assertEquals('個人撮影「ぱいずりオアトリート♡」Jカップ魔女っ子の連挟射しても続けちゃうパイズリ', $metadata->title);
$this->assertEquals('個人撮影「ぱいずりオアトリート♡」Jカップ魔女っ子の連挟射しても続けちゃうパイズリ - イベントコスチュームということもあり、大ボリュームだった前回、前々回の パイズリ役cupメイド と ナースパイズリを超え 今回さらに超ボリューム&超密度の内容になってます! -------- …', $metadata->description);
$this->assertEquals('https://storage2000.contents.fc2.com/file/104/10362633/1477676255.72.png', $metadata->image);
if ($this->shouldUseMock()) {
$this->assertSame('https://adult.contents.fc2.com/article_search.php?id=401545', (string) $this->handler->getLastRequest()->getUri());
}
}
public function testGeneral()
{
$responseText = $this->fetchSnapshot(__DIR__ . '/../../fixture/FC2Contents/general.html');
$this->createResolver(FC2ContentsResolver::class, $responseText);
$metadata = $this->resolver->resolve('https://contents.fc2.com/article_search.php?id=336610');
$this->assertEquals('ゆかいなどうぶつたち ~オオカミ・キツネ・タヌキ~', $metadata->title);
$this->assertEquals('ゆかいなどうぶつたち ~オオカミ・キツネ・タヌキ~ - 今回のおともだちは、オオカミ・キツネ・タヌキだよ。地球上に住んでいるたくさんのおともだち、みんなにどんどん紹介するからたのしみにしてね!', $metadata->description);
$this->assertEquals('https://storage6000.contents.fc2.com/file/300/29917555/1519118184.65.jpg', $metadata->image);
if ($this->shouldUseMock()) {
$this->assertSame('https://contents.fc2.com/article_search.php?id=336610', (string) $this->handler->getLastRequest()->getUri());
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long