Image display in fb2 parser
This commit is contained in:
@@ -89,16 +89,22 @@ class FB2:
|
|||||||
for j in i:
|
for j in i:
|
||||||
if j.name == 'title':
|
if j.name == 'title':
|
||||||
this_title = j.getText(separator=' ')
|
this_title = j.getText(separator=' ')
|
||||||
|
|
||||||
self.book['book_list'].append(
|
self.book['book_list'].append(
|
||||||
(this_title, str(i)))
|
[this_title, str(i)])
|
||||||
|
|
||||||
# Extract all images to the temp_dir
|
# Extract all images to the temp_dir
|
||||||
for i in self.xml.find_all('binary'):
|
for i in self.xml.find_all('binary'):
|
||||||
this_image_name = i.get('id')
|
image_name = i.get('id')
|
||||||
this_image_path = os.path.join(temp_dir, this_image_name)
|
image_path = os.path.join(temp_dir, image_name)
|
||||||
|
image_string = f'<image l:href="#{image_name}"'
|
||||||
|
replacement_string = f'<img src=\"{image_path}\"'
|
||||||
|
|
||||||
|
for j in self.book['book_list']:
|
||||||
|
j[1] = j[1].replace(image_string, replacement_string)
|
||||||
try:
|
try:
|
||||||
this_image_data = base64.decodebytes(i.text.encode())
|
image_data = base64.decodebytes(i.text.encode())
|
||||||
with open(this_image_path, 'wb') as outimage:
|
with open(image_path, 'wb') as outimage:
|
||||||
outimage.write(this_image_data)
|
outimage.write(image_data)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user