예제 #1
0
 public static function parseUrl($url = '')
 {
     $url = trim($url);
     if ($url == '') {
         return false;
     }
     if (!Validator::isValidHttpUrl($url)) {
         return false;
     }
     $urlParts = parse_url($url);
     if (!$urlParts) {
         return false;
     }
     $domain = $urlParts['host'];
     $path = $urlParts['path'];
     $source = MangaSourceList::getInstance()->getSourceByDomain($domain);
     if (!$source) {
         return false;
     }
     $sourceKey = $source['key'];
     $souceClassPrefix = $source['classPrefix'];
     $sourceClassName = "MangaSource{$souceClassPrefix}";
     $mangaData = false;
     if (class_exists($sourceClassName)) {
         $objSourceClass = new $sourceClassName();
         if (method_exists($objSourceClass, 'getMangaDataFromPath')) {
             $mangaData = $objSourceClass->getMangaDataFromPath($path);
         }
     }
     if (!$mangaData) {
         return false;
     }
     if (!isset($mangaData['slug']) || trim($mangaData['slug']) == '') {
         return false;
     }
     return array('source' => $sourceKey, 'slug' => $mangaData['slug'], 'chapter' => $mangaData['chapter']);
 }
 /**
  * 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'];
     }
 }
예제 #3
0
$objChapterTitles = ChapterTitles::getInstance(array('mangaInfo' => $mangaInfo));
# ========================================================
# Prepare manga status object. we be gonna need it!
# ========================================================
$mangaStatus = MangaStatus::getInstance(array('mangaInfo' => $mangaInfo));
# ========================================================
# get chapters list!
# ========================================================
$actionRequiringChapterFetch = array(ArgumentsList::ACTION_NEW_CHAPTERS, ArgumentsList::ACTION_SPECIFIC_CHAPTERS);
if (in_array($objArgumentsList->getAction(), $actionRequiringChapterFetch)) {
    consoleLinePurple("Updating chapters list from {$mangaInfo->getSource()} ...");
    /**
     * @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);
예제 #4
0
# By: anjan @ Nov 06, 2015 12:15 PM
# ====================================================================
# --slug
# ====================================================================
Console::text(__pad_space_right("--slug", $paramPadLength), 1);
$blockText = 'The manga slug or id by which the manga is identified on the source site. This is usually part of the mnaga chapters url page.' . "Example: " . Console::text("nisekoi", 0, ConsoleColors::COLOR_CYAN, true) . ' from ' . Console::text("http://www.mangapanda.com/nisekoi", 0, ConsoleColors::COLOR_CYAN, true);
Console::writeMultiline($blockText, MANGA_SCRAPPER_TAB_STR . $emptyPaddedStr, '', true);
# ====================================================================
# By: anjan @ Nov 06, 2015 12:15 PM
# ====================================================================
# --source
# ====================================================================
Console::text(__pad_space_right("--source", $paramPadLength), 1);
$blockText = 'Manga sources/sites to fetch data from. Supported sources: ';
$temp = [];
foreach (MangaSourceList::getInstance()->getAllowedSourceList() as $src_key => $src_data) {
    $temp[] = Console::text($src_key, 0, ConsoleColors::COLOR_CYAN, true);
}
$blockText .= join(', ', $temp);
Console::writeMultiline($blockText, MANGA_SCRAPPER_TAB_STR . $emptyPaddedStr, '', true);
# ====================================================================
# By: anjan @ Nov 06, 2015 12:15 PM
# ====================================================================
# --url
# ====================================================================
Console::text(__pad_space_right("--url", $paramPadLength), 1);
$blockText = 'Accepts an url to manga chapters list or a specific chapter. If a valid manga chapter list url is specified, then the source, and slug param is ignored. Also, if the url is for a chapter, in addition to source and slug, action and chapter-ids params are ignored as well.';
Console::writeMultiline($blockText, MANGA_SCRAPPER_TAB_STR . $emptyPaddedStr, '', true);
/*********************************************************************
 * By: Anjan @ Nov 06, 2015 5:13 PM
 *********************************************************************