Grand Sorcerer
Posts: 11,734
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Plugboard, template, and custom composite column recipes
Several people are doing interesting and useful things with templates, plugboards, and composite fields. This thread is both a request that they share what they have done and a place to put the information.
Suggestions/recipes are summarized below. Don't hesitate to post corrections and useful variants.
Kindle/Kobo- Metadata: Show series - series Index - Title as Title (Kindle/Kobo) (economix)
Spoiler:
I have been playing around with the Metadata plugboards to get the titles on a Kindle 3 to show series information. I used the following template:
format: mobi
device: kindle2
template: {series}{series_index:0>2s| - | - }{title}
destination: title
This works very nicely for books that are part of a series e.g.:
Quote:
A Song of Ice & Fire - 01 - A Game of Thrones
A Song of Ice & Fire - 02 - A Clash of Kings
A Song of Ice & Fire - 03 - A Storm of Swords
A Song of Ice & Fire - 04 - A Feast for Crows
|
- Metadata: Show series [series index] - title as title (Kindle) (Scott Nielsen)
- Metadata: Show author name as Initial and Surname (Kindle) (inspired by brewjono)
- Reading/read status custom column (Kindle) (pchrist7, w/ideas from beckywc):
Filename (Save Templates)- Filename: author sort/series/title - version (WinCE/Mobile (Mobipocket))(sweetpea)
- Filename: Create file paths grouping authors into [A - D]-like categories (WinCE/Mobile (Mobipocket)) (Sweetpea)
Spoiler:
{author_sort:switch(^[A-D],[A - D],^[E-J],[E - J],^[K-O],[K - O],^[P-T],[P - T],^[U-Z],[U - Z],[Other])}
- Filename: Create path based on series index (sweetpea, inspired by Arco Witter)
Spoiler:
If you have a lot of books in a series, and want them in a folder hierarchy like series/00-09/author/title, series/10-19/author/title. You want just author/title if there is no series.
Create a composite column called (for example) #s_index.
Column: #s_dex
Template: {series_index:0>2s}
Save template:
Code:
{series}{#s_dex:switch(0.,00-09,1.,10-19,2.,20-29,3.,30-39,4.,40-49,5.,50-59,6.,60-69,7.,70-79,8.,80-89,9.,90-99,)|/|/}{author}/{title}
General Metadata- Metadata: Put series into the title, using either initials or a shortened form. Strip leading articles from the series name (any) (inspired by Gary_M_Mugford)
Spoiler:
The solution requires creating three composite columns. The first column is used to remove the leading articles. The second is used to compute the 'shorten' form. The third is to compute the 'initials' form. Once you have these columns, the plugboard selects between them. You can hide any or all of the three columns on the library view.
First column:
Code:
Name: #stripped_series. Template: {series:re(^(A|The|An)\s+,)||}
Second column (the shortened form):
Code:
Name: #shortened. Template: {#stripped_series:shorten(4,-,4)}
Third column (the initials form) (Modified/corrected by eschwartz 6/Jan/14):
Code:
Name: #initials. Template: {#stripped_series:re([\s]?([^\s])[^\s]+(\s|$),\1)}
Plugboard expression:
Code:
Template:{#stripped_series:lookup(.\s,#initials,.,#shortened,series)}{series_index:0>2s| [|] }{title}
Destination field: title
This set of fields and plugboard produces:
Series: The Lord of the Rings
Series index: 2
Title: The Two Towers
Output: LotR [02] The Two Towers
Series: Dahak
Series index: 1
Title: Mutineers Moon
Output: Dahak [01] Mutineers Moon
Series: Berserkers
Series Index: 4
Title: Berserker Throne
Output: Bers-kers [04] Berserker Throne
Series: Meg Langslow Mysteries
Series Index: 3
Title: Revenge of the Wrought-Iron Flamingos
Output: MLM [03] Revenge of the Wrought-Iron Flamingos
- Author pen names.
Spoiler:
Use User categories and templates to manage multiple pen names for authors. See this thread, in particular posts #7 and #15.
Useful stored templates
- Get the lookup name of the current column in the books view:
Spoiler:
Stored template:
Code:
python:
def evaluate(book, context):
from calibre.gui2.ui import get_gui
gui = get_gui()
cv = get_gui().current_view()
return cv.column_map[cv.currentIndex().column()]
Preferences / Stored templates screen capture:
Example:
Code:
current_column_name = current_column();
column_value = field(current_column_name)
- Check if a date is less than another:
Spoiler:
Stored template:
Code:
python:
def evaluate(book, context):
args = context.arguments
if args is None or len(args) != 2:
return "date_less_than requires 2 arguments"
d1 = book.get(args[0])
d2 = book.get(args[1])
if d1 is None or d2 is None:
return '' # return no if either date isn't defined
return 'Yes' if d1 < d2 else ''
Preferences / Stored templates screen capture:
Example:
Code:
if date_less_than('#mydate1', '#mydate2') == 'Yes' then something fi
Template Searches
Common composite custom columns
All the recipes below require the creation of a custom column of type 'Column built from other columns', called a composite column. Creation instructions are under the spoiler.
- Display the ISBN. Template: {isbn}
- Display the formats for a book. Template: {formats}. EDIT: calibre 6.17 has a native Formats column. See Preferences / Add your own columns and check the box for Formats (lookup name 'formats')
- Display Yes if the book has an EPUB format. Template:{formats:contains(EPUB, Yes,)}
- Display the author sort. Template: {author_sort}
- Display the title sort. Template: {title_sort}
Deprecated- Sony Metadata
Spoiler:
Metadata: Show author and title for title (Sony) (Sweetpea)
Metadata: Show title [series [series index]] as title, limiting series to 8 letters (Sony) (chaley)
Metadata: Show series - series index - title, with series as initials (Sony) (inspired by speakingtohe)
Metadata: Given a yes/no 'Read' custom column, have the collections display Read, Reading, Unread (Sony) (sweetpea)
Last edited by chaley; 03-15-2024 at 06:19 PM.
|