mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Various fixes needed for the new metainformation based drivers
This commit is contained in:
parent
9a28d7017f
commit
c065a4d8fa
@ -48,9 +48,9 @@ class CYBOOKG3(USBMS):
|
|||||||
|
|
||||||
def upload_cover(self, path, filename, metadata):
|
def upload_cover(self, path, filename, metadata):
|
||||||
coverdata = getattr(metadata, 'thumbnail', None)
|
coverdata = getattr(metadata, 'thumbnail', None)
|
||||||
if coverdata:
|
if coverdata and coverdata[2]:
|
||||||
with open('%s_6090.t2b' % os.path.join(path, filename), 'wb') as t2bfile:
|
with open('%s_6090.t2b' % os.path.join(path, filename), 'wb') as t2bfile:
|
||||||
t2b.write_t2b(t2bfile, coverdata)
|
t2b.write_t2b(t2bfile, coverdata[2])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_handle(cls, device_info, debug=False):
|
def can_handle(cls, device_info, debug=False):
|
||||||
|
@ -276,7 +276,9 @@ class DevicePlugin(Plugin):
|
|||||||
The idea is to use the metadata to determine where on the device to
|
The idea is to use the metadata to determine where on the device to
|
||||||
put the book. len(metadata) == len(files). Apart from the regular
|
put the book. len(metadata) == len(files). Apart from the regular
|
||||||
cover_data, there may also be a thumbnail attribute, which should
|
cover_data, there may also be a thumbnail attribute, which should
|
||||||
be used in preference.
|
be used in preference. The thumbnail attribute is of the form
|
||||||
|
(width, height, cover_data as jpeg). In addition the MetaInformation
|
||||||
|
objects can have a tag_order attribute.
|
||||||
'''
|
'''
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@ -286,17 +288,8 @@ class DevicePlugin(Plugin):
|
|||||||
Add locations to the booklists. This function must not communicate with
|
Add locations to the booklists. This function must not communicate with
|
||||||
the device.
|
the device.
|
||||||
@param locations: Result of a call to L{upload_books}
|
@param locations: Result of a call to L{upload_books}
|
||||||
@param metadata: List of dictionaries. Each dictionary must have the
|
@param metadata: List of MetaInformation objects, same as for
|
||||||
keys C{title}, C{authors}, C{author_sort}, C{cover}, C{tags}.
|
:method:`upload_books`.
|
||||||
The value of the C{cover}
|
|
||||||
element can be None or a three element tuple (width, height, data)
|
|
||||||
where data is the image data in JPEG format as a string. C{tags} must be
|
|
||||||
a possibly empty list of strings. C{authors} must be a string.
|
|
||||||
C{author_sort} may be None. It is upto the driver to decide whether to
|
|
||||||
use C{author_sort} or not.
|
|
||||||
The dictionary can also have an optional key "tag order" which should be
|
|
||||||
another dictionary that maps tag names to lists of book ids. The ids are
|
|
||||||
ids from the book database.
|
|
||||||
@param booklists: A tuple containing the result of calls to
|
@param booklists: A tuple containing the result of calls to
|
||||||
(L{books}(oncard=None), L{books}(oncard='carda'),
|
(L{books}(oncard=None), L{books}(oncard='carda'),
|
||||||
L{books}(oncard='cardb')).
|
L{books}(oncard='cardb')).
|
||||||
|
@ -54,8 +54,8 @@ class NOOK(USBMS):
|
|||||||
|
|
||||||
|
|
||||||
coverdata = getattr(metadata, 'thumbnail', None)
|
coverdata = getattr(metadata, 'thumbnail', None)
|
||||||
if coverdata:
|
if coverdata and coverdata[2]:
|
||||||
cover = Image.open(cStringIO.StringIO(coverdata))
|
cover = Image.open(cStringIO.StringIO(coverdata[2]))
|
||||||
else:
|
else:
|
||||||
coverdata = open(I('library.png'), 'rb').read()
|
coverdata = open(I('library.png'), 'rb').read()
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ class BookList(_BookList):
|
|||||||
return child
|
return child
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def add_book(self, info, name, size, ctime):
|
def add_book(self, mi, name, size, ctime):
|
||||||
""" Add a node into the DOM tree, representing a book """
|
""" Add a node into the DOM tree, representing a book """
|
||||||
book = self.book_by_path(name)
|
book = self.book_by_path(name)
|
||||||
if book is not None:
|
if book is not None:
|
||||||
@ -194,9 +194,9 @@ class BookList(_BookList):
|
|||||||
except:
|
except:
|
||||||
sourceid = '1'
|
sourceid = '1'
|
||||||
attrs = {
|
attrs = {
|
||||||
"title" : info["title"],
|
"title" : mi.title,
|
||||||
'titleSorter' : sortable_title(info['title']),
|
'titleSorter' : sortable_title(mi.title),
|
||||||
"author" : info["authors"] if info['authors'] else _('Unknown'),
|
"author" : mi.format_authors() if mi.format_authors() else _('Unknown'),
|
||||||
"page":"0", "part":"0", "scale":"0", \
|
"page":"0", "part":"0", "scale":"0", \
|
||||||
"sourceid":sourceid, "id":str(cid), "date":"", \
|
"sourceid":sourceid, "id":str(cid), "date":"", \
|
||||||
"mime":mime, "path":name, "size":str(size)
|
"mime":mime, "path":name, "size":str(size)
|
||||||
@ -205,8 +205,8 @@ class BookList(_BookList):
|
|||||||
node.setAttributeNode(self.document.createAttribute(attr))
|
node.setAttributeNode(self.document.createAttribute(attr))
|
||||||
node.setAttribute(attr, attrs[attr])
|
node.setAttribute(attr, attrs[attr])
|
||||||
try:
|
try:
|
||||||
w, h, data = info["cover"]
|
w, h, data = mi.thumbnail
|
||||||
except TypeError:
|
except:
|
||||||
w, h, data = None, None, None
|
w, h, data = None, None, None
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
@ -221,10 +221,15 @@ class BookList(_BookList):
|
|||||||
book = Book(node, self.mountpath, [], prefix=self.prefix)
|
book = Book(node, self.mountpath, [], prefix=self.prefix)
|
||||||
book.datetime = ctime
|
book.datetime = ctime
|
||||||
self.append(book)
|
self.append(book)
|
||||||
if info.has_key('tags'):
|
tags = []
|
||||||
if info.has_key('tag order'):
|
if mi.tags:
|
||||||
self.tag_order.update(info['tag order'])
|
tags.extend(mi.tags)
|
||||||
self.set_tags(book, info['tags'])
|
if mi.series:
|
||||||
|
tags.append(mi.series)
|
||||||
|
if tags:
|
||||||
|
if hasattr(mi, 'tag_order'):
|
||||||
|
self.tag_order.update(mi.tag_order)
|
||||||
|
self.set_tags(book, tags)
|
||||||
|
|
||||||
def _delete_book(self, node):
|
def _delete_book(self, node):
|
||||||
nid = node.getAttribute('id')
|
nid = node.getAttribute('id')
|
||||||
|
@ -400,7 +400,13 @@ class BooksModel(QAbstractTableModel):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def metadata_for(self, ids):
|
def metadata_for(self, ids):
|
||||||
return [self.db.get_metadata(id, index_is_id=True) for id in ids]
|
ans = []
|
||||||
|
for id in ids:
|
||||||
|
mi = self.db.get_metadata(id, index_is_id=True)
|
||||||
|
if mi.series is not None:
|
||||||
|
mi.tag_order = self.db.books_in_series_of(id, index_is_id=True)
|
||||||
|
ans.append(mi)
|
||||||
|
return ans
|
||||||
|
|
||||||
def get_metadata(self, rows, rows_are_ids=False, full_metadata=False):
|
def get_metadata(self, rows, rows_are_ids=False, full_metadata=False):
|
||||||
metadata, _full_metadata = [], []
|
metadata, _full_metadata = [], []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user