diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index 4dd27ce0..f64b8d2c 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -344,12 +344,21 @@ anthology_title_pattern:${title} Anthology ## any anthology tags. anthology_tags:Anthology -## Reorder ships so b/a and c/b/a become a/b and a/b/c. Only separates -## on '/', so use replace_metadata to change separator first if -## needed. Something like: ships=>[ ]*(/|&|&)[ ]*=>/ You can use -## ships_LIST to change the / back to something else if you want. +## Reorder ships so b/a and c/b/a become a/b and a/b/c. '/' is no +## longer hard coded and can be changed and added to with +## sort_ships_splits. sort_ships:false +## Each line indicates first a regex that should be used to split each +## ships entry and then, after => the string to use to merge the parts +## back together. \s == blank space. +## Each part will have replace_metadata with key ships_CHARS applied. +## By default, sort_ships_splits:/=>/ +## Here's possible an example for AO3: +#sort_ships_splits: +# [ ]*/[ ]*=>/ +# [ ]*&[ ]*=>\s&\s + ## join_string_ options -- FanFicFare list entries are comma ## separated by default. You can use this to change that. For example, ## if you want authors separated with ' & ' instead, use diff --git a/fanficfare/configurable.py b/fanficfare/configurable.py index 14cbc099..71bf187f 100644 --- a/fanficfare/configurable.py +++ b/fanficfare/configurable.py @@ -302,6 +302,7 @@ def get_valid_keywords(): 'replace_metadata', 'slow_down_sleep_time', 'sort_ships', + 'sort_ships_splits', 'strip_chapter_numbers', 'strip_chapter_numeral', 'strip_text_links', diff --git a/fanficfare/defaults.ini b/fanficfare/defaults.ini index 9e8c14b5..d09c672d 100644 --- a/fanficfare/defaults.ini +++ b/fanficfare/defaults.ini @@ -343,12 +343,21 @@ chapter_title_new_pattern:(new) ${title} ## (new) is just text and can be changed. chapter_title_addnew_pattern:${index}. (new) ${title} -## Reorder ships so b/a and c/b/a become a/b and a/b/c. Only separates -## on '/', so use replace_metadata to change separator first if -## needed. Something like: ships=>[ ]*(/|&|&)[ ]*=>/ You can use -## ships_LIST to change the / back to something else if you want. +## Reorder ships so b/a and c/b/a become a/b and a/b/c. '/' is no +## longer hard coded and can be changed and added to with +## sort_ships_splits. sort_ships:false +## Each line indicates first a regex that should be used to split each +## ships entry and then, after => the string to use to merge the parts +## back together. \s == blank space. +## Each part will have replace_metadata with key ships_CHARS applied. +## By default, sort_ships_splits:/=>/ +## Here's possible an example for AO3: +#sort_ships_splits: +# [ ]*/[ ]*=>/ +# [ ]*&[ ]*=>\s&\s + ## join_string_ options -- FanFicFare list entries are comma ## separated by default. You can use this to change that. For example, ## if you want authors separated with ' & ' instead, use diff --git a/fanficfare/story.py b/fanficfare/story.py index 6b45b096..761e782b 100644 --- a/fanficfare/story.py +++ b/fanficfare/story.py @@ -793,6 +793,33 @@ class Story(Configurable): if retlist is None: retlist = [] + # reorder ships so b/a and c/b/a become a/b and a/b/c. Only on '/', + # use replace_metadata to change separator first if needed. + # ships=>[ ]*(/|&|&)[ ]*=>/ + if listname == 'ships' and self.getConfig('sort_ships') and retlist: + # retlist = [ '/'.join(sorted(x.split('/'))) for x in retlist ] + ## empty default of /=>/ + sort_ships_splits = self.getConfig('sort_ships_splits',"/=>/") + + for line in sort_ships_splits.splitlines(): + if line: + logger.debug("sort_ships_splits:%s"%line) + logger.debug(retlist) + (splitre,splitmerge) = line.split("=>") + splitmerge = splitmerge.replace(SPACE_REPLACE,' ') + newretlist = [] + for x in retlist: + curlist = [] + for y in re.split(splitre,x): + ## for SPLIT_META(\,) + if doreplacements: + y = self.doReplacements(y,'ships_CHARS',return_list=True) + curlist.extend(y) + newretlist.append( splitmerge.join(sorted(curlist)) ) + + retlist = newretlist + logger.debug(retlist) + if retlist: if doreplacements: newretlist = [] @@ -812,12 +839,6 @@ class Story(Configurable): )) > 1: retlist.append(self.getConfig('add_genre_when_multi_category')) - # reorder ships so b/a and c/b/a become a/b and a/b/c. Only on '/', - # use replace_metadata to change separator first if needed. - # ships=>[ ]*(/|&|&)[ ]*=>/ - if listname == 'ships' and self.getConfig('sort_ships') and retlist: - retlist = [ '/'.join(sorted(x.split('/'))) for x in retlist ] - if retlist: if listname in ('author','authorUrl','authorId') or self.getConfig('keep_in_order_'+listname): # need to retain order for author & authorUrl so the