From 6460cfca37681ad0a65bf9f14baf44c75869231b Mon Sep 17 00:00:00 2001 From: Junior Date: Mon, 16 Feb 2026 14:34:42 -0500 Subject: [PATCH] Only extract comic if it isn't already extracted (muuuuch faster for large comics) --- ajax/showcomic.php | 67 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/ajax/showcomic.php b/ajax/showcomic.php index adb8a07..30d8ec6 100644 --- a/ajax/showcomic.php +++ b/ajax/showcomic.php @@ -47,41 +47,52 @@ if ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) { } $data["startindex"] = $currentpage; +$extracted = false; if ( !is_dir($comicoutputfull) ) { mkdir($comicoutputfull, 0755, true); +} else { + touch($comicoutputfull); + $extracted = true; } $files = array(); -if ( $ext == "cbz" ) { - $zip = new ZipArchive(); - $opened = $zip->open($comicfull); - for ( $i=0; $i<$zip->numFiles; $i++ ) { - $imgname = basename($zip->getNameIndex($i)); - //$myext = substr($imgname, -3); - if ( ! isset(pathinfo($imgname)['extension']) ) continue; - $myext = strtolower(pathinfo($imgname)['extension']); - if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { - $imgname = str_replace("#", "", $imgname); - $imgcontents = $zip->getFromIndex($i); - $written = file_put_contents($comicoutputfull . $imgname, $imgcontents); - if ( $written ) $files[] = $imgname; - } +if ( $extracted ) { + $contents = glob($comicoutputfull . "*"); + foreach ( $contents as $i ) { + $files[] = basename($i); } -} elseif ( $ext == "cbr" ) { - $rar = RarArchive::open($comicfull); - $entries = $rar->getEntries(); - foreach ( $entries as $entry ) { - $outfile = str_replace("#", "", basename($entry->getName())); - $entry->extract(false, $comicoutputfull . $outfile); - if ( ! isset(pathinfo($outfile)['extension']) ) continue; - $myext = strtolower(pathinfo($outfile)['extension']); - if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { - $files[] = basename($outfile); - } - } - unset($entry); } else { - exit(); + if ( $ext == "cbz" ) { + $zip = new ZipArchive(); + $opened = $zip->open($comicfull); + for ( $i=0; $i<$zip->numFiles; $i++ ) { + $imgname = basename($zip->getNameIndex($i)); + //$myext = substr($imgname, -3); + if ( ! isset(pathinfo($imgname)['extension']) ) continue; + $myext = strtolower(pathinfo($imgname)['extension']); + if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { + $imgname = str_replace("#", "", $imgname); + $imgcontents = $zip->getFromIndex($i); + $written = file_put_contents($comicoutputfull . $imgname, $imgcontents); + if ( $written ) $files[] = $imgname; + } + } + } elseif ( $ext == "cbr" ) { + $rar = RarArchive::open($comicfull); + $entries = $rar->getEntries(); + foreach ( $entries as $entry ) { + $outfile = str_replace("#", "", basename($entry->getName())); + $entry->extract(false, $comicoutputfull . $outfile); + if ( ! isset(pathinfo($outfile)['extension']) ) continue; + $myext = strtolower(pathinfo($outfile)['extension']); + if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { + $files[] = basename($outfile); + } + } + unset($entry); + } else { + exit(); + } } natsort($files);