# ======================================================== $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)); # ======================================================== # 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)); }
/** * 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!"); } }
public function showChapters() { $allChapters = MangaStatus::getInstance()->getAllChaptersList(); /** * @var ChapterInfo $c */ foreach ($allChapters as $c) { consoleLineInfo($c->getNumber(true) . ' : ' . $c->getTitle()); } }