It is doable (my coding skils are not quite up to this) in Program Mode
Take a look at
http://manual.calibre-ebook.com/template_lang.html
class calibre.utils.formatter_functions.BuiltinCurrentLi braryName[source]
You should be able to use:
current_library_name() – return the last name on the path to the current calibre library. This function can be called in template program mode using the template “{:’current_library_name()’}”.
With a
switch(val, pattern, value, pattern, value, ..., else_value)