/** * 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!"); } }
/** * 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)); # ========================================================