mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add support for extracting cover images to fb2-meta
This commit is contained in:
parent
25310eb146
commit
2960781bb0
@ -5,7 +5,8 @@ __copyright__ = '2008, Anatoly Shipitsin <norguhtar at gmail.com>'
|
||||
|
||||
'''Read meta information from fb2 files'''
|
||||
|
||||
import sys, os
|
||||
import sys, os, mimetypes
|
||||
from base64 import b64decode
|
||||
|
||||
from calibre.ebooks.BeautifulSoup import BeautifulStoneSoup
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
@ -18,15 +19,30 @@ def get_metadata(stream):
|
||||
author= [firstname+" "+lastname]
|
||||
title = soup.find("book-title").string
|
||||
comments = soup.find("annotation")
|
||||
cp = soup.find('coverpage')
|
||||
cdata = None
|
||||
if cp:
|
||||
cimage = cp.find('image', attrs={'l:href':True})
|
||||
if cimage:
|
||||
id = cimage['l:href'].replace('#', '')
|
||||
binary = soup.find('binary', id=id, attrs={'content-type':True})
|
||||
if binary:
|
||||
mt = binary['content-type']
|
||||
exts = mimetypes.guess_all_extensions(mt)
|
||||
if not exts:
|
||||
exts = ['.jpg']
|
||||
cdata = (exts[0][1:], b64decode(binary.string.strip()))
|
||||
|
||||
if comments and len(comments) > 1:
|
||||
comments = comments.p.contents[0]
|
||||
series = soup.find("sequence")
|
||||
# series_index = series.index
|
||||
mi = MetaInformation(title, author)
|
||||
mi.comments = comments
|
||||
mi.author_sort = lastname+'; '+firstname
|
||||
if series:
|
||||
mi.series = series.get('name', None)
|
||||
# mi.series_index = series_index
|
||||
if cdata:
|
||||
mi.cover_data = cdata
|
||||
return mi
|
||||
|
||||
def main(args=sys.argv):
|
||||
|
Loading…
x
Reference in New Issue
Block a user