mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2895 (Error downloading cover if ISBN contains en dashes)
This commit is contained in:
commit
192abdd179
@ -46,13 +46,17 @@ class Writer(FormatWriter):
|
||||
|
||||
sections = hr+text+images+metadata+['MeTaInFo\x00']
|
||||
|
||||
lengths = [len(i) for i in sections]
|
||||
lengths = [len(i) if i not in images else len(i[0]) + len(i[1]) for i in sections]
|
||||
|
||||
pdbHeaderBuilder = PdbHeaderBuilder(IDENTITY, metadata[0].partition('\x00')[0])
|
||||
pdbHeaderBuilder.build_header(lengths, out_stream)
|
||||
|
||||
for item in sections:
|
||||
out_stream.write(item)
|
||||
if item in images:
|
||||
out_stream.write(item[0])
|
||||
out_stream.write(item[1])
|
||||
else:
|
||||
out_stream.write(item)
|
||||
|
||||
def _text(self, oeb_book):
|
||||
pmlmlizer = PMLMLizer(self.log)
|
||||
@ -69,10 +73,10 @@ class Writer(FormatWriter):
|
||||
|
||||
for item in manifest:
|
||||
if item.media_type in OEB_IMAGES:
|
||||
image = 'PNG '
|
||||
header = 'PNG '
|
||||
|
||||
image += image_name(item.href)
|
||||
image = image.ljust(62, '\x00')
|
||||
header += image_name(item.href)
|
||||
header = header.ljust(62, '\x00')
|
||||
|
||||
im = Image.open(cStringIO.StringIO(item.data)).convert('P')
|
||||
im.thumbnail((300,300), Image.ANTIALIAS)
|
||||
@ -81,10 +85,8 @@ class Writer(FormatWriter):
|
||||
im.save(data, 'PNG')
|
||||
data = data.getvalue()
|
||||
|
||||
image += data
|
||||
|
||||
if len(image) < 65505:
|
||||
images.append(image)
|
||||
if len(data) + len(header) < 65505:
|
||||
images.append((header, data))
|
||||
|
||||
return images
|
||||
|
||||
|
@ -392,7 +392,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
||||
self.tags.update_tags_cache(self.db.all_tags())
|
||||
|
||||
def fetch_cover(self):
|
||||
isbn = unicode(self.isbn.text()).strip()
|
||||
isbn = re.sub(r'[^0-9a-zA-Z]', '', unicode(self.isbn.text())).strip()
|
||||
self.fetch_cover_button.setEnabled(False)
|
||||
self.setCursor(Qt.WaitCursor)
|
||||
title, author = map(unicode, (self.title.text(), self.authors.text()))
|
||||
@ -510,7 +510,8 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
||||
aus = qstring_to_unicode(self.author_sort.text())
|
||||
if aus:
|
||||
self.db.set_author_sort(self.id, aus, notify=False)
|
||||
self.db.set_isbn(self.id, qstring_to_unicode(self.isbn.text()), notify=False)
|
||||
self.db.set_isbn(self.id,
|
||||
re.sub(r'[^0-9a-zA-Z]', '', unicode(self.isbn.text())), notify=False)
|
||||
self.db.set_rating(self.id, 2*self.rating.value(), notify=False)
|
||||
self.db.set_publisher(self.id, qstring_to_unicode(self.publisher.currentText()), notify=False)
|
||||
self.db.set_tags(self.id, qstring_to_unicode(self.tags.text()).split(','), notify=False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user