diff options
| author | fsteffek <[email protected]> | 2015-02-21 16:32:38 +0100 |
|---|---|---|
| committer | Paweł Jastrzębski <[email protected]> | 2015-02-21 18:40:59 +0100 |
| commit | ecbf60fb28e3a7ce3bfba2eb8a43823e9a2db9bb (patch) | |
| tree | 3150c87a6788009c82d739a6c23fb0f351f832d9 | |
| parent | Fixed CLI version (diff) | |
| download | kcc-ecbf60fb28e3a7ce3bfba2eb8a43823e9a2db9bb.tar.gz kcc-ecbf60fb28e3a7ce3bfba2eb8a43823e9a2db9bb.tar.bz2 kcc-ecbf60fb28e3a7ce3bfba2eb8a43823e9a2db9bb.zip | |
Add ComicInfo bookmarks -> EPUB chapter support
Bookmarks from ComicRack's ComicInfo.xml are now converted to EPUB chapters. `Bookmark` is an attribute to the `Page` element in ComicInfo.xml. * Works with flat directory structure (no sub-folders support)
| -rwxr-xr-x | kcc/comic2ebook.py | 20 | ||||
| -rw-r--r-- | kcc/metadata.py | 8 |
2 files changed, 24 insertions, 4 deletions
diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index e8c2152..b654d2a 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -220,10 +220,14 @@ def buildNCX(dstdir, title, chapters, chapterNames): ]) for chapter in chapters: folder = chapter[0].replace(os.path.join(dstdir, 'OEBPS'), '').lstrip('/').lstrip('\\\\') - if os.path.basename(folder) != "Text": - title = chapterNames[os.path.basename(folder)] filename = getImageFileName(os.path.join(folder, chapter[1])) - f.write("<navPoint id=\"" + folder.replace('/', '_').replace('\\', '_') + "\"><navLabel><text>" + navID = folder.replace('/', '_').replace('\\', '_') + if options.chapters: + title = chapterNames[chapter[1]] + navID = filename[0].replace('/', '_').replace('\\', '_') + elif os.path.basename(folder) != "Text": + title = chapterNames[os.path.basename(folder)] + f.write("<navPoint id=\"" + navID + "\"><navLabel><text>" + title + "</text></navLabel><content src=\"" + filename[0].replace("\\", "/") + ".html\"/></navPoint>\n") f.write("</navMap>\n</ncx>") @@ -441,6 +445,13 @@ def buildEPUB(path, chapterNames, tomeNumber): if lastfile and not options.panelviewused and 'Ko' not in options.profile \ and options.profile not in ['K1', 'K2', 'KDX', 'OTHER']: filelist[-1] = buildHTML(lastfile[0], lastfile[1], lastfile[2], True) + # Overwrite chapternames if tree is flat and ComicInfo.xml has bookmarks + if not chapterNames and options.chapters: + chapterlist = [] + for aChapter in options.chapters: + filename = filelist[aChapter[0]][1] + chapterlist.append((filelist[aChapter[0]][0].replace('Images', 'Text'), filename)) + chapterNames[filename] = aChapter[1] buildNCX(path, options.title, chapterlist, chapterNames) buildOPF(path, options.title, filelist, cover) @@ -624,6 +635,7 @@ def getComicInfo(path, originalPath): xmlPath = os.path.join(path, 'ComicInfo.xml') options.authors = ['KCC'] options.remoteCovers = {} + options.chapters = [] titleSuffix = '' if options.title == 'defaulttitle': defaultTitle = True @@ -658,6 +670,8 @@ def getComicInfo(path, originalPath): options.authors = ['KCC'] if xml.data['MUid']: options.remoteCovers = getCoversFromMCB(xml.data['MUid']) + if xml.data['Bookmarks']: + options.chapters = xml.data['Bookmarks'] os.remove(xmlPath) diff --git a/kcc/metadata.py b/kcc/metadata.py index 8070d52..697a554 100644 --- a/kcc/metadata.py +++ b/kcc/metadata.py @@ -38,7 +38,8 @@ class MetadataParser: 'Pencillers': [], 'Inkers': [], 'Colorists': [], - 'MUid': ''} + 'MUid': '', + 'Bookmarks': []} self.rawdata = None self.compressor = None if self.source.endswith('.xml'): @@ -100,6 +101,11 @@ class MetadataParser: .search(self.rawdata.getElementsByTagName('ScanInformation')[0].firstChild.nodeValue) if coverId: self.data['MUid'] = coverId.group(2) + if len(self.rawdata.getElementsByTagName('Page')) != 0: + for page in self.rawdata.getElementsByTagName('Page'): + if 'Bookmark' in page.attributes and 'Image' in page.attributes: + self.data['Bookmarks'].append((int(page.attributes['Image'].value), + page.attributes['Bookmark'].value)) def saveXML(self): if self.rawdata: |