diff options
author | Paweł Jastrzębski <pawelj@iosphe.re> | 2017-10-14 18:01:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-14 18:01:32 +0200 |
commit | 7524c50657e3b01459dc6940f562021a3e33a9b2 (patch) | |
tree | 3293727977f898cfc6718af8d415ef60de362b3e /kindlecomicconverter | |
parent | Merge pull request #244 from ciromattia/dev (diff) | |
parent | Updated README + version bump (diff) | |
download | kcc-7524c50657e3b01459dc6940f562021a3e33a9b2.tar.gz kcc-7524c50657e3b01459dc6940f562021a3e33a9b2.tar.bz2 kcc-7524c50657e3b01459dc6940f562021a3e33a9b2.zip |
Merge pull request #250 from ciromattia/dev
5.4.2
Diffstat (limited to 'kindlecomicconverter')
-rw-r--r-- | kindlecomicconverter/KCC_gui.py | 60 | ||||
-rw-r--r-- | kindlecomicconverter/KCC_ui.py | 1 | ||||
-rw-r--r-- | kindlecomicconverter/__init__.py | 2 | ||||
-rwxr-xr-x | kindlecomicconverter/comic2ebook.py | 23 | ||||
-rwxr-xr-x | kindlecomicconverter/image.py | 1 | ||||
-rw-r--r-- | kindlecomicconverter/metadata.py | 4 |
6 files changed, 56 insertions, 35 deletions
diff --git a/kindlecomicconverter/KCC_gui.py b/kindlecomicconverter/KCC_gui.py index c2749ff..a98585a 100644 --- a/kindlecomicconverter/KCC_gui.py +++ b/kindlecomicconverter/KCC_gui.py @@ -500,28 +500,38 @@ class KCCGUI(KCC_ui.Ui_mainWindow): GUI.jobList.scrollToBottom() def selectFileMetaEditor(self): - if self.UnRAR: - if self.sevenza: - fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath, - 'Comic (*.cbz *.cbr *.cb7)') - else: - fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath, - 'Comic (*.cbz *.cbr)') + sname = '' + if QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier: + dname = QtWidgets.QFileDialog.getExistingDirectory(MW, 'Select directory', self.lastPath) + if dname != '': + sname = os.path.join(dname, 'ComicInfo.xml') + if sys.platform.startswith('win'): + sname = sname.replace('/', '\\') + self.lastPath = os.path.abspath(sname) else: - if self.sevenza: - fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath, - 'Comic (*.cbz *.cb7)') - else: - fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath, - 'Comic (*.cbz)') - if fname[0] != '': - if sys.platform.startswith('win'): - fname = fname[0].replace('/', '\\') + if self.UnRAR: + if self.sevenza: + fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath, + 'Comic (*.cbz *.cbr *.cb7)') + else: + fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath, + 'Comic (*.cbz *.cbr)') else: - fname = fname[0] - self.lastPath = os.path.abspath(os.path.join(fname, os.pardir)) + if self.sevenza: + fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath, + 'Comic (*.cbz *.cb7)') + else: + fname = QtWidgets.QFileDialog.getOpenFileName(MW, 'Select file', self.lastPath, + 'Comic (*.cbz)') + if fname[0] != '': + if sys.platform.startswith('win'): + sname = fname[0].replace('/', '\\') + else: + sname = fname[0] + self.lastPath = os.path.abspath(os.path.join(sname, os.pardir)) + if sname != '': try: - self.editor.loadData(fname) + self.editor.loadData(sname) except Exception as err: _, _, traceback = sys.exc_info() GUI.sentry.captureException() @@ -618,9 +628,9 @@ class KCCGUI(KCC_ui.Ui_mainWindow): def togglequalityBox(self, value): profile = GUI.profiles[str(GUI.deviceBox.currentText())] if value == 2: - if profile['Label'] in ['KV']: + if profile['Label'] in ['KV', 'KO']: self.addMessage('This option is intended for older Kindle models.', 'warning') - self.addMessage('It will not increase quality on a device with 300 ppi screen.', 'warning') + self.addMessage('On this device, quality improvement will be negligible.', 'warning') GUI.upscaleBox.setEnabled(False) GUI.upscaleBox.setChecked(True) else: @@ -918,6 +928,8 @@ class KCCGUI(KCC_ui.Ui_mainWindow): MW.resize(500, 500) self.profiles = { + "Kindle Oasis 2": {'PVOptions': True, 'ForceExpert': False, 'DefaultFormat': 0, + 'DefaultUpscale': True, 'Label': 'KO'}, "Kindle Oasis": {'PVOptions': True, 'ForceExpert': False, 'DefaultFormat': 0, 'DefaultUpscale': True, 'Label': 'KV'}, "Kindle Voyage": {'PVOptions': True, 'ForceExpert': False, 'DefaultFormat': 0, @@ -956,6 +968,7 @@ class KCCGUI(KCC_ui.Ui_mainWindow): 'DefaultUpscale': False, 'Label': 'K34'}, } profilesGUI = [ + "Kindle Oasis 2", "Kindle Oasis", "Kindle Voyage", "Kindle PW 3", @@ -1106,7 +1119,10 @@ class KCCGUI_MetaEditor(KCC_ui_editor.Ui_editorDialog): for field in (self.writerLine, self.pencillerLine, self.inkerLine, self.coloristLine): field.setText(', '.join(self.parser.data[field.objectName().capitalize()[:-4] + 's'])) if self.seriesLine.text() == '': - self.seriesLine.setText(file.split('\\')[-1].split('/')[-1].split('.')[0]) + if file.endswith('.xml'): + self.seriesLine.setText(file.split('\\')[-2]) + else: + self.seriesLine.setText(file.split('\\')[-1].split('/')[-1].split('.')[0]) def saveData(self): for field in (self.volumeLine, self.numberLine, self.muidLine): diff --git a/kindlecomicconverter/KCC_ui.py b/kindlecomicconverter/KCC_ui.py index ef8fcbf..b70f3ef 100644 --- a/kindlecomicconverter/KCC_ui.py +++ b/kindlecomicconverter/KCC_ui.py @@ -258,6 +258,7 @@ class Ui_mainWindow(object): self.colorBox.setText(_translate("mainWindow", "Color mode")) self.gammaLabel.setText(_translate("mainWindow", "Gamma: Auto")) self.editorButton.setText(_translate("mainWindow", "Editor")) + self.editorButton.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'>Shift+Click to edit directory.</p></body></html>")) self.wikiButton.setText(_translate("mainWindow", "Wiki")) self.directoryButton.setToolTip(_translate("mainWindow", "<html><head/><body><p style=\'white-space:pre\'>Add directory containing JPG, PNG or GIF files to queue.<br/><span style=\" font-weight:600;\">CBR, CBZ and CB7 files inside will not be processed!</span></p></body></html>")) self.directoryButton.setText(_translate("mainWindow", "Add directory")) diff --git a/kindlecomicconverter/__init__.py b/kindlecomicconverter/__init__.py index 45fe8a6..dad32ea 100644 --- a/kindlecomicconverter/__init__.py +++ b/kindlecomicconverter/__init__.py @@ -1,4 +1,4 @@ -__version__ = '5.4.1' +__version__ = '5.4.2' __license__ = 'ISC' __copyright__ = '2012-2017, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>' __docformat__ = 'restructuredtext en' diff --git a/kindlecomicconverter/comic2ebook.py b/kindlecomicconverter/comic2ebook.py index 4d5f574..e27d5e6 100755 --- a/kindlecomicconverter/comic2ebook.py +++ b/kindlecomicconverter/comic2ebook.py @@ -104,7 +104,7 @@ def buildHTML(path, imgfile, imgfilepath): htmlfile = os.path.join(htmlpath, filename[0] + '.xhtml') imgsize = Image.open(os.path.join(head, "Images", postfix, imgfile)).size if options.hq: - imgsizeframe = deviceres + imgsizeframe = (int(imgsize[0] // 1.5), int(imgsize[1] // 1.5)) else: imgsizeframe = imgsize f = open(htmlfile, "w", encoding='UTF-8') @@ -118,7 +118,7 @@ def buildHTML(path, imgfile, imgfilepath): "content=\"width=" + str(imgsize[0]) + ", height=" + str(imgsize[1]) + "\"/>\n" "</head>\n", "<body style=\"" + additionalStyle + "\">\n", - "<div style=\"text-align:center;top:" + getTopMargin(deviceres, imgsize) + "%;\">\n", + "<div style=\"text-align:center;top:" + getTopMargin(deviceres, imgsizeframe) + "%;\">\n", "<img width=\"" + str(imgsizeframe[0]) + "\" height=\"" + str(imgsizeframe[1]) + "\" ", "src=\"", "../" * backref, "Images/", postfix, imgfile, "\"/>\n</div>\n"]) if options.iskindle and options.panelview: @@ -699,7 +699,7 @@ def sanitizeTree(filetree): for root, dirs, files in os.walk(filetree, False): for name in files: splitname = os.path.splitext(name) - slugified = slugify(splitname[0]) + slugified = slugify(splitname[0], False) while os.path.exists(os.path.join(root, slugified + splitname[1])) and splitname[0].upper()\ != slugified.upper(): slugified += "A" @@ -709,7 +709,7 @@ def sanitizeTree(filetree): os.replace(key, newKey) for name in dirs: tmpName = name - slugified = slugify(name) + slugified = slugify(name, True) while os.path.exists(os.path.join(root, slugified)) and name.upper() != slugified.upper(): slugified += "A" chapterNames[slugified] = tmpName @@ -856,8 +856,11 @@ def createNewTome(): return tomePath, tomePathRoot -def slugify(value): - value = slugifyExt(value) +def slugify(value, isDir): + if isDir: + value = slugifyExt(value, regex_pattern=r'[^-a-z0-9_\.]+') + else: + value = slugifyExt(value) value = sub(r'0*([0-9]{4,})', r'\1', sub(r'([0-9]+)', r'0000\1', value, count=2)) return value @@ -887,8 +890,8 @@ def makeParser(): otherOptions = OptionGroup(psr, "OTHER") mainOptions.add_option("-p", "--profile", action="store", dest="profile", default="KV", - help="Device profile (Available options: K1, K2, K34, K578, KDX, KPW, KV, KoMT, KoG, KoGHD," - " KoA, KoAHD, KoAH2O, KoAO) [Default=KV]") + help="Device profile (Available options: K1, K2, K34, K578, KDX, KPW, KV, KO, KoMT, KoG," + " KoGHD, KoA, KoAHD, KoAH2O, KoAO) [Default=KV]") mainOptions.add_option("-m", "--manga-style", action="store_true", dest="righttoleft", default=False, help="Manga style (right-to-left reading and splitting)") mainOptions.add_option("-q", "--hq", action="store_true", dest="hq", default=False, @@ -951,13 +954,13 @@ def checkOptions(): options.iskindle = False options.bordersColor = None if options.format == 'Auto': - if options.profile in ['K1', 'K2', 'K34', 'K578', 'KPW', 'KV']: + if options.profile in ['K1', 'K2', 'K34', 'K578', 'KPW', 'KV', 'KO']: options.format = 'MOBI' elif options.profile in ['OTHER', 'KoMT', 'KoG', 'KoGHD', 'KoA', 'KoAHD', 'KoAH2O', 'KoAO']: options.format = 'EPUB' elif options.profile in ['KDX']: options.format = 'CBZ' - if options.profile in ['K1', 'K2', 'K34', 'K578', 'KPW', 'KV']: + if options.profile in ['K1', 'K2', 'K34', 'K578', 'KPW', 'KV', 'KO']: options.iskindle = True if options.white_borders: options.bordersColor = 'white' diff --git a/kindlecomicconverter/image.py b/kindlecomicconverter/image.py index c95817e..e7f29a4 100755 --- a/kindlecomicconverter/image.py +++ b/kindlecomicconverter/image.py @@ -85,6 +85,7 @@ class ProfileData: 'KDX': ("Kindle DX/DXG", (824, 1000), Palette16, 1.8), 'KPW': ("Kindle Paperwhite 1/2", (758, 1024), Palette16, 1.8), 'KV': ("Kindle Paperwhite 3/Voyage/Oasis", (1072, 1448), Palette16, 1.8), + 'KO': ("Kindle Oasis 2", (1264, 1680), Palette16, 1.8), 'KoMT': ("Kobo Mini/Touch", (600, 800), Palette16, 1.8), 'KoG': ("Kobo Glo", (768, 1024), Palette16, 1.8), 'KoGHD': ("Kobo Glo HD", (1072, 1448), Palette16, 1.8), diff --git a/kindlecomicconverter/metadata.py b/kindlecomicconverter/metadata.py index f2cf488..714dcd1 100644 --- a/kindlecomicconverter/metadata.py +++ b/kindlecomicconverter/metadata.py @@ -43,10 +43,10 @@ class MetadataParser: 'Bookmarks': []} self.rawdata = None self.compressor = None - if self.source.endswith('.xml'): + if self.source.endswith('.xml') and os.path.exists(self.source): self.rawdata = parse(self.source) self.parseXML() - else: + elif not self.source.endswith('.xml'): if is_zipfile(self.source): self.compressor = 'zip' with ZipFile(self.source) as zip_file: |