diff --git a/lazylibrarian/librarysync.py b/lazylibrarian/librarysync.py index 757cb6a95..bebebb0db 100644 --- a/lazylibrarian/librarysync.py +++ b/lazylibrarian/librarysync.py @@ -449,11 +449,10 @@ def LibraryScan(startdir=None, library='eBook', authid=None, remove=True): extn = os.path.splitext(files)[1] # if it's an epub or a mobi we can try to read metadata from it - if (extn == ".epub") or (extn == ".mobi"): + if extn in [".epub", ".mobi"]: book_filename = os.path.join(rootdir, files) if PY2: book_filename = book_filename.encode(lazylibrarian.SYS_ENCODING) - try: res = get_book_info(book_filename) except Exception as e: diff --git a/lazylibrarian/postprocess.py b/lazylibrarian/postprocess.py index 9788c5029..84482599f 100644 --- a/lazylibrarian/postprocess.py +++ b/lazylibrarian/postprocess.py @@ -105,10 +105,14 @@ def processAlternate(source_dir=None): logger.debug('No metadata file found for %s' % new_book) if 'title' not in metadata or 'creator' not in metadata: # if not got both, try to get metadata from the book file - try: - metadata = get_book_info(new_book) - except Exception as e: - logger.debug('No metadata found in %s, %s %s' % (new_book, type(e).__name__, str(e))) + extn = os.path.splitext(new_book)[1] + if extn in [".epub", ".mobi"]: + if PY2: + new_book = new_book.encode(lazylibrarian.SYS_ENCODING) + try: + metadata = get_book_info(new_book) + except Exception as e: + logger.debug('No metadata found in %s, %s %s' % (new_book, type(e).__name__, str(e))) if 'title' in metadata and 'creator' in metadata: authorname = metadata['creator'] bookname = metadata['title'] diff --git a/lazylibrarian/webServe.py b/lazylibrarian/webServe.py index 805ed6a6b..362320a81 100644 --- a/lazylibrarian/webServe.py +++ b/lazylibrarian/webServe.py @@ -1892,7 +1892,7 @@ def editBook(self, bookid=None): @cherrypy.expose def bookUpdate(self, bookname='', bookid='', booksub='', bookgenre='', booklang='', - manual='0', authorname='', cover='', **kwargs): + manual='0', authorname='', cover='', newid='', **kwargs): myDB = database.DBConnection() if bookid: @@ -1905,6 +1905,17 @@ def bookUpdate(self, bookname='', bookid='', booksub='', bookgenre='', booklang= if bookgenre == 'None': bookgenre = '' manual = bool(check_int(manual, 0)) + + if not (bookid == newid): + cmd = "SELECT BookName,Authorname from books,authors " + cmd += "WHERE books.AuthorID = authors.AuthorID and BookID=?" + match = myDB.match(cmd, (newid,)) + if match: + logger.warn("Cannot change bookid to %s, in use by %s/%s" % + (newid, match['BookName'], match['AuthorName'])) + else: + logger.warn("Updating bookid is not supported yet") + # edited += "BookID " if not (bookdata["BookName"] == bookname): edited += "Title " if not (bookdata["BookSub"] == booksub): @@ -2001,6 +2012,7 @@ def bookUpdate(self, bookname='', bookid='', booksub='', bookgenre='', booklang= else: logger.debug('Book [%s] has not been moved' % bookname) # if edited or moved: + raise cherrypy.HTTPRedirect("editBook?bookid=%s" % bookid) raise cherrypy.HTTPRedirect("books") diff --git a/lib/mobi/__init__.py b/lib/mobi/__init__.py index c17a446d3..f68d26573 100644 --- a/lib/mobi/__init__.py +++ b/lib/mobi/__init__.py @@ -13,6 +13,7 @@ from struct import * from pprint import pprint from lib.six import PY2 + if PY2: import utils from lz77 import uncompress_lz77 @@ -358,7 +359,10 @@ def parseMobiHeader(self): self.offset += resultsDict['header length']; def onebits(x, width=16): - return len(filter(lambda x: x == "1", (str((x>>i)&1) for i in xrange(width-1,-1,-1)))); + if PY2: + return len(filter(lambda x: x == "1", (str((x>>i)&1) for i in xrange(width-1,-1,-1)))); + else: + return len([x for x in (str((x>>i)&1) for i in range(width-1,-1,-1)) if x == "1"]); resultsDict['extra bytes'] = 2*onebits(unpack(">H", self.contents[self.offset-2:self.offset])[0] & 0xFFFE)