diff --git a/calibre-plugin/fff_plugin.py b/calibre-plugin/fff_plugin.py index 3e881ffa..5f623100 100644 --- a/calibre-plugin/fff_plugin.py +++ b/calibre-plugin/fff_plugin.py @@ -1958,14 +1958,17 @@ class FanFicFarePlugin(InterfaceAction): configuration = None if prefs['allow_custcol_from_ini']: configuration = get_fff_config(book['url'],options['fileform']) - # meta => custcol[,a|n|r] + # meta => custcol[,a|n|r|n_anthaver,r_anthaver] # cliches=>\#acolumn,r for line in configuration.getConfig('custom_columns_settings').splitlines(): if "=>" in line: (meta,custcol) = map( lambda x: x.strip(), line.split("=>") ) flag='r' + anthaver=False if "," in custcol: (custcol,flag) = map( lambda x: x.strip(), custcol.split(",") ) + anthaver = 'anthaver' in flag + flag=flag[0] # first char only. if meta not in book['all_metadata']: # if double quoted, use as a literal value. @@ -1987,8 +1990,15 @@ class FanFicFarePlugin(InterfaceAction): if flag == 'r' or (flag == 'n' and book['added']): if coldef['datatype'] in ('int','float'): # for favs, etc--site specific metadata. if 'anthology_meta_list' in book and meta in book['anthology_meta_list']: - # re-split list, strip commas, convert to floats, sum up. - val = sum([ float(x.replace(",","")) for x in val.split(", ") ]) + # re-split list, strip commas, convert to floats + items = [ float(x.replace(",","")) for x in val.split(", ") ] + if anthaver: + if items: + val = sum(items) / float(len(items)) + else: + val = 0 + else: + val = sum(items) else: val = unicode(val).replace(",","") else: diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index cc386d32..1dd3571d 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -1008,15 +1008,24 @@ cliches_label:Character Cliches ## 'mode'. 'r' to Replace any existing values, 'a' to Add to existing ## value (use with tag-like columns), and 'n' for setting on New books ## only. (Default is 'r'.) + ## Literal strings can be set into custom columns using double quotes. ## Each metadata=>column mapping must be on a separate line and each ## needs to have one space at the start of each line. +## 'r_anthaver' and 'n_anthaver' can be used to indicate the same as +## 'r' and 'n' for normal downloads, but to average the metadata for +## the differents story in an anthology before setting in integer and +## float type custom columns. This can be useful for a rating column, +## for example. Default is to sum the values of all stories, and +## numChapters and numWords are always summed. + #custom_columns_settings: # cliches=>#acolumn # themes=>#bcolumn,a # timeline=>#ccolumn,n # "FanFiction"=>#collection +# rating=>#rating,r_anthaver [efiction.esteliel.de] ## Site dedicated to these categories/characters/ships