From 03633440a63ac86bcd8108b8361f94712d69c56c Mon Sep 17 00:00:00 2001 From: eai04191 Date: Tue, 20 Aug 2019 20:23:02 +0900 Subject: [PATCH 1/2] =?UTF-8?q?jakeasmith/http=5Fbuild=5Furl=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + composer.lock | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2c46aed..3b89d39 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "doctrine/dbal": "^2.9", "fideloper/proxy": "~3.3", "guzzlehttp/guzzle": "^6.3", + "jakeasmith/http_build_url": "^1.0", "laravel/framework": "5.5.*", "laravel/tinker": "~1.0", "misd/linkify": "^1.1", diff --git a/composer.lock b/composer.lock index eaf81d3..fb352b4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "28abd730d4572663d10ae815393c73cd", + "content-hash": "b6dfb80c350a7276bb2513a1aeb3d602", "packages": [ { "name": "anhskohbo/no-captcha", @@ -806,6 +806,39 @@ ], "time": "2019-07-01T23:21:34+00:00" }, + { + "name": "jakeasmith/http_build_url", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/jakeasmith/http_build_url.git", + "reference": "93c273e77cb1edead0cf8bcf8cd2003428e74e37" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jakeasmith/http_build_url/zipball/93c273e77cb1edead0cf8bcf8cd2003428e74e37", + "reference": "93c273e77cb1edead0cf8bcf8cd2003428e74e37", + "shasum": "" + }, + "type": "library", + "autoload": { + "files": [ + "src/http_build_url.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jake A. Smith", + "email": "theman@jakeasmith.com" + } + ], + "description": "Provides functionality for http_build_url() to environments without pecl_http.", + "time": "2017-05-01T15:36:40+00:00" + }, { "name": "jakub-onderka/php-console-color", "version": "v0.2", From cdc6335a0687705b65f53eaba5ead73de1e7d77a Mon Sep 17 00:00:00 2001 From: eai04191 Date: Tue, 20 Aug 2019 23:07:15 +0900 Subject: [PATCH 2/2] =?UTF-8?q?HentaiFoundryResolver=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HentaiFoundryResolver.php | 56 +++ app/MetadataResolver/MetadataResolver.php | 1 + .../HentaiFoundryResolverTest.php | 36 ++ tests/fixture/HentaiFoundry/illust.html | 350 ++++++++++++++++++ 4 files changed, 443 insertions(+) create mode 100644 app/MetadataResolver/HentaiFoundryResolver.php create mode 100644 tests/Unit/MetadataResolver/HentaiFoundryResolverTest.php create mode 100644 tests/fixture/HentaiFoundry/illust.html diff --git a/app/MetadataResolver/HentaiFoundryResolver.php b/app/MetadataResolver/HentaiFoundryResolver.php new file mode 100644 index 0000000..87131a5 --- /dev/null +++ b/app/MetadataResolver/HentaiFoundryResolver.php @@ -0,0 +1,56 @@ +client = $client; + $this->ogpResolver = $ogpResolver; + } + + private function nbsp2space(string $string): string + { + return str_replace("\xc2\xa0", ' ', $string); + } + + private function br2nl(string $string): string + { + return str_replace('
', PHP_EOL, $string); + } + + public function resolve(string $url): Metadata + { + $res = $this->client->get( + http_build_url($url, ['query' => 'enterAgree=1']), + ['cookies' => new CookieJar()] + ); + + $metadata = new Metadata(); + $crawler = new Crawler((string) $res->getBody()); + + $author = $crawler->filter('#picBox .boxtitle a')->text(); + $description = trim(strip_tags($this->nbsp2space($this->br2nl($crawler->filter('.picDescript')->html())))); + + $metadata->title = $crawler->filter('#picBox .boxtitle .imageTitle')->text(); + $metadata->description = 'by ' . $author . PHP_EOL . $description; + $metadata->image = 'https:' . $crawler->filter('img[src^="//picture"]')->attr('src'); + $metadata->tags = $crawler->filter('a[rel="tag"]')->extract('_text'); + + return $metadata; + } +} diff --git a/app/MetadataResolver/MetadataResolver.php b/app/MetadataResolver/MetadataResolver.php index bb2ec08..e12f662 100644 --- a/app/MetadataResolver/MetadataResolver.php +++ b/app/MetadataResolver/MetadataResolver.php @@ -33,6 +33,7 @@ class MetadataResolver implements Resolver '~store\.steampowered\.com/app/\d+~' => SteamResolver::class, '~www\.xtube\.com/video-watch/.*-\d+$~'=> XtubeResolver::class, '~ss\.kb10uy\.org/posts/\d+$~' => Kb10uyShortStoryServerResolver::class, + '~www\.hentai-foundry\.com/pictures/user/.+/\d+/.+~'=> HentaiFoundryResolver::class, ]; public $mimeTypes = [ diff --git a/tests/Unit/MetadataResolver/HentaiFoundryResolverTest.php b/tests/Unit/MetadataResolver/HentaiFoundryResolverTest.php new file mode 100644 index 0000000..f781bb1 --- /dev/null +++ b/tests/Unit/MetadataResolver/HentaiFoundryResolverTest.php @@ -0,0 +1,36 @@ +shouldUseMock()) { + sleep(1); + } + } + + public function test() + { + $responseText = file_get_contents(__DIR__ . '/../../fixture/HentaiFoundry/illust.html'); + + $this->createResolver(HentaiFoundryResolver::class, $responseText); + + $metadata = $this->resolver->resolve('https://www.hentai-foundry.com/pictures/user/DevilHS/723498/Witchcraft'); + $this->assertSame('Witchcraft', $metadata->title); + $this->assertSame('by DevilHS' . PHP_EOL . 'gift for Liru', $metadata->description); + $this->assertEquals(['witch', 'futa'], $metadata->tags); + $this->assertSame('https://pictures.hentai-foundry.com/d/DevilHS/723498/DevilHS-723498-Witchcraft.png', $metadata->image); + if ($this->shouldUseMock()) { + $this->assertSame('https://www.hentai-foundry.com/pictures/user/DevilHS/723498/Witchcraft?enterAgree=1', (string) $this->handler->getLastRequest()->getUri()); + } + } +} diff --git a/tests/fixture/HentaiFoundry/illust.html b/tests/fixture/HentaiFoundry/illust.html new file mode 100644 index 0000000..fc5b11c --- /dev/null +++ b/tests/fixture/HentaiFoundry/illust.html @@ -0,0 +1,350 @@ + + + + + + + + + + + + + + + + + + + +Witchcraft by DevilHS - Hentai Foundry + + + + + + + + + + + + + + +
+ + + + + +
+
+ Username   + Password   + +
+ Remember +   Register   + |   Forgot your password? +
+
+
+ + +
+

Witchcraft

+

+ + +
+ + + +
+

Witchcraft

+
Witchcraft by DevilHS
+
+
+Witchcraft by DevilHS
+
+
+

Description

+
Description
+
+
+DevilHS
gift for Liru
+
+

General Info

+
General Info
+
+
+
+
+ + + + + + + +
Ratings
NSxTg
Comments 11
Category +Original » Futanari (Dickgirls) Media Digital drawing or painting
Date Submitted Time Taken
Views 20597 Reference
Favorites... 876 Keywords ,
Vote Score 649 License Berne Convention
+
+

Comments

+
Comments (11)
+
+
+

You are not authorized to comment here. Your must be registered and logged in to comment

+

Kessandra on August 15, 2019, 8:21:56 AM

+
Kessandra on
+
+
+
KessandraLooks like some beautiful magic is going on. 
+
+

TrueInsanity on July 28, 2019, 4:34:52 AM

+
TrueInsanity on
+
+
+
TrueInsanityOh hell yes
+
+

Kaze26 on July 27, 2019, 5:23:29 AM

+
Kaze26 on
+
+
+
Kaze26Spectacular
+
+

QuarterLife on July 25, 2019, 6:39:08 PM

+
QuarterLife on
+
+
+
QuarterLifeI'm curious as to what she's casting, is it to help her last longer or is it why she has a cock and balls?
+
+Either way it's a good picture, good job, nice tight.
+
+

DevilHS on July 25, 2019, 10:59:26 PM

+
DevilHS on
+
+
+
DevilHSShe casted herself a magic dick.
+
+

QuarterLife on July 26, 2019, 12:00:08 AM

+
QuarterLife on
+
+
+
QuarterLifeAh alright, not just a regular dick, but a magic dick, looks like a good dick too. :D
+
+

XSUBREADERX on July 25, 2019, 9:59:58 PM

+
XSUBREADERX on
+
+
+
XSUBREADERXVery Nice!
+
+

AceSR on July 25, 2019, 6:41:45 PM

+
AceSR on
+
+
+
AceSRNice gift
+
+

FloridasSonShines on July 25, 2019, 2:47:00 PM

+
FloridasSonShines on
+
+
+
FloridasSonShinesAwesome!
+
+

Kreegan on July 25, 2019, 12:39:04 PM

+
Kreegan on
+
+
+
KreeganGreat :D
+
+
+
+
+
+
+ +
+
Site Copyright © 2006-2019 All Rights Reserved
Site design by Sticky
+
Art and stories Copyright their artists/writers
+Series & Characters Copyright their respective creators/studios
+

All characters depicted are 18 or older, even if otherwise specified.

+ + ipv6 ready + +
+
+
+ + +
+
+ +
+ + + + \ No newline at end of file