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 getChapters($url = '')
 {
     $chapters_url = $this->_mangaInfo->getUrl();
     if ($chapters_url == '') {
         return false;
     }
     $content = Url::curlFetch($chapters_url);
     if (!$content) {
         return false;
     }
     $chapterListFragments = $this->_getLists($content);
     if (!$chapterListFragments) {
         consoleLineError('Unable to fetch chapters info from: ' . $url);
         exit;
     }
     $chapters = array();
     foreach ($chapterListFragments as $cf) {
         $chapterInfo = $this->_getChapterInfo($cf);
         if (!$chapterInfo) {
             consoleLineError('Unable to fetch chapters info from: ' . $url);
             exit;
         }
         $chapters[$chapterInfo['number']] = new ChapterInfo($chapterInfo);
     }
     return $chapters;
 }
 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);
 }
 public function dumpChapterTitles()
 {
     $allChapters = MangaStatus::getInstance()->getAllChaptersList();
     $csvPath = $this->_mangaInfo->getOutputDir() . 'chapter-titles.' . $this->_mangaInfo->getSource() . '.' . date('Y-m-d_H-i') . '.csv';
     $f = fopen($csvPath, 'w');
     if ($f) {
         /**
          * @var ChapterInfo $c
          */
         foreach ($allChapters as $c) {
             fputcsv($f, array($c->getNumber(), $c->getTitle()));
         }
         fclose($f);
         consoleLinePurple("Titles exported to " . $csvPath);
     } else {
         consoleLineError("Unable to create file " . $csvPath);
         exit;
     }
 }
Exemple #6
0
 * Date: 10/19/15
 * Time: 2:19 PM
 */
$startTime = time();
require_once 'config.php';
ini_set('display_errors', TRUE);
error_reporting(E_ALL);
Console::emptyLines(1);
# ========================================================
# Parse and prepare CLI arguments
# ========================================================
$objArgumentsList = ArgumentsList::getInstance(ArgumentParser::prepareCliArguments());
# ========================================================
# Prepare managa info instance ...
# ========================================================
$mangaInfo = MangaInfo::getInstance(array('source' => $objArgumentsList->getSource(), 'name' => $objArgumentsList->getMangaName(), 'slug' => $objArgumentsList->getMangaSlug(), 'url' => MangaSourceList::getInstance()->generateMangaChaptersUrl($objArgumentsList->getSource(), array('slug' => $objArgumentsList->getMangaSlug())), 'output_dir' => $objArgumentsList->getOutputDir()));
Console::seperatorLine();
consoleLineInfo('Strating at: ' . date('M d, Y h:i a', $startTime));
Console::seperatorLine();
consoleLineInfo('Fetching chapters for: ' . $mangaInfo->getName());
consoleLineInfo('Manga Url: ' . $mangaInfo->getUrl());
Console::seperatorLine();
# ========================================================
# Do we have chapter titles list already?
# ========================================================
$objChapterTitles = ChapterTitles::getInstance(array('mangaInfo' => $mangaInfo));
# ========================================================
# Prepare manga status object. we be gonna need it!
# ========================================================
$mangaStatus = MangaStatus::getInstance(array('mangaInfo' => $mangaInfo));
# ========================================================