diff --git a/src/calibre/devices/cybookg3/books.py b/src/calibre/devices/cybookg3/books.py index 4e46faca42..9a1689af0b 100644 --- a/src/calibre/devices/cybookg3/books.py +++ b/src/calibre/devices/cybookg3/books.py @@ -8,39 +8,56 @@ import os, fnmatch, time from calibre.devices.interface import BookList as _BookList EBOOK_DIR = "eBooks" -EBOOK_TYPES = ['mobi', 'prc', 'pdf', 'txt'] +EBOOK_TYPES = ['mobi', 'prc', 'html', 'pdf', 'rtf', 'txt'] -class Book(object): - def __init__(self, path, title, authors): - self.title = title - self.authors = authors - self.size = os.path.getsize(path) - self.datetime = time.gmtime(os.path.getctime(path)) +class Book(object): + def __init__(self, path, title, authors): + self.title = title + self.authors = authors + self.size = os.path.getsize(path) + self.datetime = time.gmtime(os.path.getctime(path)) self.path = path - self.thumbnail = None - self.tags = [] + self.thumbnail = None + self.tags = [] - @apply - def thumbnail(): + @apply + def thumbnail(): return None - - def __str__(self): - """ Return a utf-8 encoded string with title author and path information """ - return self.title.encode('utf-8') + " by " + \ - self.authors.encode('utf-8') + " at " + self.path.encode('utf-8') + + def __str__(self): + """ Return a utf-8 encoded string with title author and path information """ + return self.title.encode('utf-8') + " by " + \ + self.authors.encode('utf-8') + " at " + self.path.encode('utf-8') -class BookList(_BookList): - def __init__(self, mountpath): - self._mountpath = mountpath - _BookList.__init__(self) +class BookList(_BookList): + def __init__(self, mountpath): + self._mountpath = mountpath + _BookList.__init__(self) self.return_books(mountpath) def return_books(self, mountpath): + # Get all books in all directories under the root EBOOK_DIR directory for path, dirs, files in os.walk(os.path.join(mountpath, EBOOK_DIR)): + # Filter out anything that isn't in the list of supported ebook types for book_type in EBOOK_TYPES: for filename in fnmatch.filter(files, '*.%s' % (book_type)): - self.append(Book(os.path.join(path, filename), filename, "")) + # Calibre uses a specific format for file names. They take the form + # title_-_author_number.extention We want to see if the file name is + # in this format. + if fnmatch.fnmatchcase(filename, '*_-_*.*'): + # Get the title and author from the file name + title, sep, author = filename.rpartition('_-_') + author, sep, ext = author.rpartition('_') + book_title = title.replace('_', ' ') + book_author = author.replace('_', ' ') + # if the filename did not match just set the title to + # the filename without the extension + else: + book_title = os.path.splitext(filename)[0].replace('_', ' ') + + book_path = os.path.join(path, filename) + self.append(Book(book_path, book_title, book_author)) def add_book(self, path, title): self.append(Book(path, title, "")) diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index 5eb6e3106c..5c4c1cfe24 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -10,12 +10,12 @@ from itertools import cycle from calibre.devices.interface import Device from calibre.devices.errors import DeviceError, FreeSpaceError -from calibre.devices.cybookg3.books import BookList, EBOOK_DIR +from calibre.devices.cybookg3.books import BookList, EBOOK_DIR, EBOOK_TYPES from calibre import iswindows, islinux, isosx, __appname__ class CYBOOKG3(Device): # Ordered list of supported formats - FORMATS = ["mobi", "prc", "pdf", "txt"] + FORMATS = EBOOK_TYPES VENDOR_ID = 0x0bda PRODUCT_ID = 0x0703 BCD = 0x110