From 910e2de0346ab84685d524c26c33799f9d9805a6 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 11 Jan 2009 19:34:44 -0500 Subject: [PATCH] Global mime mapping for ebook types --- src/calibre/devices/cybookg3/driver.py | 11 ++--------- src/calibre/devices/kindle/driver.py | 8 +------- src/calibre/devices/usbms/driver.py | 13 +++++++------ 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index 7ab9a909a0..3737de3d7d 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -9,16 +9,9 @@ import os, fnmatch from calibre.devices.usbms.driver import USBMS class CYBOOKG3(USBMS): - MIME_MAP = { - 'mobi' : 'application/mobi', - 'prc' : 'application/prc', - 'html' : 'application/html', - 'pdf' : 'application/pdf', - 'rtf' : 'application/rtf', - 'txt' : 'text/plain', - } # Ordered list of supported formats - FORMATS = MIME_MAP.keys() + # Be sure these have an entry in calibre.devices.mime + FORMATS = ['mobi', 'prc', 'html', 'pdf', 'rtf', 'txt'] VENDOR_ID = 0x0bda PRODUCT_ID = 0x0703 diff --git a/src/calibre/devices/kindle/driver.py b/src/calibre/devices/kindle/driver.py index 4313f24847..d5ef7008bc 100755 --- a/src/calibre/devices/kindle/driver.py +++ b/src/calibre/devices/kindle/driver.py @@ -9,14 +9,8 @@ import os, fnmatch from calibre.devices.usbms.driver import USBMS class KINDLE(USBMS): - MIME_MAP = { - 'azw' : 'application/azw', - 'mobi' : 'application/mobi', - 'prc' : 'application/prc', - 'txt' : 'text/plain', - } # Ordered list of supported formats - FORMATS = MIME_MAP.keys() + FORMATS = ['azw', 'mobi', 'prc', 'txt'] VENDOR_ID = 0x1949 PRODUCT_ID = 0x0001 diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index ba89db29c9..7e5706f4ea 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -12,11 +12,11 @@ from itertools import cycle from calibre.devices.usbms.device import Device from calibre.devices.usbms.books import BookList, Book from calibre.devices.errors import FreeSpaceError +from calibre.devices.mime import MIME_MAP class USBMS(Device): EBOOK_DIR_MAIN = '' EBOOK_DIR_CARD = '' - MIME_MAP = {} FORMATS = [] def __init__(self, key='-1', log_packets=False, report_progress=None): @@ -41,7 +41,7 @@ class USBMS(Device): # Get all books in all directories under the root ebook_dir directory for path, dirs, files in os.walk(os.path.join(prefix, ebook_dir)): # Filter out anything that isn't in the list of supported ebook types - for book_type in self.MIME_MAP.keys(): + for book_type in self.FORMATS: for filename in fnmatch.filter(files, '*.%s' % (book_type)): title, author, mime = self.__class__.extract_book_metadata_by_filename(filename) @@ -138,10 +138,11 @@ class USBMS(Device): else: book_title = os.path.splitext(filename)[0].replace('_', ' ') - fileext = os.path.splitext(filename)[1] - if fileext in cls.MIME_MAP.keys(): - book_mime = cls.MIME_MAP[fileext] - + fileext = os.path.splitext(filename)[1][1:] + + if fileext in cls.FORMATS: + book_mime = MIME_MAP[fileext] if fileext in MIME_MAP.keys() else 'Unknown' + return book_title, book_author, book_mime # ls, rm, cp, mkdir, touch, cat