mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Added reading of classification and category from lrf file when book is added to library.
This commit is contained in:
parent
714b4efbd8
commit
fa758e1b2c
@ -57,18 +57,25 @@ class LibraryDatabase(object):
|
||||
title, author, publisher, size, cover = os.path.basename(_file), \
|
||||
None, None, os.stat(_file)[ST_SIZE], None
|
||||
ext = title[title.rfind(".")+1:].lower() if title.find(".") > -1 else None
|
||||
comments = None
|
||||
comments, tags = None, None
|
||||
if ext == "lrf":
|
||||
lrf = LRFMetaFile(open(_file, "r+b"))
|
||||
title, author, cover, publisher = lrf.title, lrf.author.strip(), \
|
||||
lrf.thumbnail, lrf.publisher.strip()
|
||||
if "unknown" in publisher.lower():
|
||||
if "unknown" in publisher.lower() or 'some publisher' in publisher.lower():
|
||||
publisher = None
|
||||
if "unknown" in author.lower():
|
||||
author = None
|
||||
comments = lrf.free_text
|
||||
if not comments:
|
||||
comments = None
|
||||
classification, category = lrf.classification, lrf.category
|
||||
if 'unknown' in classification.lower():
|
||||
classification = ''
|
||||
if 'unknown' in category.lower():
|
||||
category = ''
|
||||
if classification or category:
|
||||
tags = ", ".join((classification, category))
|
||||
data = open(_file).read()
|
||||
usize = len(data)
|
||||
data = compress(data)
|
||||
@ -79,7 +86,7 @@ class LibraryDatabase(object):
|
||||
self.con.execute("insert into books_meta (title, authors, publisher, "+\
|
||||
"size, tags, comments, rating) values "+\
|
||||
"(?,?,?,?,?,?,?)", \
|
||||
(title, author, publisher, size, None, comments, None))
|
||||
(title, author, publisher, size, tags, comments, None))
|
||||
_id = self.con.execute("select max(id) from books_meta").next()[0]
|
||||
self.con.execute("insert into books_data values (?,?,?,?)", \
|
||||
(_id, ext, usize, sqlite.Binary(data)))
|
||||
|
@ -389,7 +389,9 @@ class LRFMetaFile(object):
|
||||
break
|
||||
if offset >= (2**8)**4:
|
||||
# New offset is larger than a DWORD, so leave
|
||||
# offset unchanged
|
||||
# offset unchanged. I'm assuming offset is an offset from
|
||||
# the previous object, otherwise this would impose a ~ 4MB limit
|
||||
# on LRF files.
|
||||
offset -= delta
|
||||
self.pack(offset, fmt=DWORD, start=pos)
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user