/** * Gets chapter info * * @param string $listHtml * * @return array|bool */ private function _getChapterInfo($listHtml = '') { try { $chapterInfo = array('mangaInfo' => $this->_mangaInfo); $xml = @simplexml_load_string($listHtml); if ($xml && $xml->count() >= 1) { $children = $xml->children(); $info = $children[0]; $a = $info->a; if ($a) { $url = (string) $a->attributes()['href']; $chapterInfo['url'] = $url; $slug = $this->_mangaInfo->getSlug(); $parts = explode($slug, $url); if (count($parts) > 1) { $chapter = trim($parts[1], '/'); $chapterInfo['number'] = $chapter; $title = trim((string) $info); if ($title == '') { $title = $this->_mangaInfo->getName() . ' ' . $chapter; } $chapterInfo['title'] = $title; } } } else { consoleLineError('Unable to parse chapter info!'); exit; } return $chapterInfo; } catch (Exception $ex) { consoleLineError($ex->getMessage()); exit; } }
function getChapters($url = '') { $chapters_url = $this->_mangaInfo->getUrl(); if ($chapters_url == '') { return false; } $content = Url::curlFetch($chapters_url); if (!$content) { return false; } $slug = $this->_mangaInfo->getSlug(); preg_match_all('%<a.*?href="(/' . $slug . '/[^"]+)".*?>(.*?)</a>%sim', $content, $result, PREG_PATTERN_ORDER); $urls = $result[1]; $titles = $result[2]; $chapters = array(); $objChapterTitles = ChapterTitles::getInstance(); for ($i = 0; $i < count($urls); $i += 1) { $url = $urls[$i]; if (preg_match('%^/' . $slug . '/(.*?)$%sim', $url, $regs)) { $chapter_id = $regs[1]; $existingTitle = $objChapterTitles->getChapterTitle($chapter_id); $title = $titles[$i]; if ($existingTitle != '') { $title = $existingTitle; } $c = new ChapterInfo(['number' => $chapter_id, 'url' => 'http://www.mangapanda.com' . $url, 'title' => $title, 'mangaInfo' => $this->_mangaInfo]); $chapters[$chapter_id] = $c; } } ksort($chapters, SORT_NUMERIC); return $chapters; }
public function createCbr() { $chapterImageDir = $this->_mangaInfo->getOutputDir() . 'images/' . $this->_chapterInfo->getNumber() . '/'; if (!is_dir($chapterImageDir)) { consoleLineError("Chapter image dir {$chapterImageDir} not found!"); exit; } $cbrDirPath = $this->_mangaInfo->getCbrDirPath(); if (!is_dir($cbrDirPath)) { consoleLineError("Cbr dir {$cbrDirPath} not found!"); exit; } $cNum = $this->_chapterInfo->getNumber(); $cTitle = $this->_chapterInfo->getTitle(); $mSlug = $this->_mangaInfo->getSlug(); $cbrFileName = '[' . $mSlug . '-' . str_pad($cNum, 6, '0', STR_PAD_LEFT) . '] - ' . Sanitization::stripNonwordCharachters($cTitle, '-', 'lower') . '.cbr'; $shellCommand = "rar a \"{$cbrDirPath}{$cbrFileName}\" {$chapterImageDir}*.jpg"; $this->_chapterInfo->setCbrFileName($cbrFileName); if ($this->shouldPrintRarOutput()) { consoleLineInfo(shell_exec($shellCommand)); } else { shell_exec($shellCommand); } consoleLinePurple("Created CBR file: " . $cbrFileName); if (file_exists($cbrDirPath . $cbrFileName)) { //shell_exec("notify-send --hint int:transient:1 -u low -t 2000 \".cbr created\" \"CBR file {$cbrFileName} created!\""); } }
function __construct($data = array()) { if (!isset($data['mangaInfo']) || !$data['mangaInfo'] instanceof MangaInfo) { consoleLineError('ChapterInfo object requires a MangaInfo object!'); } $this->_mangaInfo = $data['mangaInfo']; $this->_number = Input::array_value($data, 'number', '', 'trim'); if ($this->_number == '') { consoleLineError('Chpater number is required!'); exit; } $this->_url = Input::array_value($data, 'url', '', 'trim'); if ($this->_url == '') { consoleLineError('Chapter url si required!'); exit; } $this->_title = Input::array_value($data, 'title', '', 'trim'); if ($this->_title == '') { consoleLineError('Chapter title is required!'); exit; } $this->_title_safe = Sanitization::stripNonwordCharachters($this->_title, '-', 'lower'); $this->_cbr_file_name = sprintf("[%s-%s] %s.cbr", $this->_mangaInfo->getSlug(), $this->_number, $this->_title_safe); }