Added reading of classification and category from lrf file when book is added to library.

This commit is contained in:
Kovid Goyal 2007-01-05 22:45:24 +00:00
parent 714b4efbd8
commit fa758e1b2c
2 changed files with 14 additions and 5 deletions

View File

@ -57,18 +57,25 @@ class LibraryDatabase(object):
title, author, publisher, size, cover = os.path.basename(_file), \ title, author, publisher, size, cover = os.path.basename(_file), \
None, None, os.stat(_file)[ST_SIZE], None None, None, os.stat(_file)[ST_SIZE], None
ext = title[title.rfind(".")+1:].lower() if title.find(".") > -1 else None ext = title[title.rfind(".")+1:].lower() if title.find(".") > -1 else None
comments = None comments, tags = None, None
if ext == "lrf": if ext == "lrf":
lrf = LRFMetaFile(open(_file, "r+b")) lrf = LRFMetaFile(open(_file, "r+b"))
title, author, cover, publisher = lrf.title, lrf.author.strip(), \ title, author, cover, publisher = lrf.title, lrf.author.strip(), \
lrf.thumbnail, lrf.publisher.strip() lrf.thumbnail, lrf.publisher.strip()
if "unknown" in publisher.lower(): if "unknown" in publisher.lower() or 'some publisher' in publisher.lower():
publisher = None publisher = None
if "unknown" in author.lower(): if "unknown" in author.lower():
author = None author = None
comments = lrf.free_text comments = lrf.free_text
if not comments: if not comments:
comments = None 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() data = open(_file).read()
usize = len(data) usize = len(data)
data = compress(data) data = compress(data)
@ -79,7 +86,7 @@ class LibraryDatabase(object):
self.con.execute("insert into books_meta (title, authors, publisher, "+\ self.con.execute("insert into books_meta (title, authors, publisher, "+\
"size, tags, comments, rating) values "+\ "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] _id = self.con.execute("select max(id) from books_meta").next()[0]
self.con.execute("insert into books_data values (?,?,?,?)", \ self.con.execute("insert into books_data values (?,?,?,?)", \
(_id, ext, usize, sqlite.Binary(data))) (_id, ext, usize, sqlite.Binary(data)))
@ -166,7 +173,7 @@ class LibraryDatabase(object):
try: try:
lrf = LRFMetaFile(s) lrf = LRFMetaFile(s)
lrf.author = metadata["authors"] lrf.author = metadata["authors"]
lrf.title = metadata["title"] lrf.title = metadata["title"]
# Not sure if I want to override the lrf freetext field # Not sure if I want to override the lrf freetext field
# with a possibly null value # with a possibly null value
#lrf.free_text = metadata["comments"] #lrf.free_text = metadata["comments"]

View File

@ -389,7 +389,9 @@ class LRFMetaFile(object):
break break
if offset >= (2**8)**4: if offset >= (2**8)**4:
# New offset is larger than a DWORD, so leave # 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 offset -= delta
self.pack(offset, fmt=DWORD, start=pos) self.pack(offset, fmt=DWORD, start=pos)
try: try: