mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Fix regression that was causing rating,tags,series and comments data to not be re-imported when importing books that had been previously saved to disk.
This commit is contained in:
parent
829a344fe9
commit
82e38e4d09
@ -676,7 +676,10 @@ def main(args=sys.argv):
|
||||
if options.get_thumbnail:
|
||||
print "Thumbnail:", td
|
||||
if options.get_cover:
|
||||
ext, data = lrf.get_cover()
|
||||
try:
|
||||
ext, data = lrf.get_cover()
|
||||
except: # Fails on books created by LRFCreator 1.0
|
||||
ext, data = None, None
|
||||
if data:
|
||||
cover = os.path.splitext(os.path.basename(args[1]))[0]+"_cover."+ext
|
||||
open(cover, 'wb').write(data)
|
||||
|
@ -43,14 +43,17 @@ def metadata_from_formats(formats):
|
||||
for path in formats:
|
||||
ext = path_to_ext(path)
|
||||
stream = open(path, 'rb')
|
||||
mi.smart_update(get_metadata(stream, stream_type=ext, use_libprs_metadata=True))
|
||||
try:
|
||||
mi.smart_update(get_metadata(stream, stream_type=ext, use_libprs_metadata=True))
|
||||
except:
|
||||
continue
|
||||
if getattr(mi, 'application_id', None) is not None:
|
||||
return mi
|
||||
|
||||
if not mi.title:
|
||||
mi.title = 'Unknown'
|
||||
mi.title = _('Unknown')
|
||||
if not mi.authors:
|
||||
mi.authors = ['Unknown']
|
||||
mi.authors = [_('Unknown')]
|
||||
|
||||
return mi
|
||||
|
||||
|
@ -320,7 +320,10 @@ class OPF(MetaInformation):
|
||||
|
||||
def get_application_id(self):
|
||||
for item in self.soup.package.metadata.findAll('dc:identifier'):
|
||||
if item.has_key('scheme') and item['scheme'] == __appname__:
|
||||
scheme = item.get('scheme', None)
|
||||
if scheme is None:
|
||||
scheme = item.get('opf:scheme', None)
|
||||
if scheme in ['libprs500', 'calibre']:
|
||||
return str(item.string).strip()
|
||||
return None
|
||||
|
||||
@ -361,10 +364,7 @@ class OPF(MetaInformation):
|
||||
return None
|
||||
|
||||
def get_rating(self):
|
||||
xm = self.soup.package.metadata.find('x-metadata')
|
||||
if not xm:
|
||||
return None
|
||||
s = xm.find('rating')
|
||||
s = self.soup.package.metadata.find('rating')
|
||||
if s and s.string:
|
||||
try:
|
||||
return int(str(s.string).strip())
|
||||
|
@ -86,10 +86,7 @@ class TOC(list):
|
||||
|
||||
self.read_html_toc(toc)
|
||||
except:
|
||||
print 'WARNING: Could not read Table of Contents:'
|
||||
import traceback
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
print 'Continuing anyway'
|
||||
print 'WARNING: Could not read Table of Contents. Continuing anyway.'
|
||||
else:
|
||||
path = opfreader.manifest.item(toc.lower())
|
||||
path = getattr(path, 'path', path)
|
||||
|
@ -422,8 +422,8 @@ in which you want to store your books files. Any existing books will be automati
|
||||
files = _('<p>Books with the same title as the following already exist in the database. Add them anyway?<ul>')
|
||||
for mi, formats in duplicates:
|
||||
files += '<li>'+mi.title+'</li>\n'
|
||||
d = question_dialog(self, _('Duplicates found!'), files+'</ul></p>')
|
||||
if d.exec_() == QMessageBox.Yes:
|
||||
d = WarningDialog(_('Duplicates found!'), _('Duplicates found!'), files+'</ul></p>', self)
|
||||
if d.exec_() == QDialog.Accepted:
|
||||
for mi, formats in duplicates:
|
||||
self.library_view.model().db.import_book(mi, formats )
|
||||
|
||||
|
@ -1513,7 +1513,6 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
def import_book_directory(self, dirpath):
|
||||
dirpath = os.path.abspath(dirpath)
|
||||
formats = []
|
||||
|
||||
for path in os.listdir(dirpath):
|
||||
path = os.path.abspath(os.path.join(dirpath, path))
|
||||
if os.path.isdir(path) or not os.access(path, os.R_OK):
|
||||
@ -1528,6 +1527,7 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
|
||||
if not formats:
|
||||
return
|
||||
|
||||
mi = metadata_from_formats(formats)
|
||||
if mi.title is None:
|
||||
return
|
||||
|
@ -206,7 +206,7 @@ class ResultCache(object):
|
||||
def index(self, id, cache=False):
|
||||
x = self._map if cache else self._map_filtered
|
||||
return x.index(id)
|
||||
|
||||
|
||||
def row(self, id):
|
||||
return self.index(id)
|
||||
|
||||
@ -226,7 +226,7 @@ class ResultCache(object):
|
||||
temp = db.conn.execute('SELECT * FROM meta').fetchall()
|
||||
# Fast mapping from ids to data.
|
||||
# Can be None for ids that dont exist (i.e. have been deleted)
|
||||
self._data = list(itertools.repeat(None, temp[-1][0]+2))
|
||||
self._data = list(itertools.repeat(None, temp[-1][0]+2)) if temp else []
|
||||
for r in temp:
|
||||
self._data[r[0]] = r
|
||||
|
||||
@ -639,6 +639,10 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
self.set_series(id, mi.series)
|
||||
if mi.cover_data[1] is not None:
|
||||
self.set_cover(id, mi.cover_data[1])
|
||||
if mi.tags:
|
||||
self.set_tags(id, mi.tags)
|
||||
if mi.comments:
|
||||
self.set_comment(id, mi.comments)
|
||||
self.set_path(id, True)
|
||||
|
||||
def set_authors(self, id, authors):
|
||||
@ -679,9 +683,12 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
aid = self.conn.execute('INSERT INTO series(name) VALUES (?)', (series,)).lastrowid
|
||||
self.conn.execute('INSERT INTO books_series_link(book, series) VALUES (?,?)', (id, aid))
|
||||
self.conn.commit()
|
||||
row = self.row(id)
|
||||
if row is not None:
|
||||
self.data.set(row, 9, series)
|
||||
try:
|
||||
row = self.row(id)
|
||||
if row is not None:
|
||||
self.data.set(row, 9, series)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def set_series_index(self, id, idx):
|
||||
if idx is None:
|
||||
@ -689,9 +696,12 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
idx = int(idx)
|
||||
self.conn.execute('UPDATE books SET series_index=? WHERE id=?', (int(idx), id))
|
||||
self.conn.commit()
|
||||
row = self.row(id)
|
||||
if row is not None:
|
||||
self.data.set(row, 10, idx)
|
||||
try:
|
||||
row = self.row(id)
|
||||
if row is not None:
|
||||
self.data.set(row, 10, idx)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def add_books(self, paths, formats, metadata, uris=[], add_duplicates=True):
|
||||
'''
|
||||
|
Loading…
x
Reference in New Issue
Block a user