Skip to content

Commit

Permalink
fixes #11 - can now handle eightmuses full collections
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymoulin committed Feb 18, 2018
1 parent 2938a3e commit 95c259d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION ?= 0.4.4
VERSION ?= 0.5.0
CACHE ?= --no-cache=1
FULLVERSION ?= ${VERSION}
archs ?= amd64 arm32v6 arm64v8 i386
Expand Down
58 changes: 42 additions & 16 deletions src/Driver/EightMuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class EightMuses extends \Yamete\DriverAbstract
{
private $aMatches = [];
private $aReturn = [];
const DOMAIN = '8muses.com';

public function canHandle()
Expand All @@ -18,26 +19,51 @@ public function canHandle()

public function getDownloadables()
{
$oRes = $this->getClient()->request('GET', $this->sUrl);
$aReturn = [];
$i = 0;
foreach ($this->getDomParser()->load((string)$oRes->getBody())->find('a.c-tile') as $oLink) {
$this->aReturn = [];
foreach ($this->getDomParser()->load($this->getBody($this->sUrl))->find('a.c-tile') as $oLink) {
/**
* @var \DOMElement $oLink
*/
$oParser = $this->getDomParser()
->load(
(string)$this->getClient()
->request('GET', 'https://www.' . self::DOMAIN . $oLink->getAttribute('href'))->getBody()
);
$sHost = $oParser->find('#imageHost')[0]->getAttribute('value');
$sName = $oParser->find('#imageName')[0]->getAttribute('value');
$sFilename = "https:$sHost/image/fl/$sName";
$sPath = $this->getFolder() . DIRECTORY_SEPARATOR
. str_pad($i++, 4, '0', STR_PAD_LEFT) . '-' . basename($sFilename);
$aReturn[$sPath] = $sFilename;
$sHref = 'https://www.' . self::DOMAIN . $oLink->getAttribute('href');
$oParser = $this->getDomParser()->load($this->getBody($sHref));
if (isset($oParser->find('#imageHost')[0])) {
$this->prepareLinks($oParser);
} else {
$oParser = $this->getDomParser()->load($this->getBody($sHref));
foreach ($oParser->find('a.c-tile') as $oLinkImg) {
/**
* @var \DOMElement $oLinkImg
*/
$sHref = 'https://www.' . self::DOMAIN . $oLinkImg->getAttribute('href');
$oParser = $this->getDomParser()->load($this->getBody($sHref));
if (isset($oParser->find('#imageHost')[0])) {
$this->prepareLinks($oParser);
}
}
}
}
return $aReturn;
return $this->aReturn;
}

/**
* Retrieve body for specified url
* @param string $sUrl
* @return string
* @throws
*/
private function getBody($sUrl)
{
return (string)$this->getClient()->request('GET', $sUrl)->getBody();
}

private function prepareLinks(\PHPHtmlParser\Dom $oParser)
{
$sHost = $oParser->find('#imageHost')[0]->getAttribute('value');
$sName = $oParser->find('#imageName')[0]->getAttribute('value');
$sFilename = "https:$sHost/image/fl/$sName";
$sPath = $this->getFolder() . DIRECTORY_SEPARATOR
. str_pad(count($this->aReturn) + 1, 4, '0', STR_PAD_LEFT) . '-' . basename($sFilename);
$this->aReturn[$sPath] = $sFilename;
}

private function getFolder()
Expand Down
9 changes: 9 additions & 0 deletions tests/Driver/EightMuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ public function testDownload()
$this->assertTrue($driver->canHandle());
$this->assertEquals(22, count($driver->getDownloadables()));
}

public function testDownloadSeries()
{
$url = 'https://www.8muses.com/comix/album/JAB-Comics/A-Model-Life';
$driver = new \Yamete\Driver\EightMuses();
$driver->setUrl($url);
$this->assertTrue($driver->canHandle());
$this->assertEquals(53, count($driver->getDownloadables()));
}
}

0 comments on commit 95c259d

Please sign in to comment.