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:
|
if options.get_thumbnail:
|
||||||
print "Thumbnail:", td
|
print "Thumbnail:", td
|
||||||
if options.get_cover:
|
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:
|
if data:
|
||||||
cover = os.path.splitext(os.path.basename(args[1]))[0]+"_cover."+ext
|
cover = os.path.splitext(os.path.basename(args[1]))[0]+"_cover."+ext
|
||||||
open(cover, 'wb').write(data)
|
open(cover, 'wb').write(data)
|
||||||
|
@ -43,14 +43,17 @@ def metadata_from_formats(formats):
|
|||||||
for path in formats:
|
for path in formats:
|
||||||
ext = path_to_ext(path)
|
ext = path_to_ext(path)
|
||||||
stream = open(path, 'rb')
|
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:
|
if getattr(mi, 'application_id', None) is not None:
|
||||||
return mi
|
return mi
|
||||||
|
|
||||||
if not mi.title:
|
if not mi.title:
|
||||||
mi.title = 'Unknown'
|
mi.title = _('Unknown')
|
||||||
if not mi.authors:
|
if not mi.authors:
|
||||||
mi.authors = ['Unknown']
|
mi.authors = [_('Unknown')]
|
||||||
|
|
||||||
return mi
|
return mi
|
||||||
|
|
||||||
|
@ -320,7 +320,10 @@ class OPF(MetaInformation):
|
|||||||
|
|
||||||
def get_application_id(self):
|
def get_application_id(self):
|
||||||
for item in self.soup.package.metadata.findAll('dc:identifier'):
|
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 str(item.string).strip()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -361,10 +364,7 @@ class OPF(MetaInformation):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_rating(self):
|
def get_rating(self):
|
||||||
xm = self.soup.package.metadata.find('x-metadata')
|
s = self.soup.package.metadata.find('rating')
|
||||||
if not xm:
|
|
||||||
return None
|
|
||||||
s = xm.find('rating')
|
|
||||||
if s and s.string:
|
if s and s.string:
|
||||||
try:
|
try:
|
||||||
return int(str(s.string).strip())
|
return int(str(s.string).strip())
|
||||||
|
@ -86,10 +86,7 @@ class TOC(list):
|
|||||||
|
|
||||||
self.read_html_toc(toc)
|
self.read_html_toc(toc)
|
||||||
except:
|
except:
|
||||||
print 'WARNING: Could not read Table of Contents:'
|
print 'WARNING: Could not read Table of Contents. Continuing anyway.'
|
||||||
import traceback
|
|
||||||
traceback.print_exc(file=sys.stdout)
|
|
||||||
print 'Continuing anyway'
|
|
||||||
else:
|
else:
|
||||||
path = opfreader.manifest.item(toc.lower())
|
path = opfreader.manifest.item(toc.lower())
|
||||||
path = getattr(path, 'path', path)
|
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>')
|
files = _('<p>Books with the same title as the following already exist in the database. Add them anyway?<ul>')
|
||||||
for mi, formats in duplicates:
|
for mi, formats in duplicates:
|
||||||
files += '<li>'+mi.title+'</li>\n'
|
files += '<li>'+mi.title+'</li>\n'
|
||||||
d = question_dialog(self, _('Duplicates found!'), files+'</ul></p>')
|
d = WarningDialog(_('Duplicates found!'), _('Duplicates found!'), files+'</ul></p>', self)
|
||||||
if d.exec_() == QMessageBox.Yes:
|
if d.exec_() == QDialog.Accepted:
|
||||||
for mi, formats in duplicates:
|
for mi, formats in duplicates:
|
||||||
self.library_view.model().db.import_book(mi, formats )
|
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):
|
def import_book_directory(self, dirpath):
|
||||||
dirpath = os.path.abspath(dirpath)
|
dirpath = os.path.abspath(dirpath)
|
||||||
formats = []
|
formats = []
|
||||||
|
|
||||||
for path in os.listdir(dirpath):
|
for path in os.listdir(dirpath):
|
||||||
path = os.path.abspath(os.path.join(dirpath, path))
|
path = os.path.abspath(os.path.join(dirpath, path))
|
||||||
if os.path.isdir(path) or not os.access(path, os.R_OK):
|
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:
|
if not formats:
|
||||||
return
|
return
|
||||||
|
|
||||||
mi = metadata_from_formats(formats)
|
mi = metadata_from_formats(formats)
|
||||||
if mi.title is None:
|
if mi.title is None:
|
||||||
return
|
return
|
||||||
|
@ -206,7 +206,7 @@ class ResultCache(object):
|
|||||||
def index(self, id, cache=False):
|
def index(self, id, cache=False):
|
||||||
x = self._map if cache else self._map_filtered
|
x = self._map if cache else self._map_filtered
|
||||||
return x.index(id)
|
return x.index(id)
|
||||||
|
|
||||||
def row(self, id):
|
def row(self, id):
|
||||||
return self.index(id)
|
return self.index(id)
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ class ResultCache(object):
|
|||||||
temp = db.conn.execute('SELECT * FROM meta').fetchall()
|
temp = db.conn.execute('SELECT * FROM meta').fetchall()
|
||||||
# Fast mapping from ids to data.
|
# Fast mapping from ids to data.
|
||||||
# Can be None for ids that dont exist (i.e. have been deleted)
|
# 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:
|
for r in temp:
|
||||||
self._data[r[0]] = r
|
self._data[r[0]] = r
|
||||||
|
|
||||||
@ -639,6 +639,10 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
self.set_series(id, mi.series)
|
self.set_series(id, mi.series)
|
||||||
if mi.cover_data[1] is not None:
|
if mi.cover_data[1] is not None:
|
||||||
self.set_cover(id, mi.cover_data[1])
|
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)
|
self.set_path(id, True)
|
||||||
|
|
||||||
def set_authors(self, id, authors):
|
def set_authors(self, id, authors):
|
||||||
@ -679,9 +683,12 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
aid = self.conn.execute('INSERT INTO series(name) VALUES (?)', (series,)).lastrowid
|
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.execute('INSERT INTO books_series_link(book, series) VALUES (?,?)', (id, aid))
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
row = self.row(id)
|
try:
|
||||||
if row is not None:
|
row = self.row(id)
|
||||||
self.data.set(row, 9, series)
|
if row is not None:
|
||||||
|
self.data.set(row, 9, series)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
def set_series_index(self, id, idx):
|
def set_series_index(self, id, idx):
|
||||||
if idx is None:
|
if idx is None:
|
||||||
@ -689,9 +696,12 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
idx = int(idx)
|
idx = int(idx)
|
||||||
self.conn.execute('UPDATE books SET series_index=? WHERE id=?', (int(idx), id))
|
self.conn.execute('UPDATE books SET series_index=? WHERE id=?', (int(idx), id))
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
row = self.row(id)
|
try:
|
||||||
if row is not None:
|
row = self.row(id)
|
||||||
self.data.set(row, 10, idx)
|
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):
|
def add_books(self, paths, formats, metadata, uris=[], add_duplicates=True):
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user