def cbz2epub3(cbzfname, epubfile='out.eub', tmpldir='template', mangamode=False, singlepage=False): # working dir imgdir = tempfile.mkdtemp() workdir = tempfile.mkdtemp() # convert img_files = importImageFromZip(cbzfname, imgdir, mangamode=mangamode, singlepage=singlepage) title = guessTitle(cbzfname) ttbl = genTemplateInfo(img_files, title, mangamode=mangamode) epubMakeTree(tmpldir, workdir, ttbl) for fname in os.listdir(imgdir): shutil.move(os.path.join(imgdir, fname), os.path.join(workdir, 'EPUB', 'Image')) epubpack(workdir, epubfile) # cleanup os.rmdir(imgdir) shutil.rmtree(workdir)
def OnDropFiles(self, x, y, filenames): self.obj.SetInsertionPointEnd() # main body for filename in filenames: if os.path.exists(filename) and os.path.isfile(filename) and filename.endswith(".epub"): import zipfile epubdir = os.path.splitext(filename)[0] zipf = zipfile.ZipFile(filename, 'r') zipf.extractall(epubdir) self.obj.AppendText(u"Extracted to %s\n" %epubdir) elif os.path.exists(filename) and os.path.isdir(filename) and os.path.exists( os.path.join(filename, "mimetype") ): from epubpack import epubpack epubfile = filename+".epub" epubpack(filename, epubfile) self.obj.AppendText(u"INFO: Archived to %s\n" %epubfile) else: self.obj.AppendText("FAIL: Wrong file or directory\n")
#------------------------------------------------- def gen_bibtoc(odir): # (1) content.opf xml = open("content.opf").read().decode("utf-8").replace("@@@TITLE@@@", u"성경 ({0:s})".format(title) ) open( os.path.join(odir, "OEBPS", "content.opf"),"w").write(xml.encode("utf-8")) print "content.opf is generated" # (2) toc.ncx xml = open("toc.ncx").read().decode("utf-8").replace("@@@TITLE@@@", u"성경 ({0:s})".format(title) ) open( os.path.join(odir, "OEBPS", "toc.ncx"),"w").write(xml.encode("utf-8")) print "toc.ncx is generated" #------------------------------------------------- if __name__ == "__main__": import os import shutil work_dir = u'epub' ofname = u"성경_{0:s}.epub".format(title) # (1) convert txt to xhtml bibtxt2xhtml(title+".txt",work_dir) # (2) content.opf+toc.ncx gen_bibtoc(work_dir) # (3) copy cover image shutil.copyfile(cover_file, os.path.join(work_dir, "OEBPS", "cover.jpeg")) # (4) create epub import epubpack epubpack.epubpack(work_dir, ofname) print u"DONE: {0:s} is generated".format(ofname).encode('utf-8') # vim:sw=4:sts=4:et