Skip to content

Commit

Permalink
adds mangaeden.com
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymoulin committed Mar 5, 2020
1 parent e1552b4 commit afc79c9
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,6 @@ Here's is the list of supported sites for now:
* wiemanga.com
* chaptermanga.com
* fanfox.net
* mangaeden.com

You must pass the URL to the album for the program to download it!
57 changes: 57 additions & 0 deletions src/Driver/MangaEdenCom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Yamete\Driver;

class MangaEdenCom extends \Yamete\DriverAbstract
{
private $aMatches = [];
const DOMAIN = 'mangaeden.com';

public function canHandle(): bool
{
return (bool)preg_match(
'~^https?://www\.(' . strtr(self::DOMAIN, ['.' => '\.']) . ')/[a-z]{2}/[^/]+/(?<album>[^/]+)/$~',
$this->sUrl,
$this->aMatches
);
}

/**
* @return array|string[]
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getDownloadables(): array
{
/**
* @var \iterator $oChapters
* @var \PHPHtmlParser\Dom\AbstractNode[] $aChapters
* @var \PHPHtmlParser\Dom\AbstractNode $oPage
* @var \PHPHtmlParser\Dom\AbstractNode $oImg
*/
$oRes = $this->getClient()->request('GET', $this->sUrl);
$oChapters = $this->getDomParser()->load((string)$oRes->getBody())->find('a.chapterLink');
$aChapters = iterator_to_array($oChapters);
$aReturn = [];
krsort($aChapters);
$index = 0;
foreach ($aChapters as $oChapter) {
$sLink = 'https://' . self::DOMAIN . $oChapter->getAttribute('href');
$oRes = $this->getClient()->request('GET', $sLink);
if (!preg_match('~var pages = (\[[^\]]+\]);~', (string)$oRes->getBody(), $aMatches)) {
continue;
}
foreach (\GuzzleHttp\json_decode($aMatches[1], true) as $aInfo) {
$sFilename = 'http:' . $aInfo['fs'];
$sBasename = $this->getFolder() . DIRECTORY_SEPARATOR . str_pad($index++, 5, '0', STR_PAD_LEFT)
. '-' . basename($sFilename);
$aReturn[$sBasename] = $sFilename;
}
}
return $aReturn;
}

private function getFolder(): string
{
return implode(DIRECTORY_SEPARATOR, [self::DOMAIN, $this->aMatches['album']]);
}
}
19 changes: 19 additions & 0 deletions tests/Driver/MangaEdenCom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace YameteTests\Driver;


class MangaEdenCom extends \PHPUnit\Framework\TestCase
{
/**
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function testDownload()
{
$url = 'https://www.mangaeden.com/en/en-manga/ase-to-sekken/';
$driver = new \Yamete\Driver\MangaEdenCom();
$driver->setUrl($url);
$this->assertTrue($driver->canHandle());
$this->assertEquals(226, count($driver->getDownloadables()));
}
}

0 comments on commit afc79c9

Please sign in to comment.