From 972d3e600d8feb292d26f3105e30e3d8d5d3a90f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 5 Aug 2010 13:00:43 -0600 Subject: [PATCH] When generating filenames from a template remove prepositions from title and series names. Can be controlled by a tweak. --- resources/default_tweaks.py | 7 +++++++ src/calibre/library/save_to_disk.py | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index aaeb992151..d0f8e1b91b 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -72,4 +72,11 @@ gui_pubdate_display_format = 'MMM yyyy' # without changing anything is sufficient to change the sort. title_series_sorting = 'library_order' +# Control how title and series names are formatted when saving to disk/sending +# to device. If set to library_order, leading articles such as The and A will +# be put at the end +# If set to 'strictly_alphabetic', the titles will be sorted without processing +# For example, with library_order, "The Client" will become "Client, The". With +# strictly_alphabetic, it would remain "The Client". +save_template_title_series_sorting = 'library_order' diff --git a/src/calibre/library/save_to_disk.py b/src/calibre/library/save_to_disk.py index 8bbdbb0932..15020855f7 100644 --- a/src/calibre/library/save_to_disk.py +++ b/src/calibre/library/save_to_disk.py @@ -8,13 +8,13 @@ __docformat__ = 'restructuredtext en' import os, traceback, cStringIO, re -from calibre.utils.config import Config, StringConfig +from calibre.utils.config import Config, StringConfig, tweaks from calibre.utils.filenames import shorten_components_to, supports_long_names, \ ascii_filename, sanitize_file_name from calibre.ebooks.metadata.opf2 import metadata_to_opf from calibre.ebooks.metadata.meta import set_metadata from calibre.constants import preferred_encoding, filesystem_encoding - +from calibre.ebooks.metadata import title_sort from calibre import strftime DEFAULT_TEMPLATE = '{author_sort}/{title}/{title} - {authors}' @@ -110,9 +110,11 @@ def safe_format(x, format_args): def get_components(template, mi, id, timefmt='%b %Y', length=250, sanitize_func=ascii_filename, replace_whitespace=False, to_lowercase=False): + library_order = tweaks['save_template_title_series_sorting'] == 'library_order' + tsfmt = title_sort if library_order else lambda x: x format_args = dict(**FORMAT_ARGS) if mi.title: - format_args['title'] = mi.title + format_args['title'] = tsfmt(mi.title) if mi.authors: format_args['authors'] = mi.format_authors() format_args['author'] = format_args['authors'] @@ -123,7 +125,7 @@ def get_components(template, mi, id, timefmt='%b %Y', length=250, if format_args['tags'].startswith('/'): format_args['tags'] = format_args['tags'][1:] if mi.series: - format_args['series'] = mi.series + format_args['series'] = tsfmt(mi.series) if mi.series_index is not None: format_args['series_index'] = mi.format_series_index() else: