Comic improvments

pull/932/head
Ozzieisaacs 6 years ago
parent f483ca3214
commit 1561a4abdf

@ -24,21 +24,34 @@ import uploader
def extractCover(tmp_file_name, original_file_extension): def extractCover(tmp_file_name, original_file_extension):
cover_data = None
if original_file_extension.upper() == '.CBZ': if original_file_extension.upper() == '.CBZ':
cf = zipfile.ZipFile(tmp_file_name) cf = zipfile.ZipFile(tmp_file_name)
compressed_name = cf.namelist()[0] for name in cf.namelist():
cover_data = cf.read(compressed_name) ext = os.path.splitext(name)
if len(ext) > 1:
extension = ext[1].lower()
if extension == '.jpg':
cover_data = cf.read(name)
break
elif original_file_extension.upper() == '.CBT': elif original_file_extension.upper() == '.CBT':
cf = tarfile.TarFile(tmp_file_name) cf = tarfile.TarFile(tmp_file_name)
compressed_name = cf.getnames()[0] for name in cf.getnames():
cover_data = cf.extractfile(compressed_name).read() ext = os.path.splitext(name)
if len(ext) > 1:
extension = ext[1].lower()
if extension == '.jpg':
cover_data = cf.extractfile(name).read()
break
prefix = os.path.dirname(tmp_file_name) prefix = os.path.dirname(tmp_file_name)
if cover_data:
tmp_cover_name = prefix + '/cover' + os.path.splitext(compressed_name)[1] tmp_cover_name = prefix + '/cover' + extension
image = open(tmp_cover_name, 'wb') image = open(tmp_cover_name, 'wb')
image.write(cover_data) image.write(cover_data)
image.close() image.close()
else:
tmp_cover_name = None
return tmp_cover_name return tmp_cover_name

@ -106,7 +106,7 @@ var createURLFromArray = function(array, mimeType) {
if (mimeType === 'image/xml+svg') { if (mimeType === 'image/xml+svg') {
const xmlStr = new TextDecoder('utf-8').decode(array); const xmlStr = new TextDecoder('utf-8').decode(array);
return 'data:image/svg+xml;UTF-8,' + encodeURIComponent(xmlStr); return 'data:image/svg+xml;UTF-8,' + encodeURIComponent(xmlStr);
} }
// TODO: Move all this browser support testing to a common place // TODO: Move all this browser support testing to a common place
// and do it just once. // and do it just once.
@ -137,11 +137,13 @@ var createURLFromArray = function(array, mimeType) {
kthoom.ImageFile = function(file) { kthoom.ImageFile = function(file) {
this.filename = file.filename; this.filename = file.filename;
var fileExtension = file.filename.split(".").pop().toLowerCase(); var fileExtension = file.filename.split(".").pop().toLowerCase();
var mimeType = fileExtension === "png" ? "image/png" : this.mimeType = fileExtension === "png" ? "image/png" :
(fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" : (fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" :
fileExtension === "gif" ? "image/gif" : fileExtension == 'svg' ? 'image/xml+svg' : undefined; fileExtension === "gif" ? "image/gif" : fileExtension == 'svg' ? 'image/xml+svg' : undefined;
this.dataURI = createURLFromArray(file.fileData, mimeType); if ( this.mimeType !== undefined) {
this.data = file; this.dataURI = createURLFromArray(file.fileData, this.mimeType);
this.data = file;
}
}; };
@ -169,34 +171,42 @@ function loadFromArrayBuffer(ab) {
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS, unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS,
function(e) { function(e) {
var percentage = e.currentBytesUnarchived / e.totalUncompressedBytesInArchive; var percentage = e.currentBytesUnarchived / e.totalUncompressedBytesInArchive;
totalImages = e.totalFilesInArchive; if (totalImages === 0) {
totalImages = e.totalFilesInArchive;
}
updateProgress(percentage *100); updateProgress(percentage *100);
lastCompletion = percentage * 100; lastCompletion = percentage * 100;
}); });
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.EXTRACT, unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.EXTRACT,
function(e) { function(e) {
// convert DecompressedFile into a bunch of ImageFiles // convert DecompressedFile into a bunch of ImageFiles
if (e.unarchivedFile) { if (e.unarchivedFile) {
var f = e.unarchivedFile; var f = e.unarchivedFile;
// add any new pages based on the filename // add any new pages based on the filename
if (imageFilenames.indexOf(f.filename) === -1) { if (imageFilenames.indexOf(f.filename) === -1) {
imageFilenames.push(f.filename); var test = new kthoom.ImageFile(f);
imageFiles.push(new kthoom.ImageFile(f)); if ( test.mimeType !== undefined) {
// add thumbnails to the TOC list imageFilenames.push(f.filename);
$("#thumbnails").append( imageFiles.push(test);
"<li>" + // add thumbnails to the TOC list
"<a data-page='" + imageFiles.length + "'>" + $("#thumbnails").append(
"<img src='" + imageFiles[imageFiles.length - 1].dataURI + "'/>" + "<li>" +
"<span>" + imageFiles.length + "</span>" + "<a data-page='" + imageFiles.length + "'>" +
"</a>" + "<img src='" + imageFiles[imageFiles.length - 1].dataURI + "'/>" +
"</li>" "<span>" + imageFiles.length + "</span>" +
); "</a>" +
"</li>"
);
// display first page if we haven't yet
if (imageFiles.length === currentImage + 1) {
updatePage(lastCompletion);
}
}
else {
totalImages--;
}
} }
} }
// display first page if we haven't yet
if (imageFiles.length === currentImage + 1) {
updatePage(lastCompletion);
}
}); });
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH, unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH,
function() { function() {

@ -68,23 +68,23 @@ var ZipLocalFile = function(bstream) {
this.filename = bstream.readString(this.fileNameLength); this.filename = bstream.readString(this.fileNameLength);
} }
info("Zip Local File Header:"); console.log("Zip Local File Header:");
info(" version=" + this.version); console.log(" version=" + this.version);
info(" general purpose=" + this.generalPurpose); console.log(" general purpose=" + this.generalPurpose);
info(" compression method=" + this.compressionMethod); console.log(" compression method=" + this.compressionMethod);
info(" last mod file time=" + this.lastModFileTime); console.log(" last mod file time=" + this.lastModFileTime);
info(" last mod file date=" + this.lastModFileDate); console.log(" last mod file date=" + this.lastModFileDate);
info(" crc32=" + this.crc32); console.log(" crc32=" + this.crc32);
info(" compressed size=" + this.compressedSize); console.log(" compressed size=" + this.compressedSize);
info(" uncompressed size=" + this.uncompressedSize); console.log(" uncompressed size=" + this.uncompressedSize);
info(" file name length=" + this.fileNameLength); console.log(" file name length=" + this.fileNameLength);
info(" extra field length=" + this.extraFieldLength); console.log(" extra field length=" + this.extraFieldLength);
info(" filename = '" + this.filename + "'"); console.log(" filename = '" + this.filename + "'");
this.extraField = null; this.extraField = null;
if (this.extraFieldLength > 0) { if (this.extraFieldLength > 0) {
this.extraField = bstream.readString(this.extraFieldLength); this.extraField = bstream.readString(this.extraFieldLength);
info(" extra field=" + this.extraField); console.log(" extra field=" + this.extraField);
} }
// read in the compressed data // read in the compressed data
@ -110,13 +110,13 @@ ZipLocalFile.prototype.unzip = function() {
// Zip Version 1.0, no compression (store only) // Zip Version 1.0, no compression (store only)
if (this.compressionMethod == 0 ) { if (this.compressionMethod == 0 ) {
info("ZIP v" + this.version + ", store only: " + this.filename + " (" + this.compressedSize + " bytes)"); console.log("ZIP v" + this.version + ", store only: " + this.filename + " (" + this.compressedSize + " bytes)");
currentBytesUnarchivedInFile = this.compressedSize; currentBytesUnarchivedInFile = this.compressedSize;
currentBytesUnarchived += this.compressedSize; currentBytesUnarchived += this.compressedSize;
} }
// version == 20, compression method == 8 (DEFLATE) // version == 20, compression method == 8 (DEFLATE)
else if (this.compressionMethod == 8) { else if (this.compressionMethod == 8) {
info("ZIP v2.0, DEFLATE: " + this.filename + " (" + this.compressedSize + " bytes)"); console.log("ZIP v2.0, DEFLATE: " + this.filename + " (" + this.compressedSize + " bytes)");
this.fileData = inflate(this.fileData, this.uncompressedSize); this.fileData = inflate(this.fileData, this.uncompressedSize);
} }
else { else {
@ -164,7 +164,7 @@ var unzip = function(arrayBuffer) {
// archive extra data record // archive extra data record
if (bstream.peekNumber(4) == zArchiveExtraDataSignature) { if (bstream.peekNumber(4) == zArchiveExtraDataSignature) {
info(" Found an Archive Extra Data Signature"); console.log(" Found an Archive Extra Data Signature");
// skipping this record for now // skipping this record for now
bstream.readNumber(4); bstream.readNumber(4);
@ -175,7 +175,7 @@ var unzip = function(arrayBuffer) {
// central directory structure // central directory structure
// TODO: handle the rest of the structures (Zip64 stuff) // TODO: handle the rest of the structures (Zip64 stuff)
if (bstream.peekNumber(4) == zCentralFileHeaderSignature) { if (bstream.peekNumber(4) == zCentralFileHeaderSignature) {
info(" Found a Central File Header"); console.log(" Found a Central File Header");
// read all file headers // read all file headers
while (bstream.peekNumber(4) == zCentralFileHeaderSignature) { while (bstream.peekNumber(4) == zCentralFileHeaderSignature) {
@ -205,7 +205,7 @@ var unzip = function(arrayBuffer) {
// digital signature // digital signature
if (bstream.peekNumber(4) == zDigitalSignatureSignature) { if (bstream.peekNumber(4) == zDigitalSignatureSignature) {
info(" Found a Digital Signature"); console.log(" Found a Digital Signature");
bstream.readNumber(4); bstream.readNumber(4);
var sizeOfSignature = bstream.readNumber(2); var sizeOfSignature = bstream.readNumber(2);

Loading…
Cancel
Save