From 7d4bfe89b96504bc0f7dcbe0a66cb222c4e3a6cb Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 2 Jan 2009 18:44:53 -0500 Subject: [PATCH 1/2] Add support for html and rtf to cybook driver --- src/calibre/devices/cybookg3/books.py | 2 +- src/calibre/devices/cybookg3/driver.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/cybookg3/books.py b/src/calibre/devices/cybookg3/books.py index 5c15919ea6..fb385f5442 100644 --- a/src/calibre/devices/cybookg3/books.py +++ b/src/calibre/devices/cybookg3/books.py @@ -8,7 +8,7 @@ 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): diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index b397192cfe..5a3521d8c0 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -10,12 +10,12 @@ 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 From 51459386810206580046b5f640c18ccfab10627f Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 2 Jan 2009 19:26:47 -0500 Subject: [PATCH 2/2] Extract the title and author from filename when reading books from a Cybook --- src/calibre/devices/cybookg3/books.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/cybookg3/books.py b/src/calibre/devices/cybookg3/books.py index fb385f5442..b5859e40d0 100644 --- a/src/calibre/devices/cybookg3/books.py +++ b/src/calibre/devices/cybookg3/books.py @@ -37,11 +37,27 @@ def __init__(self, mountpath): self.return_books(mountpath) def return_books(self, mountpath): - books = []; + # 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, ""))