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!\"");
     }
 }
 public function getImagePageUrls()
 {
     $chapterUrl = $this->_chapterInfo->getUrl();
     if (!$chapterUrl) {
         consoleLineError('Chapter url not defined!', 2);
     }
     $content = Url::curlFetch($chapterUrl);
     if (!$content) {
         consoleLineError("Unable to fetch content from " . $chapterUrl, 2);
     }
     $html = '';
     if (preg_match('%(<select\\s+class="wid60"[^>]+>.*?</select>)%simx', $content, $regs)) {
         $html = $regs[1];
     }
     if (!$html) {
         consoleLineError('Unable to fetch chapter image urls from: ' . $chapterUrl);
         exit;
     }
     try {
         $xml = simplexml_load_string($html);
         $imageInfo = array();
         foreach ($xml->option as $o) {
             $number = (string) $o;
             $url = (string) $o->attributes()['value'];
             $imageInfo[] = new ImageInfo(array('number' => $number, 'pageUrl' => $url));
         }
         return $imageInfo;
     } catch (Exception $ex) {
         consoleLineError('Unable to fetch chapter image urls from: ' . $chapterUrl);
         exit;
     }
 }
 private function __construct($data = array())
 {
     if (isset($data['mangaInfo']) && $data['mangaInfo'] instanceof MangaInfo) {
         $this->_mangaInfo = $data['mangaInfo'];
     } else {
         consoleLineError('MangaInfo object not set!');
         exit;
     }
 }
 /**
  * parses the argument and prepares a simple associative array
  *
  * @param array $argsData
  *
  * @return array
  */
 public static function parseAndPrepareArgumentsArray($argsData = array())
 {
     $argsData = is_array($argsData) ? $argsData : array();
     if (empty($argsData)) {
         return array();
     }
     $data = array();
     foreach ($argsData as $ad) {
         $ad = trim($ad);
         if ($ad == '' || strpos($ad, '--') !== 0) {
             consoleLineError("Invalid param: " . $ad, 2);
             exit;
         }
         $temp = explode('=', $ad, 2);
         $argName = isset($temp[0]) ? trim($temp[0]) : '';
         $argValue = isset($temp[1]) ? trim($temp[1]) : '';
         $data[str_replace('--', '', $argName)] = $argValue;
     }
     return $data;
 }
 public function getImagePageUrls()
 {
     $chapterUrl = $this->_chapterInfo->getUrl();
     if (!$chapterUrl) {
         consoleLineError('Chapter url not defined!', 2);
     }
     $content = Url::curlFetch($chapterUrl);
     if (!$content) {
         consoleLineError("Unable to fetch content from " . $chapterUrl, 2);
     }
     $result = array();
     preg_match_all($this->getImageLinkRegex(), $content, $result, PREG_PATTERN_ORDER);
     $urls = $result[1];
     $numbers = $result[2];
     $imageInfo = array();
     if (is_array($urls) && is_array($numbers)) {
         $loopStart = 0;
         $loopEnd = count($urls);
         for ($i = $loopStart; $i < $loopEnd; $i += 1) {
             $imageInfo[] = new ImageInfo(array('number' => $numbers[$i], 'pageUrl' => 'http://www.mangapanda.com' . $urls[$i]));
         }
     }
     return $imageInfo;
 }
 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);
 }
Exemple #7
0
     $imageUrlList = $objChapterImages->getImagePageUrls();
     consoleLinePurple("Found images: " . count($imageUrlList));
     $classImageScrapper = $classPrefix . 'ImageScrapper';
     if (class_exists($classImageScrapper)) {
         /**
          * @var ImageScrapper $objImageScrapper
          */
         $objImageScrapper = new $classImageScrapper(['mangaInfo' => $mangaInfo, 'chapterInfo' => $chapter, 'images' => $imageUrlList]);
         $objImageScrapper->fetchImages();
     } else {
         consoleLineError("Class not found: " . $classImageScrapper, 2);
         consoleLineInfo('');
         exit;
     }
 } else {
     consoleLineError("Class not found: " . $classChapterImages, 2);
     consoleLineInfo('');
     exit;
 }
 $fetchedCount += 1;
 // Did we reach chapters count limit? break then!
 if ($chaptersCountToFetch > 0 && $fetchedCount >= $chaptersCountToFetch) {
     break;
 }
 /**
  * @var ArgumentsList $objArgumentsList
  */
 global $objArgumentsList;
 $delay = $objArgumentsList->getChapterDelay();
 if ($delay) {
     consoleLineInfo("---------------------------------------");
 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;
 }
Exemple #9
0
<?php

/**
 * Created by PhpStorm.
 * User: anjan
 * Date: 11/17/15
 * Time: 6:37 PM
 */
consoleLinePurple('Recreating .cbr files ...');
consoleLineBlue("CBR Dir: " . $mangaInfo->getCbrDirPath());
if ($objArgumentsList->shouldKeepCbrBackup()) {
    $cbrBackupDir = $mangaInfo->getOutputDir() . 'cbr-backup/' . date('Y-m-d-H-i') . '/';
    consoleLineInfo('Backing up old .cbr files to ' . $cbrBackupDir);
    if (!is_dir($cbrBackupDir)) {
        if (!mkdir($cbrBackupDir, 0777, true)) {
            consoleLineError("Unable to create cbr backup dir [{$cbrBackupDir}] ");
            exit;
        }
    }
    exec("cp " . $mangaInfo->getCbrDirPath() . "/*.cbr {$cbrBackupDir}/");
} else {
    consoleLineInfo('Removing .existing cbr files ...');
}
exec("rm " . $mangaInfo->getCbrDirPath() . "/*.cbr");
consoleLineInfo('Done');
$chapters = $mangaStatus->getAllChaptersList();
$objChaptersTitles = ChapterTitles::getInstance();
/**
 * @var ChapterInfo $c
 */
foreach ($chapters as &$c) {
 /**
  * Parses argument data
  *
  * @param array $data
  */
 private function parseData($data = array())
 {
     // show help if requested and exit!
     if (isset($data['help'])) {
         require_once MANGA_ROOT_DIR . 'includes/templates/help/index.php';
         exit;
     }
     $data = is_array($data) ? $data : array();
     // image delay
     $this->setImageDelay(Input::array_value($data, 'image-delay', '', 'trim'));
     // chapter delay
     $this->setChapterDelay(Input::array_value($data, 'chapter-delay', '', 'trim'));
     // url
     if (isset($data['url'])) {
         $url = trim($data['url']);
         if ($url == '') {
             consoleLineError("Url parameter cannot be empty!");
             exit;
         }
         $parsedData = UrlParser::parseUrl($url);
         if (!$parsedData) {
             consoleLineError("Provided url is not is not valid!");
             exit;
         } else {
             $data['source'] = $parsedData['source'];
             $data['slug'] = $parsedData['slug'];
             $chapter = trim($parsedData['chapter']);
             if ($chapter != '') {
                 $data['chapter-ids'] = $chapter;
                 $data['action'] = self::ACTION_SPECIFIC_CHAPTERS;
             }
         }
     }
     // check for valid params
     $dataKeys = array_keys($data);
     $diff = array_diff($dataKeys, $this->_allowed_param_names);
     if (count($diff) > 0) {
         consoleLineError("Invalid params: " . join(',', $diff), 2);
         exit;
     }
     $this->_argumentsList = $data;
     // action
     $action = Input::array_value($data, 'action', '', 'trim');
     if ($action == '') {
         $action = self::ACTION_NEW_CHAPTERS;
     }
     if (!$this->isValidAction($action)) {
         $this->displayInvalidActionMessage(TRUE);
     } else {
         $this->_action = $action;
         if ($this->_action == self::ACTION_SPECIFIC_CHAPTERS) {
             $chapterIds = Input::array_value($data, 'chapter-ids', '', 'trim');
             if ($chapterIds == '') {
                 consoleLineError('One or more chapter ids are required when action is "' . self::ACTION_SPECIFIC_CHAPTERS . '"');
                 Console::emptyLines();
                 exit;
             }
         }
     }
     // source
     $source = Input::array_value($data, 'source', MangaSourceList::SOUCE_MANGAPANDA, 'trim');
     if (MangaSourceList::getInstance()->isValidSource($source)) {
         $this->_source = $source;
     } else {
         MangaSourceList::getInstance()->displayInvalidMangaSourceMessage(TRUE);
     }
     // slug
     $slug = Input::array_value($data, 'slug', '', 'trim');
     if ($slug == '') {
         consoleLineError('Manga slug is required!', 2);
         consoleLinePurple('Example: --slug=nisekoi', 2);
         Console::writeMultiline('Slug usualy means the SEO friendly name of the manga. But it can be different for different manga sources.The slug is part of the manga chapters list url.');
         consoleLineInfo('');
         exit;
     }
     $this->_mangaSlug = $slug;
     // name
     $name = Input::array_value($data, 'name', '', 'trim');
     if ($name == '') {
         $name = $this->_mangaSlug;
     }
     $this->_mangaName = $name;
     // Output dir
     $output_dir = Input::array_value($data, 'output-dir', '', 'trim');
     if ($output_dir == '') {
         $output_dir = './manga/' . $this->_source . '/' . $this->_mangaSlug . '/';
     }
     if (!is_dir($output_dir)) {
         if (!mkdir($output_dir, 0777, TRUE)) {
             consoleLineError("Unable to create output dir: " . $output_dir, 2);
             consoleLineInfo('');
             exit;
         }
     } else {
         $tmpFile = tempnam($output_dir, 'mst-');
         if (!fopen($tmpFile, 'w')) {
             consoleLineError("Output dir is not writeable!" . $output_dir, 2);
             consoleLineInfo('');
             exit;
         } else {
             @unlink($tmpFile);
         }
     }
     $this->_output_dir = $output_dir;
     # chapters count
     $chaptersCount = Input::array_value_as_int($data, 'chapters-count', 0);
     if ($chaptersCount < 0) {
         $chaptersCount = 0;
     }
     $this->_chapters_count = $chaptersCount;
     # chapter ids
     $chapterIds = Input::array_value($data, 'chapter-ids', '', 'trim');
     if ($chapterIds == '') {
         $this->_chapter_ids = array();
     } else {
         // is it a file?
         if (is_readable($chapterIds)) {
             $chapterIds = trim(file_get_contents($chapterIds));
         }
         $chapterIds = explode(',', $chapterIds);
         $chapterIds = array_map('trim', $chapterIds);
         // check for ranges
         $chapterRangesIds = array();
         foreach ($chapterIds as $k => $v) {
             $cid = $chapterIds[$k];
             if (preg_match('/([0-9.]+)\\s*-\\s*([0-9.]+)/im', $cid, $regs)) {
                 $chapterRangesIds[$k] = array('start' => $regs[1], 'end' => $regs[2]);
             }
         }
         if (count($chapterRangesIds) > 0) {
             // unset the range format entries first, as we are gonna get real
             // chapter ids from that range next
             foreach ($chapterRangesIds as $k => $rangeData) {
                 unset($chapterIds[$k]);
             }
             // get available chapters from ranges
             foreach ($chapterRangesIds as $k => $rangeData) {
                 $start = $rangeData['start'];
                 $end = $rangeData['end'];
                 for ($i = $start; $i <= $end; $i += 1) {
                     $chapterIds[] = $i;
                 }
             }
         }
         asort($chapterIds);
         $chapterIds = array_unique($chapterIds);
         $this->_chapter_ids = $chapterIds;
     }
     # create cbr
     $createCbr = isset($data['create-cbr']) ? $data['create-cbr'] : TRUE;
     $result = strtolower(exec('type -p rar'));
     if (strpos($result, 'not found')) {
         consoleLineError('rar doesnt seem to be installed in the system!');
         $createCbr = FALSE;
     }
     $this->_create_cbr = $createCbr;
     if (!$this->_create_cbr) {
         consoleLineError('.cbr files will not be created!');
     }
     # no cbr backup
     if ($this->_action == self::ACTION_RECREATE_CBR) {
         $this->_no_cbr_backup = isset($data['no-cbr-backup']) && $data['no-cbr-backup'];
     }
 }
 public function getImageUrl($pageUrl = '')
 {
     $pageUrl = trim($pageUrl);
     if ($pageUrl == '') {
         consoleLineError("Iamge page url is empty!");
         exit;
     }
     $content = Url::curlFetch($pageUrl);
     $regs = array();
     if (preg_match('/<img.*?id="img".*?src="([^"]+)".*?>/sim', $content, $regs)) {
         $result = $regs[1];
     } else {
         $result = "";
     }
     return trim($result);
 }
Exemple #12
0
     * @var ChaptersList $objChaptersList
     */
    $objChaptersList = NULL;
    $classPrefix = MangaSourceList::getInstance()->getSourceClassPrefix($mangaInfo->getSource());
    $classChaptersList = "{$classPrefix}ChaptersList";
    if (class_exists($classChaptersList)) {
        $objChaptersList = $classChaptersList::getInstance(array('mangaInfo' => $mangaInfo));
    }
    if ($objChaptersList) {
        $chapterrsList = $objChaptersList->getChapters();
        if (!is_array($chapterrsList) || empty($chapterrsList)) {
            consoleLineError('Unable to fetch chapters list!');
            exit;
        }
    } else {
        consoleLineError('Unsupported manga host!');
        exit;
    }
    consoleLineInfo("Found chapters: " . count($chapterrsList), 1);
}
switch ($objArgumentsList->getAction()) {
    case ArgumentsList::ACTION_NEW_CHAPTERS:
        require_once MANGA_ROOT_DIR . 'includes/templates/actions/fetch-new-chapters/index.php';
        break;
    case ArgumentsList::ACTION_SPECIFIC_CHAPTERS:
        require_once MANGA_ROOT_DIR . 'includes/templates/actions/fetch-specific-chapters/index.php';
        break;
    case ArgumentsList::ACTION_EXPORT_CHAPTER_TITLES:
        $objChapterTitles->dumpChapterTitles();
        break;
    case ArgumentsList::ACTION_SHOW_CHAPTERS:
 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 #14
0
<?php

# ========================================================
# Check for new chapters
# ========================================================
$completedChaptersList = $mangaStatus->getCompletedChaptersList();
consoleLineInfo("Completed chapters count: " . count($completedChaptersList), 1);
$newChapters = array_diff_key($chapterrsList, $completedChaptersList);
if (!empty($newChapters)) {
    consoleLinePurple("New chapters to fetch: " . count($newChapters));
} else {
    consoleLineError("No new chapters to fetch!");
}
if (!empty($newChapters)) {
    $chaptersCountToFetch = $objArgumentsList->getChaptersCount();
    if ($chaptersCountToFetch > 0) {
        if ($chaptersCountToFetch > 1) {
            consoleLinePurple("Fetching only first {$chaptersCountToFetch} chapters!");
        } else {
            consoleLinePurple("Fetching only first chapter!");
        }
    }
    // Fetch chapters ...
    require_once MANGA_ROOT_DIR . 'includes/templates/actions/__common/chapters/fetch.php';
}
# ========================================================
# Update status data
# ========================================================
$mangaStatus->updateChaptersTotalCount(count($chapterrsList));
$mangaStatus->updateAllChaptersList($chapterrsList);
Exemple #15
0
/**
 * Created by PhpStorm.
 * User: anjan
 * Date: 11/5/15
 * Time: 8:33 AM
 */
$specificChapterIds = $objArgumentsList->getChapterIds();
Console::seperatorLine();
consoleLinePurple("Fetching specific chapter(s): " . join(',', $specificChapterIds));
Console::seperatorLine();
consoleLineBlue('Checking for valid chapter ids ...');
$newChapters = array();
foreach ($specificChapterIds as $chapterId) {
    if (!isset($chapterrsList[$chapterId])) {
        consoleLineError("Invalid chapter id: " . $chapterId);
        exit;
    } else {
        $newChapters[$chapterId] = $chapterrsList[$chapterId];
    }
}
if (!empty($newChapters)) {
    $chaptersCountToFetch = $objArgumentsList->getChaptersCount();
    if ($chaptersCountToFetch > 0) {
        if ($chaptersCountToFetch > 1) {
            consoleLinePurple("Fetching only first {$chaptersCountToFetch} chapters!");
        } else {
            consoleLinePurple("Fetching only first chapter!");
        }
    }
    // Fetch chapters ...