/**
  * 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!");
     }
 }
Exemple #2
0
<?php

/**
 * Created by PhpStorm.
 * User: anjan
 * Date: 11/17/15
 * Time: 6:37 PM
 */
consoleLinePurple('Recreating .cbr files ...');
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) {
Exemple #3
0
<?php

/**
 * Created by PhpStorm.
 * User: anjan
 * Date: 11/5/15
 * Time: 8:33 AM
 */
$specificChapterIds = $objArgumentsList->getChapterIds();
Console::seperatorLine();
consoleLinePurple("Fetching specific chapter(s): " . join(',', $specificChapterIds));
Console::seperatorLine();
consoleLineBlue('Checking for valid chapter ids ...');
$newChapters = array();
foreach ($specificChapterIds as $chapterId) {
    if (!isset($chapterrsList[$chapterId])) {
        consoleLineError("Invalid chapter id: " . $chapterId);
        exit;
    } else {
        $newChapters[$chapterId] = $chapterrsList[$chapterId];
    }
}
if (!empty($newChapters)) {
    $chaptersCountToFetch = $objArgumentsList->getChaptersCount();
    if ($chaptersCountToFetch > 0) {
        if ($chaptersCountToFetch > 1) {
            consoleLinePurple("Fetching only first {$chaptersCountToFetch} chapters!");
        } else {
            consoleLinePurple("Fetching only first chapter!");
        }
    }