While the Warnings collection can be important to some sites (for searching), once in Calibre it has less value (IMO) as a separate field. For example, AO3's warnings of "Graphic Depictions Of Violence" and "Major Character Death" I change to tags of "Violence" and "Death". However, I still prefer to shunt the non-normalized Warnings data into a separate field so I can more-easily notice data not currently covered by my normalization scheme.
To normalize in this fashion, I have to "move" the metadata between the conditional key (warnings, etc.) and the target key (extratags, category, etc.), which might look something like this:
Code:
add_to_replace_metadata:
extratags=>^(.*)$=>\1\,Violence&&warnings=>Graphic Depictions Of Violence
That code does not work though, because replace_matadata patterns will not find a match when looking for anything at all (^(.*)$). Not really sure why, but no matter. This limitation can be overcome by manually adding a "magic number"-type value to the target metakey. I'm not certain it would work in personal.ini as searching on ^(FanFiction)$ also failed, so I manually added one to the AO3's adapter file as a proof-of-concept test:
Code:
FanFicFare.zip\fanficfare\adapters\adapter_archiveofourownorg.py
...
#magic search pattern
self.story.addToList('freeformtags',"!")
a = metasoup.find('dd',{'class':"freeform tags"})
if a != None:
genres = a.findAll('a',{'class':"tag"})
for genre in genres:
self.story.addToList('freeformtags',genre.string)
...
This does get around the limitation of not being able to match something non-specific, like so:
Code:
personal.ini
...
[archiveofourown.org]
add_to_replace_metadata:
freeformtags=>^!$=>!\,Violence&&warnings=>Graphic Depictions Of Violence
exclude_metadata_post:
warnings=~^(Graphic Depictions Of Violence)$
freeformtags=~^!$
This sort of works. On an existing Calibre fic from AO3, the previously un-normalized Warning does successfully get transformed into a Tag during an Update Calibre Metadata from Website operation. However, if you do a full test with a new fic (or deleting and re-adding an existing story), this fails. How it fails is weird though. The "Graphic Depictions Of Violence" warning is not added to the Warnings field (is successfully excluded), but a "Violence" tag is not added to the Tags field (include_subject_tags: freeformtags).
I have not fully scrutinized the code behind replace_metadata, but this behavior leads me to suspect that the conditionalkey search might not be looking at all available data--both the current metadata in Calibre (if any), and the transitory metadata from the website (which may be excluded later). If so, I can't imagine that is working as intended, so it's a bug.