Skip to content

Commit

Permalink
Override book's title if Title is set in XML (#532)
Browse files Browse the repository at this point in the history
* Allow overriding title if it is set in XML
  • Loading branch information
vinhtq115 authored Jun 10, 2023
1 parent b0e38a7 commit 935727c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion kindlecomicconverter/comic2ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,9 @@ def getComicInfo(path, originalpath):
os.remove(xmlPath)
return
options.authors = []
if defaultTitle:
if xml.data['Title']:
options.title = hescape(xml.data['Title'])
elif defaultTitle:
if xml.data['Series']:
options.title = hescape(xml.data['Series'])
if xml.data['Volume']:
Expand Down
11 changes: 8 additions & 3 deletions kindlecomicconverter/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def __init__(self, source):
'Inkers': [],
'Colorists': [],
'Summary': '',
'Bookmarks': []}
'Bookmarks': [],
'Title': ''}
self.rawdata = None
self.format = None
if self.source.endswith('.xml') and os.path.exists(self.source):
Expand All @@ -58,6 +59,8 @@ def parseXML(self):
self.data['Number'] = self.rawdata.getElementsByTagName('Number')[0].firstChild.nodeValue
if len(self.rawdata.getElementsByTagName('Summary')) != 0:
self.data['Summary'] = self.rawdata.getElementsByTagName('Summary')[0].firstChild.nodeValue
if len(self.rawdata.getElementsByTagName('Title')) != 0:
self.data['Title'] = self.rawdata.getElementsByTagName('Title')[0].firstChild.nodeValue
for field in ['Writer', 'Penciller', 'Inker', 'Colorist']:
if len(self.rawdata.getElementsByTagName(field)) != 0:
for person in self.rawdata.getElementsByTagName(field)[0].firstChild.nodeValue.split(', '):
Expand All @@ -76,7 +79,8 @@ def saveXML(self):
for row in (['Series', self.data['Series']], ['Volume', self.data['Volume']],
['Number', self.data['Number']], ['Writer', ', '.join(self.data['Writers'])],
['Penciller', ', '.join(self.data['Pencillers'])], ['Inker', ', '.join(self.data['Inkers'])],
['Colorist', ', '.join(self.data['Colorists'])], ['Summary', self.data['Summary']]):
['Colorist', ', '.join(self.data['Colorists'])], ['Summary', self.data['Summary']],
['Title', self.data['Title']]):
if self.rawdata.getElementsByTagName(row[0]):
node = self.rawdata.getElementsByTagName(row[0])[0]
if row[1]:
Expand All @@ -97,7 +101,8 @@ def saveXML(self):
for row in (['Series', self.data['Series']], ['Volume', self.data['Volume']],
['Number', self.data['Number']], ['Writer', ', '.join(self.data['Writers'])],
['Penciller', ', '.join(self.data['Pencillers'])], ['Inker', ', '.join(self.data['Inkers'])],
['Colorist', ', '.join(self.data['Colorists'])], ['Summary', self.data['Summary']]):
['Colorist', ', '.join(self.data['Colorists'])], ['Summary', self.data['Summary']],
['Title', self.data['Title']]):
if row[1]:
main = doc.createElement(row[0])
root.appendChild(main)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ python-slugify>=1.2.1
raven>=6.0.0
# PyQt5-tools
mozjpeg-lossless-optimization>=1.1.2
distro
distro

0 comments on commit 935727c

Please sign in to comment.