mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #3013 (Find ISBN in file and add it to metadata)
This commit is contained in:
parent
c98a4df96d
commit
7f4dcb8827
@ -3,6 +3,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
'''Read meta information from PDF files'''
|
'''Read meta information from PDF files'''
|
||||||
|
|
||||||
|
import re
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
@ -11,10 +12,16 @@ from calibre.ebooks.metadata import MetaInformation, string_to_authors, authors_
|
|||||||
|
|
||||||
pdfreflow, pdfreflow_error = plugins['pdfreflow']
|
pdfreflow, pdfreflow_error = plugins['pdfreflow']
|
||||||
|
|
||||||
|
_isbn_pat = re.compile(r'ISBN[: ]*([-0-9Xx]+)')
|
||||||
|
|
||||||
def get_metadata(stream, cover=True):
|
def get_metadata(stream, cover=True):
|
||||||
if pdfreflow is None:
|
if pdfreflow is None:
|
||||||
raise RuntimeError(pdfreflow_error)
|
raise RuntimeError(pdfreflow_error)
|
||||||
info = pdfreflow.get_metadata(stream.read(), cover)
|
raw = stream.read()
|
||||||
|
isbn = _isbn_pat.search(raw)
|
||||||
|
if isbn is not None:
|
||||||
|
isbn = isbn.group(1).replace('-', '').replace(' ', '')
|
||||||
|
info = pdfreflow.get_metadata(raw, cover)
|
||||||
title = info.get('Title', None)
|
title = info.get('Title', None)
|
||||||
au = info.get('Author', None)
|
au = info.get('Author', None)
|
||||||
if au is None:
|
if au is None:
|
||||||
@ -22,6 +29,8 @@ def get_metadata(stream, cover=True):
|
|||||||
else:
|
else:
|
||||||
au = string_to_authors(au)
|
au = string_to_authors(au)
|
||||||
mi = MetaInformation(title, au)
|
mi = MetaInformation(title, au)
|
||||||
|
if isbn is not None:
|
||||||
|
mi.isbn = isbn
|
||||||
|
|
||||||
creator = info.get('Creator', None)
|
creator = info.get('Creator', None)
|
||||||
if creator:
|
if creator:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user