mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Tweak to build collections of all books by title and by author
This commit is contained in:
parent
30c9bd1143
commit
041f4645fa
@ -180,6 +180,23 @@ sony_collection_renaming_rules={}
|
|||||||
# Default: empty (no rules), so no collection attributes are named.
|
# Default: empty (no rules), so no collection attributes are named.
|
||||||
sony_collection_sorting_rules = []
|
sony_collection_sorting_rules = []
|
||||||
|
|
||||||
|
# Specify whether special collections are to be made. The two available are
|
||||||
|
# all_by_author and all_by_title. These collections work around various device
|
||||||
|
# idiosyncrasies regarding sorting of lists. The all by author collection is
|
||||||
|
# sorted by author(s) then title. The by title collection is sorted by title
|
||||||
|
# then authors(s)
|
||||||
|
# Enable a collection by entering a collection name in the variable. That
|
||||||
|
# collection name must be unique.
|
||||||
|
# Examples:
|
||||||
|
# sony_all_books_by_author_collection = '%All by author'
|
||||||
|
# create a collection of all books sorted by author
|
||||||
|
# sony_all_books_by_title_collection = '%All by title'
|
||||||
|
# create a collection of books sorted by title, respecting the order tweaks
|
||||||
|
# sony_all_books_by_author_collection = ''
|
||||||
|
# disable the collection
|
||||||
|
sony_all_books_by_author_collection = ''
|
||||||
|
sony_all_books_by_title_collection = ''
|
||||||
|
|
||||||
|
|
||||||
# Create search terms to apply a query across several built-in search terms.
|
# Create search terms to apply a query across several built-in search terms.
|
||||||
# Syntax: {'new term':['existing term 1', 'term 2', ...], 'new':['old'...] ...}
|
# Syntax: {'new term':['existing term 1', 'term 2', ...], 'new':['old'...] ...}
|
||||||
|
@ -410,6 +410,9 @@ class XMLCache(object):
|
|||||||
newmi = book.deepcopy_metadata()
|
newmi = book.deepcopy_metadata()
|
||||||
newmi.template_to_attribute(book, plugboard)
|
newmi.template_to_attribute(book, plugboard)
|
||||||
newmi.set('_new_book', getattr(book, '_new_book', False))
|
newmi.set('_new_book', getattr(book, '_new_book', False))
|
||||||
|
book.set('_pb_title_sort',
|
||||||
|
newmi.get('title_sort', newmi.get('title', None)))
|
||||||
|
book.set('_pb_author_sort', newmi.get('author_sort', ''))
|
||||||
else:
|
else:
|
||||||
newmi = book
|
newmi = book
|
||||||
(gtz_count, ltz_count, use_tz_var) = \
|
(gtz_count, ltz_count, use_tz_var) = \
|
||||||
|
@ -132,9 +132,14 @@ class CollectionsBookList(BookList):
|
|||||||
use_renaming_rules = prefs['manage_device_metadata'] == 'on_connect'
|
use_renaming_rules = prefs['manage_device_metadata'] == 'on_connect'
|
||||||
|
|
||||||
collections = {}
|
collections = {}
|
||||||
# This map of sets is used to avoid linear searches when testing for
|
|
||||||
# book equality
|
all_by_author = tweaks['sony_all_books_by_author_collection']
|
||||||
|
all_by_title = tweaks['sony_all_books_by_title_collection']
|
||||||
|
|
||||||
for book in self:
|
for book in self:
|
||||||
|
tsval = book.get('_pb_title_sort',
|
||||||
|
book.get('title_sort', book.get('title', 'zzzz')))
|
||||||
|
asval = book.get('_pb_author_sort', book.get('author_sort', ''))
|
||||||
# Make sure we can identify this book via the lpath
|
# Make sure we can identify this book via the lpath
|
||||||
lpath = getattr(book, 'lpath', None)
|
lpath = getattr(book, 'lpath', None)
|
||||||
if lpath is None:
|
if lpath is None:
|
||||||
@ -211,22 +216,29 @@ class CollectionsBookList(BookList):
|
|||||||
collections[cat_name] = {}
|
collections[cat_name] = {}
|
||||||
if use_renaming_rules and sort_attr:
|
if use_renaming_rules and sort_attr:
|
||||||
sort_val = book.get(sort_attr, None)
|
sort_val = book.get(sort_attr, None)
|
||||||
collections[cat_name][lpath] = \
|
collections[cat_name][lpath] = (book, sort_val, tsval)
|
||||||
(book, sort_val, book.get('title_sort', 'zzzz'))
|
|
||||||
elif is_series:
|
elif is_series:
|
||||||
if doing_dc:
|
if doing_dc:
|
||||||
collections[cat_name][lpath] = \
|
collections[cat_name][lpath] = \
|
||||||
(book, book.get('series_index', sys.maxint),
|
(book, book.get('series_index', sys.maxint), tsval)
|
||||||
book.get('title_sort', 'zzzz'))
|
|
||||||
else:
|
else:
|
||||||
collections[cat_name][lpath] = \
|
collections[cat_name][lpath] = \
|
||||||
(book, book.get(attr+'_index', sys.maxint),
|
(book, book.get(attr+'_index', sys.maxint), tsval)
|
||||||
book.get('title_sort', 'zzzz'))
|
|
||||||
else:
|
else:
|
||||||
if lpath not in collections[cat_name]:
|
if lpath not in collections[cat_name]:
|
||||||
collections[cat_name][lpath] = \
|
collections[cat_name][lpath] = (book, tsval, tsval)
|
||||||
(book, book.get('title_sort', 'zzzz'),
|
|
||||||
book.get('title_sort', 'zzzz'))
|
# All books by author
|
||||||
|
if all_by_author:
|
||||||
|
if all_by_author not in collections:
|
||||||
|
collections[all_by_author] = {}
|
||||||
|
collections[all_by_author][lpath] = (book, asval, tsval)
|
||||||
|
# All books by title
|
||||||
|
if all_by_title:
|
||||||
|
if all_by_title not in collections:
|
||||||
|
collections[all_by_title] = {}
|
||||||
|
collections[all_by_title][lpath] = (book, tsval, asval)
|
||||||
|
|
||||||
# Sort collections
|
# Sort collections
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user