From df622dfbf022077ba9cb8fa6f682872309a4c911 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Tue, 21 Jan 2014 20:42:04 -0600 Subject: [PATCH] Allow literal strings in custom_columns_settings to set columns. --- calibre-plugin/ffdl_plugin.py | 21 ++++++++++++++------- plugin-defaults.ini | 4 +++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/calibre-plugin/ffdl_plugin.py b/calibre-plugin/ffdl_plugin.py index 50050b2..0fea38a 100644 --- a/calibre-plugin/ffdl_plugin.py +++ b/calibre-plugin/ffdl_plugin.py @@ -1546,8 +1546,15 @@ class FanFictionDownLoaderPlugin(InterfaceAction): (custcol,flag) = map( lambda x: x.strip(), custcol.split(",") ) if meta not in book['all_metadata']: - logger.debug("No value for %s, skipping custom column(%s) update."%(meta,custcol)) - continue + # if double quoted, use as a literal value. + if meta[0] == '"' and meta[-1] == '"': + val = meta[1:-1] + logger.debug("No metadata value for %s, setting custom column(%s) literally to %s."%(meta,custcol,val)) + else: + logger.debug("No value for %s, skipping custom column(%s) update."%(meta,custcol)) + continue + else: + val = book['all_metadata'][meta] if custcol not in custom_columns: continue @@ -1559,11 +1566,11 @@ class FanFictionDownLoaderPlugin(InterfaceAction): 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 book['all_metadata'][meta].split(", ") ]) + val = sum([ float(x.replace(",","")) for x in val.split(", ") ]) else: - val = unicode(book['all_metadata'][meta]).replace(",","") + val = unicode(val).replace(",","") else: - val = book['all_metadata'][meta] + val = val if val != '': db.set_custom(book_id, val, label=label, commit=False) @@ -1578,8 +1585,8 @@ class FanFictionDownLoaderPlugin(InterfaceAction): except: pass - if book['all_metadata'][meta]: - vallist = [book['all_metadata'][meta]] + if val: + vallist = [val] db.set_custom(book_id, ", ".join(vallist), label=label, commit=False) diff --git a/plugin-defaults.ini b/plugin-defaults.ini index bceece1..748c1bc 100644 --- a/plugin-defaults.ini +++ b/plugin-defaults.ini @@ -691,13 +691,15 @@ 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. #custom_columns_settings: -# cliches=>#acolumn,r +# cliches=>#acolumn # themes=>#bcolumn,a # timeline=>#ccolumn,n +# "FanFiction"=>#collection [efiction.esteliel.de] ## Site dedicated to these categories/characters/ships