mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix handling of commas in author name when sending books to device. Fixes #1914 (author name scrambled?)
This commit is contained in:
parent
4a8811f691
commit
91087fa3bd
@ -150,10 +150,13 @@ class Device(object):
|
|||||||
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 dictionaries. Each dictionary must have the
|
||||||
keys C{title}, C{authors}, C{cover}, C{tags}. The value of the C{cover}
|
keys C{title}, C{authors}, C{author_sort}, C{cover}, C{tags}.
|
||||||
|
The value of the C{cover}
|
||||||
element can be None or a three element tuple (width, height, data)
|
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
|
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.
|
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
|
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
|
another dictionary that maps tag names to lists of book ids. The ids are
|
||||||
ids from the book database.
|
ids from the book database.
|
||||||
|
@ -55,7 +55,7 @@ class Book(object):
|
|||||||
|
|
||||||
title = book_metadata_field("title")
|
title = book_metadata_field("title")
|
||||||
authors = book_metadata_field("author", \
|
authors = book_metadata_field("author", \
|
||||||
formatter=lambda x: x if x and x.strip() else "Unknown")
|
formatter=lambda x: x if x and x.strip() else _('Unknown'))
|
||||||
mime = book_metadata_field("mime")
|
mime = book_metadata_field("mime")
|
||||||
rpath = book_metadata_field("path")
|
rpath = book_metadata_field("path")
|
||||||
id = book_metadata_field("id", formatter=int)
|
id = book_metadata_field("id", formatter=int)
|
||||||
@ -193,7 +193,7 @@ class BookList(_BookList):
|
|||||||
attrs = {
|
attrs = {
|
||||||
"title" : info["title"],
|
"title" : info["title"],
|
||||||
'titleSorter' : sortable_title(info['title']),
|
'titleSorter' : sortable_title(info['title']),
|
||||||
"author" : info["authors"] if info['authors'] else 'Unknown', \
|
"author" : info["authors"] if info['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)
|
||||||
|
@ -18,7 +18,7 @@ from calibre.ebooks.chardet import xml_to_unicode
|
|||||||
from calibre import relpath
|
from calibre import relpath
|
||||||
from calibre.constants import __appname__, __version__
|
from calibre.constants import __appname__, __version__
|
||||||
from calibre.ebooks.metadata.toc import TOC
|
from calibre.ebooks.metadata.toc import TOC
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation, string_to_authors
|
||||||
|
|
||||||
|
|
||||||
class Resource(object):
|
class Resource(object):
|
||||||
@ -614,7 +614,7 @@ class OPF(object):
|
|||||||
def fget(self):
|
def fget(self):
|
||||||
ans = []
|
ans = []
|
||||||
for elem in self.authors_path(self.metadata):
|
for elem in self.authors_path(self.metadata):
|
||||||
ans.extend([x.strip() for x in self.get_text(elem).split(',')])
|
ans.extend(string_to_authors(self.get_text(elem)))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def fset(self, val):
|
def fset(self, val):
|
||||||
@ -624,8 +624,8 @@ class OPF(object):
|
|||||||
for author in val:
|
for author in val:
|
||||||
attrib = {'{%s}role'%self.NAMESPACES['opf']: 'aut'}
|
attrib = {'{%s}role'%self.NAMESPACES['opf']: 'aut'}
|
||||||
elem = self.create_metadata_element('creator', attrib=attrib)
|
elem = self.create_metadata_element('creator', attrib=attrib)
|
||||||
self.set_text(elem, author)
|
self.set_text(elem, author.strip())
|
||||||
|
|
||||||
return property(fget=fget, fset=fset)
|
return property(fget=fget, fset=fset)
|
||||||
|
|
||||||
@apply
|
@apply
|
||||||
|
@ -180,11 +180,12 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.toolbar_button_size.setCurrentIndex(0 if icons == self.ICON_SIZES[0] else 1 if icons == self.ICON_SIZES[1] else 2)
|
self.toolbar_button_size.setCurrentIndex(0 if icons == self.ICON_SIZES[0] else 1 if icons == self.ICON_SIZES[1] else 2)
|
||||||
self.show_toolbar_text.setChecked(config['show_text_in_toolbar'])
|
self.show_toolbar_text.setChecked(config['show_text_in_toolbar'])
|
||||||
|
|
||||||
for ext in BOOK_EXTENSIONS:
|
book_exts = sorted(BOOK_EXTENSIONS)
|
||||||
|
for ext in book_exts:
|
||||||
self.single_format.addItem(ext.upper(), QVariant(ext))
|
self.single_format.addItem(ext.upper(), QVariant(ext))
|
||||||
|
|
||||||
single_format = config['save_to_disk_single_format']
|
single_format = config['save_to_disk_single_format']
|
||||||
self.single_format.setCurrentIndex(BOOK_EXTENSIONS.index(single_format))
|
self.single_format.setCurrentIndex(book_exts.index(single_format))
|
||||||
self.cover_browse.setValue(config['cover_flow_queue_length'])
|
self.cover_browse.setValue(config['cover_flow_queue_length'])
|
||||||
self.systray_notifications.setChecked(not config['disable_tray_notification'])
|
self.systray_notifications.setChecked(not config['disable_tray_notification'])
|
||||||
from calibre.translations.compiled import translations
|
from calibre.translations.compiled import translations
|
||||||
@ -203,7 +204,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.pdf_metadata.setChecked(prefs['read_file_metadata'])
|
self.pdf_metadata.setChecked(prefs['read_file_metadata'])
|
||||||
|
|
||||||
added_html = False
|
added_html = False
|
||||||
for ext in BOOK_EXTENSIONS:
|
for ext in book_exts:
|
||||||
ext = ext.lower()
|
ext = ext.lower()
|
||||||
ext = re.sub(r'(x{0,1})htm(l{0,1})', 'html', ext)
|
ext = re.sub(r'(x{0,1})htm(l{0,1})', 'html', ext)
|
||||||
if ext == 'lrf' or is_supported('book.'+ext):
|
if ext == 'lrf' or is_supported('book.'+ext):
|
||||||
|
@ -20,6 +20,7 @@ from calibre.gui2 import NONE, TableView, qstring_to_unicode, config, \
|
|||||||
error_dialog
|
error_dialog
|
||||||
from calibre.utils.search_query_parser import SearchQueryParser
|
from calibre.utils.search_query_parser import SearchQueryParser
|
||||||
from calibre.ebooks.metadata.meta import set_metadata as _set_metadata
|
from calibre.ebooks.metadata.meta import set_metadata as _set_metadata
|
||||||
|
from calibre.ebooks.metadata import string_to_authors
|
||||||
|
|
||||||
class LibraryDelegate(QItemDelegate):
|
class LibraryDelegate(QItemDelegate):
|
||||||
COLOR = QColor("blue")
|
COLOR = QColor("blue")
|
||||||
@ -364,12 +365,13 @@ class BooksModel(QAbstractTableModel):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_metadata(self, rows, rows_are_ids=False):
|
def get_metadata(self, rows, rows_are_ids=False, full_metadata=False):
|
||||||
metadata = []
|
metadata, _full_metadata = [], []
|
||||||
if not rows_are_ids:
|
if not rows_are_ids:
|
||||||
rows = [self.db.id(row.row()) for row in rows]
|
rows = [self.db.id(row.row()) for row in rows]
|
||||||
for id in rows:
|
for id in rows:
|
||||||
mi = self.db.get_metadata(id, index_is_id=True)
|
mi = self.db.get_metadata(id, index_is_id=True)
|
||||||
|
_full_metadata.append(mi)
|
||||||
au = authors_to_string(mi.authors if mi.authors else [_('Unknown')])
|
au = authors_to_string(mi.authors if mi.authors else [_('Unknown')])
|
||||||
tags = mi.tags if mi.tags else []
|
tags = mi.tags if mi.tags else []
|
||||||
if mi.series is not None:
|
if mi.series is not None:
|
||||||
@ -377,6 +379,7 @@ class BooksModel(QAbstractTableModel):
|
|||||||
info = {
|
info = {
|
||||||
'title' : mi.title,
|
'title' : mi.title,
|
||||||
'authors' : au,
|
'authors' : au,
|
||||||
|
'author_sort' : mi.author_sort,
|
||||||
'cover' : self.db.cover(id, index_is_id=True),
|
'cover' : self.db.cover(id, index_is_id=True),
|
||||||
'tags' : tags,
|
'tags' : tags,
|
||||||
'comments': mi.comments,
|
'comments': mi.comments,
|
||||||
@ -387,7 +390,10 @@ class BooksModel(QAbstractTableModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
metadata.append(info)
|
metadata.append(info)
|
||||||
return metadata
|
if full_metadata:
|
||||||
|
return metadata, _full_metadata
|
||||||
|
else:
|
||||||
|
return metadata
|
||||||
|
|
||||||
def get_preferred_formats_from_ids(self, ids, all_formats, mode='r+b'):
|
def get_preferred_formats_from_ids(self, ids, all_formats, mode='r+b'):
|
||||||
ans = []
|
ans = []
|
||||||
@ -928,12 +934,8 @@ class DeviceBooksModel(BooksModel):
|
|||||||
au = self.unknown
|
au = self.unknown
|
||||||
if role == Qt.EditRole:
|
if role == Qt.EditRole:
|
||||||
return QVariant(au)
|
return QVariant(au)
|
||||||
au = au.split(',')
|
authors = string_to_authors(au)
|
||||||
authors = []
|
return QVariant("\n".join(authors))
|
||||||
for i in au:
|
|
||||||
authors += i.strip().split('&')
|
|
||||||
jau = [ a.strip() for a in authors ]
|
|
||||||
return QVariant("\n".join(jau))
|
|
||||||
elif col == 2:
|
elif col == 2:
|
||||||
size = self.db[self.map[row]].size
|
size = self.db[self.map[row]].size
|
||||||
return QVariant(BooksView.human_readable(size))
|
return QVariant(BooksView.human_readable(size))
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
import os, sys, textwrap, collections, traceback, time
|
import os, sys, textwrap, collections, traceback, time
|
||||||
@ -910,12 +911,13 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
if not self.device_manager or not rows or len(rows) == 0:
|
if not self.device_manager or not rows or len(rows) == 0:
|
||||||
return
|
return
|
||||||
ids = iter(self.library_view.model().id(r) for r in rows)
|
ids = iter(self.library_view.model().id(r) for r in rows)
|
||||||
metadata = self.library_view.model().get_metadata(rows)
|
metadata, full_metadata = self.library_view.model().get_metadata(
|
||||||
|
rows, full_metadata=True)
|
||||||
for mi in metadata:
|
for mi in metadata:
|
||||||
cdata = mi['cover']
|
cdata = mi['cover']
|
||||||
if cdata:
|
if cdata:
|
||||||
mi['cover'] = self.cover_to_thumbnail(cdata)
|
mi['cover'] = self.cover_to_thumbnail(cdata)
|
||||||
metadata = iter(metadata)
|
metadata, full_metadata = iter(metadata), iter(full_metadata)
|
||||||
_files = self.library_view.model().get_preferred_formats(rows,
|
_files = self.library_view.model().get_preferred_formats(rows,
|
||||||
self.device_manager.device_class.FORMATS,
|
self.device_manager.device_class.FORMATS,
|
||||||
paths=True, set_metadata=True,
|
paths=True, set_metadata=True,
|
||||||
@ -923,22 +925,15 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
files = [getattr(f, 'name', None) for f in _files]
|
files = [getattr(f, 'name', None) for f in _files]
|
||||||
bad, good, gf, names, remove_ids = [], [], [], [], []
|
bad, good, gf, names, remove_ids = [], [], [], [], []
|
||||||
for f in files:
|
for f in files:
|
||||||
mi = metadata.next()
|
mi, smi = metadata.next(), full_metadata.next()
|
||||||
id = ids.next()
|
id = ids.next()
|
||||||
if f is None:
|
if f is None:
|
||||||
bad.append(mi['title'])
|
bad.append(mi['title'])
|
||||||
else:
|
else:
|
||||||
remove_ids.append(id)
|
remove_ids.append(id)
|
||||||
aus = mi['authors'].split(',')
|
|
||||||
aus2 = []
|
|
||||||
for a in aus:
|
|
||||||
aus2.extend(a.split('&'))
|
|
||||||
try:
|
try:
|
||||||
smi = MetaInformation(mi['title'], aus2)
|
with open(f, 'r+b') as _f:
|
||||||
smi.comments = mi.get('comments', None)
|
set_metadata(_f, smi, f.rpartition('.')[2])
|
||||||
_f = open(f, 'r+b')
|
|
||||||
set_metadata(_f, smi, f.rpartition('.')[2])
|
|
||||||
_f.close()
|
|
||||||
except:
|
except:
|
||||||
print 'Error setting metadata in book:', mi['title']
|
print 'Error setting metadata in book:', mi['title']
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user