/**
  * @param array $data
  *
  * @return ArgumentsList
  */
 public static function getInstance($data = array())
 {
     if (self::$instance === NULL) {
         self::$instance = new self($data);
     }
     return self::$instance;
 }
Example #2
0
/**
 * Created by PhpStorm.
 * User: anjan
 * 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));
# ========================================================
 /**
  * Fetch images
  */
 public function fetchImages()
 {
     if (!is_array($this->_images) || count($this->_images) == 0) {
         consoleLineError('No image to fetch!');
     }
     $chapterImageDir = $this->_mangaInfo->getOutputDir() . 'images/' . $this->_chapterInfo->getNumber() . '/';
     if (!is_dir($chapterImageDir)) {
         if (!mkdir($chapterImageDir, 0777, true)) {
             consoleLineError("Unable to create chapter image dir!");
             exit;
         }
     }
     $totalImages = count($this->_images);
     $totalFetched = 0;
     /**
      * @var ImageInfo $imgInfo
      */
     foreach ($this->_images as $imgInfo) {
         if (!$imgInfo instanceof ImageInfo) {
             consoleLineError("Incorrect image info!");
             exit;
         }
         $imgFileName = $this->_mangaInfo->getSlug() . '-' . str_pad($this->_chapterInfo->getNumber(), 6, '0', STR_PAD_LEFT) . '-' . str_pad($imgInfo->getNumber(), 3, '0', STR_PAD_LEFT) . '.jpg';
         $destImagePath = $chapterImageDir . $imgFileName;
         /* Kinda for backward compatibility */
         $imgFileName1 = $imgInfo->getNumber() . '.jpg';
         $destImagePath1 = $chapterImageDir . $imgFileName1;
         if (file_exists($destImagePath1)) {
             copy($destImagePath1, $destImagePath);
             unlink($destImagePath1);
         }
         if (file_exists($destImagePath)) {
             $totalFetched += 1;
             consoleLineBlue("[{$totalFetched}/{$totalImages}] " . $destImagePath);
             continue;
         }
         $imageUrl = $this->getImageUrl($imgInfo->getPageUrl());
         if ($imageUrl == '') {
             consoleLineError($destImagePath);
             continue;
         }
         $imageData = Url::curlFetch($imageUrl);
         if (!$imageData) {
             consoleLineError($destImagePath);
             continue;
         } else {
             $totalFetched += 1;
             consoleLineSuccess("[{$totalFetched}/{$totalImages}] " . $destImagePath);
             file_put_contents($destImagePath, $imageData);
         }
     }
     if ($totalFetched == $totalImages) {
         consoleLinePurple("Images fetched: {$totalFetched}/{$totalImages}");
     } else {
         consoleLineError("Images fetched: {$totalFetched}/{$totalImages}");
     }
     if ($totalImages == $totalFetched) {
         consoleLinePurple('Chapter completely fetched!');
         $mangaStatus = MangaStatus::getInstance();
         consoleLinePurple("Chapter [" . $this->_chapterInfo->getTitle() . "] is now set as completed!");
         if (ArgumentsList::getInstance()->shouldCreateCbr()) {
             /* Create CBR */
             $cbrCreator = new CbrCreator(array('mangaInfo' => $this->_mangaInfo, 'chapterInfo' => $this->_chapterInfo));
             $cbrCreator->setPrintRarOutput(false);
             $cbrCreator->createCbr();
         }
         $completedChapters = $mangaStatus->getCompletedChaptersList();
         $completedChapters[$this->_chapterInfo->getNumber()] = $this->_chapterInfo;
         $mangaStatus->updateCompletedChaptersList($completedChapters);
     } else {
         $mangaStatus = MangaStatus::getInstance();
         $partialChapters = $mangaStatus->getPartialChaptersList();
         $partialChapters[$this->_chapterInfo->getNumber()] = $this->_chapterInfo;
         $mangaStatus->updatePartialChaptersList($partialChapters);
         consoleLineBlue('Chapter completed partially!');
         consoleLineBlue("Chapter " . $this->_chapterInfo->getTitle() . " is set as partially completed!");
     }
 }
Example #4
0
$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
 *********************************************************************
 * Available actions
 *********************************************************************/
Console::emptyLines(1);
consoleLinePurple('List of supported actions -', 2);
$actionKeyLengths = array();
foreach (ArgumentsList::getActionList() as $key => $data) {
    $actionKeyLengths[] = strlen($key);
}
$maxkeyLen = max($actionKeyLengths) + 2 * strlen(MANGA_SCRAPPER_TAB_STR);
foreach (ArgumentsList::getActionList() as $key => $data) {
    Console::text(__pad_space_right(MANGA_SCRAPPER_TAB_STR . $key . MANGA_SCRAPPER_TAB_STR, $maxkeyLen), 0, ConsoleColors::COLOR_CYAN);
    Console::writeMultiline($data['desc'] . ($data['default'] ? Console::text(' [default]', 0, ConsoleColors::COLOR_RED, true) : ''), __pad_space_right('', $maxkeyLen), '', true);
}
Console::emptyLines(1);