mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Extract the title and author from filename when reading books from a Cybook
This commit is contained in:
parent
7d4bfe89b9
commit
5145938681
@ -37,11 +37,27 @@ class BookList(_BookList):
|
||||
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, ""))
|
||||
|
Loading…
x
Reference in New Issue
Block a user