URL置換を削除 タグを追加

なんかもともと入っているurlが十分大きいので置換する必要がないことに気が付きました
This commit is contained in:
eai04191 2019-09-10 22:59:18 +09:00
parent db39ee35c2
commit dc8a70291d
3 changed files with 11 additions and 10 deletions

View File

@ -27,12 +27,12 @@ class DeviantArtResolver implements Resolver
$data = json_decode($res->getBody()->getContents(), true);
$metadata = new Metadata();
// アスペクト比を保ったまま、縦か横が最大1024pxになる画像を取得する。
// Ref: https://support.wixmp.com/en/article/image-service-3835799
// 作成されていない画像が参照されると403を返すようなので、サイト内で使用されている1024pxにした。
$metadata->image = preg_replace('~/v1/fit/w_\d+,h_\d+(?:,q_\d+),strp/.+\.(jpg|png|webp|gif)~', '/v1/fit/w_1024,h_1024,strp/image.jpg', $data['thumbnail_url']);
$metadata->title = $data['title'] ?? '';
$metadata->description = 'By ' . $data['author_name'];
$metadata->image = $data['url'];
if (isset($data['tags'])) {
$metadata->tags = explode(', ', $data['tags']);
}
return $metadata;
}

View File

@ -24,12 +24,13 @@ class DeviantArtResolverTest extends TestCase
$this->createResolver(DeviantArtResolver::class, $responseText);
$metadata = $this->resolver->resolve('https://www.deviantart.com/rasbii/art/backstage-620617246');
$this->assertSame('backstage', $metadata->title);
$this->assertSame('By Rasbii', $metadata->description);
$this->assertStringStartsWith('https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/bee96c7a-4956-44a4-81aa-7587cf0b85d1/da9hzby-b9640ac3-1815-4c77-9410-0d4882a20e25.png/v1/fit/w_1024,h_1024,strp/image.jpg?token=', $metadata->image);
$metadata = $this->resolver->resolve('https://www.deviantart.com/gatanii69/art/R-15-mabel-and-will-update-686016962');
$this->assertSame('R-15 mabel and will update', $metadata->title);
$this->assertSame('By gatanii69', $metadata->description);
$this->assertStringStartsWith('https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/6854f36d-8010-4cd0-9d62-0cf9b7829764/dbcfq2q-d78c9f6e-dced-4e5c-a345-2a1bfd5d7620.jpg', $metadata->image);
$this->assertSame(['nsfw', 'reversefalls', 'gravityfalls', 'gravityfallsfanart', 'mabelpines', 'billcipher', 'reversemabel', 'willcipher', 'reversebill', 'reversebillcipher', 'mawill'], $metadata->tags);
if ($this->shouldUseMock()) {
$this->assertSame('https://backend.deviantart.com/oembed?url=https://www.deviantart.com/rasbii/art/backstage-620617246', (string) $this->handler->getLastRequest()->getUri());
$this->assertSame('https://backend.deviantart.com/oembed?url=https://www.deviantart.com/gatanii69/art/R-15-mabel-and-will-update-686016962', (string) $this->handler->getLastRequest()->getUri());
}
}
}

View File

@ -1 +1 @@
{"version":"1.0","type":"photo","title":"backstage","category":"Anthro > Digital Media > Drawings > Animals","url":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/bee96c7a-4956-44a4-81aa-7587cf0b85d1\/da9hzby-b9640ac3-1815-4c77-9410-0d4882a20e25.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcL2JlZTk2YzdhLTQ5NTYtNDRhNC04MWFhLTc1ODdjZjBiODVkMVwvZGE5aHpieS1iOTY0MGFjMy0xODE1LTRjNzctOTQxMC0wZDQ4ODJhMjBlMjUucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.KUvvn12bGl06p0Nwe7tl7Hxa_JoDRhwh2M3H_1JFJ2Q","author_name":"Rasbii","author_url":"https:\/\/www.deviantart.com\/rasbii","provider_name":"DeviantArt","provider_url":"https:\/\/www.deviantart.com","safety":"adult","pubdate":"2016-07-09T13:12:42-07:00","community":{"statistics":{"_attributes":{"views":6708,"favorites":127,"comments":39,"downloads":0}}},"rating":"adult","license":{"_attributes":{"type":"text\/html","href":"http:\/\/creativecommons.org\/licenses\/by-nc-nd\/3.0\/"},"0":"Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License"},"width":"689","height":"619","imagetype":"png","thumbnail_url":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/bee96c7a-4956-44a4-81aa-7587cf0b85d1\/da9hzby-b9640ac3-1815-4c77-9410-0d4882a20e25.png\/v1\/fit\/w_300,h_619,q_70,strp\/backstage_by_rasbii_da9hzby-300w.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9NjE5IiwicGF0aCI6IlwvZlwvYmVlOTZjN2EtNDk1Ni00NGE0LTgxYWEtNzU4N2NmMGI4NWQxXC9kYTloemJ5LWI5NjQwYWMzLTE4MTUtNGM3Ny05NDEwLTBkNDg4MmEyMGUyNS5wbmciLCJ3aWR0aCI6Ijw9Njg5In1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmltYWdlLm9wZXJhdGlvbnMiXX0.XM8Nf4BYEWI5FJEtk9EOYNtQGOlznuuBbs9wFrLOYUw","thumbnail_width":300,"thumbnail_height":270,"thumbnail_url_150":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/bee96c7a-4956-44a4-81aa-7587cf0b85d1\/da9hzby-b9640ac3-1815-4c77-9410-0d4882a20e25.png\/v1\/fit\/w_150,h_150,q_70,strp\/backstage_by_rasbii_da9hzby-150.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9NjE5IiwicGF0aCI6IlwvZlwvYmVlOTZjN2EtNDk1Ni00NGE0LTgxYWEtNzU4N2NmMGI4NWQxXC9kYTloemJ5LWI5NjQwYWMzLTE4MTUtNGM3Ny05NDEwLTBkNDg4MmEyMGUyNS5wbmciLCJ3aWR0aCI6Ijw9Njg5In1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmltYWdlLm9wZXJhdGlvbnMiXX0.XM8Nf4BYEWI5FJEtk9EOYNtQGOlznuuBbs9wFrLOYUw","thumbnail_url_200h":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/bee96c7a-4956-44a4-81aa-7587cf0b85d1\/da9hzby-b9640ac3-1815-4c77-9410-0d4882a20e25.png\/v1\/fill\/w_223,h_200,q_70,strp\/backstage_by_rasbii_da9hzby-200h.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9NjE5IiwicGF0aCI6IlwvZlwvYmVlOTZjN2EtNDk1Ni00NGE0LTgxYWEtNzU4N2NmMGI4NWQxXC9kYTloemJ5LWI5NjQwYWMzLTE4MTUtNGM3Ny05NDEwLTBkNDg4MmEyMGUyNS5wbmciLCJ3aWR0aCI6Ijw9Njg5In1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmltYWdlLm9wZXJhdGlvbnMiXX0.XM8Nf4BYEWI5FJEtk9EOYNtQGOlznuuBbs9wFrLOYUw","thumbnail_width_200h":223,"thumbnail_height_200h":200}
{"version":"1.0","type":"photo","title":"R-15 mabel and will update","category":"Fan Art > Manga & Anime > Digital > Movies & TV","url":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/6854f36d-8010-4cd0-9d62-0cf9b7829764\/dbcfq2q-d78c9f6e-dced-4e5c-a345-2a1bfd5d7620.jpg\/v1\/fill\/w_1193,h_670,q_70,strp\/r_15_mabel_and_will_update_by_gatanii69_dbcfq2q-pre.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9ODQyIiwicGF0aCI6IlwvZlwvNjg1NGYzNmQtODAxMC00Y2QwLTlkNjItMGNmOWI3ODI5NzY0XC9kYmNmcTJxLWQ3OGM5ZjZlLWRjZWQtNGU1Yy1hMzQ1LTJhMWJmZDVkNzYyMC5qcGciLCJ3aWR0aCI6Ijw9MTUwMCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.6Vj946U_q31oKJDfyUfJGCj-kufd47zV1RjCtN_qtVc","author_name":"gatanii69","author_url":"https:\/\/www.deviantart.com\/gatanii69","provider_name":"DeviantArt","provider_url":"https:\/\/www.deviantart.com","safety":"adult","pubdate":"2017-06-12T06:08:10-07:00","community":{"statistics":{"_attributes":{"views":8322,"favorites":405,"comments":56,"downloads":50}}},"rating":"adult","tags":"nsfw, reversefalls, gravityfalls, gravityfallsfanart, mabelpines, billcipher, reversemabel, willcipher, reversebill, reversebillcipher, mawill","copyright":{"_attributes":{"url":"https:\/\/www.deviantart.com\/gatanii69","year":"2017","entity":"gatanii69"}},"width":1193,"height":670,"imagetype":"","thumbnail_url":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/6854f36d-8010-4cd0-9d62-0cf9b7829764\/dbcfq2q-d78c9f6e-dced-4e5c-a345-2a1bfd5d7620.jpg\/v1\/fit\/w_300,h_842,q_70,strp\/r_15_mabel_and_will_update_by_gatanii69_dbcfq2q-300w.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9ODQyIiwicGF0aCI6IlwvZlwvNjg1NGYzNmQtODAxMC00Y2QwLTlkNjItMGNmOWI3ODI5NzY0XC9kYmNmcTJxLWQ3OGM5ZjZlLWRjZWQtNGU1Yy1hMzQ1LTJhMWJmZDVkNzYyMC5qcGciLCJ3aWR0aCI6Ijw9MTUwMCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.6Vj946U_q31oKJDfyUfJGCj-kufd47zV1RjCtN_qtVc","thumbnail_width":300,"thumbnail_height":168,"thumbnail_url_150":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/6854f36d-8010-4cd0-9d62-0cf9b7829764\/dbcfq2q-d78c9f6e-dced-4e5c-a345-2a1bfd5d7620.jpg\/v1\/fit\/w_150,h_150,q_70,strp\/r_15_mabel_and_will_update_by_gatanii69_dbcfq2q-150.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9ODQyIiwicGF0aCI6IlwvZlwvNjg1NGYzNmQtODAxMC00Y2QwLTlkNjItMGNmOWI3ODI5NzY0XC9kYmNmcTJxLWQ3OGM5ZjZlLWRjZWQtNGU1Yy1hMzQ1LTJhMWJmZDVkNzYyMC5qcGciLCJ3aWR0aCI6Ijw9MTUwMCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.6Vj946U_q31oKJDfyUfJGCj-kufd47zV1RjCtN_qtVc","thumbnail_url_200h":"https:\/\/images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com\/f\/6854f36d-8010-4cd0-9d62-0cf9b7829764\/dbcfq2q-d78c9f6e-dced-4e5c-a345-2a1bfd5d7620.jpg\/v1\/fill\/w_300,h_168,q_70,strp\/r_15_mabel_and_will_update_by_gatanii69_dbcfq2q-200h.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9ODQyIiwicGF0aCI6IlwvZlwvNjg1NGYzNmQtODAxMC00Y2QwLTlkNjItMGNmOWI3ODI5NzY0XC9kYmNmcTJxLWQ3OGM5ZjZlLWRjZWQtNGU1Yy1hMzQ1LTJhMWJmZDVkNzYyMC5qcGciLCJ3aWR0aCI6Ijw9MTUwMCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.6Vj946U_q31oKJDfyUfJGCj-kufd47zV1RjCtN_qtVc","thumbnail_width_200h":300,"thumbnail_height_200h":168}