From eecace33bd66bf5e84901867006bfc0679a35b39 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 9 Sep 2019 10:58:20 +0900 Subject: [PATCH 1/3] =?UTF-8?q?2=E6=A1=81=E4=BB=A5=E4=B8=8A=E3=81=AEcdn?= =?UTF-8?q?=E3=81=AEURL=E3=81=AB=E5=AF=BE=E5=BF=9C=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E6=AD=A3=E8=A6=8F=E8=A1=A8?= =?UTF-8?q?=E7=8F=BE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Unit/MetadataResolver/XtubeResolverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/MetadataResolver/XtubeResolverTest.php b/tests/Unit/MetadataResolver/XtubeResolverTest.php index 828ec3f..3704766 100644 --- a/tests/Unit/MetadataResolver/XtubeResolverTest.php +++ b/tests/Unit/MetadataResolver/XtubeResolverTest.php @@ -27,7 +27,7 @@ class XtubeResolverTest extends TestCase $metadata = $this->resolver->resolve('https://www.xtube.com/video-watch/homegrown-big-tits-18634762'); $this->assertEquals('Homegrown Big Tits', $metadata->title); $this->assertEquals('Dedicated to the fans of the beautiful amateur women with big natural tits. All user submitted - you can see big boob amateur hotties fucking and sucking as their tits bounce and sway.', $metadata->description); - $this->assertRegExp('~https://cdn\d-s-hw-e5\.xtube\.com/m=eSK08f/videos/201302/07/RF4Nk-S774-/240X180/1\.jpg~', $metadata->image); + $this->assertRegExp('~https://cdn\d+-s-hw-e5\.xtube\.com/m=eSK08f/videos/201302/07/RF4Nk-S774-/240X180/1\.jpg~', $metadata->image); $this->assertEquals(['bigtits', 'homeg'], $metadata->tags); } From 0f530099b429ceec2822a18492bab8f6acc8e859 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 9 Sep 2019 13:51:07 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=BF=E3=81=AE?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E6=96=B9=E6=B3=95=E3=82=92API=E3=81=8B?= =?UTF-8?q?=E3=82=89=E3=82=B9=E3=82=AF=E3=83=AC=E3=82=A4=E3=83=94=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit より多くのタグと高画質なサムネイルを取得するように変更 --- app/MetadataResolver/XtubeResolver.php | 21 +- .../MetadataResolver/XtubeResolverTest.php | 9 +- tests/fixture/Xtube/test.json | 1 - tests/fixture/Xtube/video.html | 2671 +++++++++++++++++ 4 files changed, 2690 insertions(+), 12 deletions(-) delete mode 100644 tests/fixture/Xtube/test.json create mode 100644 tests/fixture/Xtube/video.html diff --git a/app/MetadataResolver/XtubeResolver.php b/app/MetadataResolver/XtubeResolver.php index d56cce0..322ec20 100644 --- a/app/MetadataResolver/XtubeResolver.php +++ b/app/MetadataResolver/XtubeResolver.php @@ -3,6 +3,7 @@ namespace App\MetadataResolver; use GuzzleHttp\Client; +use Symfony\Component\DomCrawler\Crawler; class XtubeResolver implements Resolver { @@ -18,20 +19,24 @@ class XtubeResolver implements Resolver public function resolve(string $url): Metadata { - if (preg_match('~www\.xtube\.com/video-watch/.*-(\d+)$~', $url, $matches) !== 1) { + if (preg_match('~www\.xtube\.com/video-watch/.*-(\d+)$~', $url) !== 1) { throw new \RuntimeException("Unmatched URL Pattern: $url"); } - $videoid = $matches[1]; - $res = $this->client->get('https://www.xtube.com/webmaster/api/getvideobyid?video_id=' . $videoid); + $res = $this->client->get($url); if ($res->getStatusCode() === 200) { - $data = json_decode($res->getBody()->getContents(), true); + $html = (string) $res->getBody(); $metadata = new Metadata(); + $crawler = new Crawler($html); - $metadata->title = $data['title'] ?? ''; - $metadata->description = strip_tags(str_replace('\n', PHP_EOL, html_entity_decode($data['description'] ?? ''))); - $metadata->image = str_replace('eSuQ8f', 'eSK08f', $data['thumb'] ?? ''); // 300x169 to 300x210 - $metadata->tags = array_values(array_unique($data['tags'])); + // poster URL抽出 + $playerConfig = explode("\n", trim($crawler->filter('#playerWrapper script')->last()->text())); + preg_match('~https:\\\/\\\/cdn\d+-s-hw-e5\.xtube\.com\\\/m=(?P.{8})\\\/videos\\\/\d{6}\\\/\d{2}\\\/.{5}-.{4}-\\\/original\\\/\d+\.jpg~', $playerConfig[0], $matches); + $metadata->image = str_replace('\/', '/', $matches[0]); + + $metadata->title = trim($crawler->filter('.underPlayerRateForm h1')->text('')); + $metadata->description = trim($crawler->filter('.fullDescription ')->text('')); + $metadata->tags = $crawler->filter('.tagsCategories a')->extract('_text'); return $metadata; } else { diff --git a/tests/Unit/MetadataResolver/XtubeResolverTest.php b/tests/Unit/MetadataResolver/XtubeResolverTest.php index 3704766..859d3d9 100644 --- a/tests/Unit/MetadataResolver/XtubeResolverTest.php +++ b/tests/Unit/MetadataResolver/XtubeResolverTest.php @@ -20,15 +20,18 @@ class XtubeResolverTest extends TestCase public function test() { - $responseText = file_get_contents(__DIR__ . '/../../fixture/Xtube/test.json'); + $responseText = file_get_contents(__DIR__ . '/../../fixture/Xtube/video.html'); $this->createResolver(XtubeResolver::class, $responseText); $metadata = $this->resolver->resolve('https://www.xtube.com/video-watch/homegrown-big-tits-18634762'); $this->assertEquals('Homegrown Big Tits', $metadata->title); $this->assertEquals('Dedicated to the fans of the beautiful amateur women with big natural tits. All user submitted - you can see big boob amateur hotties fucking and sucking as their tits bounce and sway.', $metadata->description); - $this->assertRegExp('~https://cdn\d+-s-hw-e5\.xtube\.com/m=eSK08f/videos/201302/07/RF4Nk-S774-/240X180/1\.jpg~', $metadata->image); - $this->assertEquals(['bigtits', 'homeg'], $metadata->tags); + $this->assertRegExp('~https://cdn\d+-s-hw-e5\.xtube\.com/m=eaAaaEFb/videos/201302/07/RF4Nk-S774-/original/1\.jpg~', $metadata->image); + $this->assertEquals(['Amateur', 'Blowjob', 'Big Boobs', 'bigtits', 'homeg'], $metadata->tags); + if ($this->shouldUseMock()) { + $this->assertSame('https://www.xtube.com/video-watch/homegrown-big-tits-18634762', (string) $this->handler->getLastRequest()->getUri()); + } } public function testNotMatch() diff --git a/tests/fixture/Xtube/test.json b/tests/fixture/Xtube/test.json deleted file mode 100644 index ad7b553..0000000 --- a/tests/fixture/Xtube/test.json +++ /dev/null @@ -1 +0,0 @@ -{"duration":"180","views":3146,"video_id":"RF4Nk-S774-","rating":"4.000","ratings":"1","title":"Homegrown Big Tits","description":"Dedicated to the fans of the beautiful amateur women with big natural tits. All user submitted - you can see big boob amateur hotties fucking and sucking as their tits bounce and sway.","url":"https:\/\/www.xtube.com\/video-watch\/homegrown-big-tits-18634762","embedCode":"https:\/\/www.xtube.com\/video-watch\/embedded\/homegrown-big-tits-18634762","default_thumb":"https:\/\/cdn5-s-hw-e5.xtube.com\/m=eSuQ8f\/videos\/201302\/07\/RF4Nk-S774-\/240X180\/1.jpg","thumb":"https:\/\/cdn5-s-hw-e5.xtube.com\/m=eSuQ8f\/videos\/201302\/07\/RF4Nk-S774-\/240X180\/1.jpg","publish_date":"2013-02-07 17:41:10","tags":{"1396":"bigtits","472012":"homeg"},"thumbs":[{"width":300,"height":210,"src":"https:\/\/cdn4-s-hw-e5.xtube.com\/m=eSK08f\/videos\/201302\/07\/RF4Nk-S774-\/240X180\/1.jpg"},{"width":300,"height":210,"src":"https:\/\/cdn4-s-hw-e5.xtube.com\/m=eSK08f\/videos\/201302\/07\/RF4Nk-S774-\/240X180\/2.jpg"},{"width":300,"height":210,"src":"https:\/\/cdn10-s-hw-e5.xtube.com\/m=eSK08f\/videos\/201302\/07\/RF4Nk-S774-\/240X180\/3.jpg"}]} \ No newline at end of file diff --git a/tests/fixture/Xtube/video.html b/tests/fixture/Xtube/video.html new file mode 100644 index 0000000..ef4cbc5 --- /dev/null +++ b/tests/fixture/Xtube/video.html @@ -0,0 +1,2671 @@ + + + + + + + + + +Homegrown Big Tits | XTube Porn Video from Homegrown Big Tits + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ +
+
+ +
+
+ +
+
+
+ + + + +
+
+
+ +
+
+

+ Homegrown Big Tits

+
+
+ 3160 views + + added + 5 years ago +
+
+
+ + + + + + + + + +
+ + 80%(1 Votes) +
+
+
+
+ + + + + +
+
+ + +
+
+
+

Embed Video

+
+
+

Video iframe

+ +
+
+
+
+ + +
+

Related Videos

+
+ + +
+
+ +
+

Comments (0)

+ +
+ + + + + +
+ + + +
+
+ +
+ + + +
+
+
+ +
+ + +
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + From c0b76e522be3f71a1ec8e0106aa47bc66f223ea2 Mon Sep 17 00:00:00 2001 From: eai04191 Date: Mon, 9 Sep 2019 13:52:32 +0900 Subject: [PATCH 3/3] =?UTF-8?q?200=E3=81=A7=E3=81=AA=E3=81=8B=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4xxや5xxの場合は`\GuzzleHttp\Exception\BadResponseException`が発生するので、今まであったelseのところには到達しなかった --- app/MetadataResolver/XtubeResolver.php | 26 ++++++++----------- .../MetadataResolver/XtubeResolverTest.php | 9 ------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/app/MetadataResolver/XtubeResolver.php b/app/MetadataResolver/XtubeResolver.php index 322ec20..d2b3272 100644 --- a/app/MetadataResolver/XtubeResolver.php +++ b/app/MetadataResolver/XtubeResolver.php @@ -24,23 +24,19 @@ class XtubeResolver implements Resolver } $res = $this->client->get($url); - if ($res->getStatusCode() === 200) { - $html = (string) $res->getBody(); - $metadata = new Metadata(); - $crawler = new Crawler($html); + $html = (string) $res->getBody(); + $metadata = new Metadata(); + $crawler = new Crawler($html); - // poster URL抽出 - $playerConfig = explode("\n", trim($crawler->filter('#playerWrapper script')->last()->text())); - preg_match('~https:\\\/\\\/cdn\d+-s-hw-e5\.xtube\.com\\\/m=(?P.{8})\\\/videos\\\/\d{6}\\\/\d{2}\\\/.{5}-.{4}-\\\/original\\\/\d+\.jpg~', $playerConfig[0], $matches); - $metadata->image = str_replace('\/', '/', $matches[0]); + // poster URL抽出 + $playerConfig = explode("\n", trim($crawler->filter('#playerWrapper script')->last()->text())); + preg_match('~https:\\\/\\\/cdn\d+-s-hw-e5\.xtube\.com\\\/m=(?P.{8})\\\/videos\\\/\d{6}\\\/\d{2}\\\/.{5}-.{4}-\\\/original\\\/\d+\.jpg~', $playerConfig[0], $matches); + $metadata->image = str_replace('\/', '/', $matches[0]); - $metadata->title = trim($crawler->filter('.underPlayerRateForm h1')->text('')); - $metadata->description = trim($crawler->filter('.fullDescription ')->text('')); - $metadata->tags = $crawler->filter('.tagsCategories a')->extract('_text'); + $metadata->title = trim($crawler->filter('.underPlayerRateForm h1')->text('')); + $metadata->description = trim($crawler->filter('.fullDescription ')->text('')); + $metadata->tags = $crawler->filter('.tagsCategories a')->extract('_text'); - return $metadata; - } else { - throw new \RuntimeException("{$res->getStatusCode()}: $url"); - } + return $metadata; } } diff --git a/tests/Unit/MetadataResolver/XtubeResolverTest.php b/tests/Unit/MetadataResolver/XtubeResolverTest.php index 859d3d9..24b55ac 100644 --- a/tests/Unit/MetadataResolver/XtubeResolverTest.php +++ b/tests/Unit/MetadataResolver/XtubeResolverTest.php @@ -42,13 +42,4 @@ class XtubeResolverTest extends TestCase $this->createResolver(XtubeResolver::class, ''); $this->resolver->resolve('https://www.xtube.com/gallery/black-celebs-free-7686657'); } - - public function testNotOK() - { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('404: https://www.xtube.com/video-watch/notfound-404'); - - $this->createResolver(XtubeResolver::class, '', [], 404); - $this->resolver->resolve('https://www.xtube.com/video-watch/notfound-404'); - } }