예제 #1
0
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) {
    $title = trim($objChaptersTitles->getChapterTitle($c->getNumber()));
    if ($title) {
        $c->setTitle($title);
    }
    $cbrCreator = new CbrCreator(array('mangaInfo' => $mangaInfo, 'chapterInfo' => $c));
    $cbrCreator->setPrintRarOutput(false);
    $cbrCreator->createCbr();
}
$mangaStatus->updateAllChaptersList($chapters);
 /**
  * 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!");
     }
 }