View Single Post
Old 08-31-2021, 05:31 PM   #911
dunhill
Guru
dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.dunhill ought to be getting tired of karma fortunes by now.
 
dunhill's Avatar
 
Posts: 875
Karma: 409970
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
Quote:
Originally Posted by dcmarquardt View Post
I just wanted to share this here because I spent the last few hours trying to narrow down how to accomplish this...

Background: I recently converted my entire audiobook (multi-mp3 per book) collection into M4B's so that I could manage them with calibre following the "One File Per Book" pattern. (If anyone is interested in a decent way to batch-process that, feel free to PM me)... Once I loaded all of my M4B files into calibre, fixed up all the metadata, etc... it occurred to me that I would create a virtual library called "Audiobooks"... The search expression I used for that is: format:M4B. Easy enough. Now, some of the newly loaded audiobooks that I have, also have various e-book formats (epub, pdf, etc...) that I added to their calibre records for convenience.

Problem: I have a virtual library that shows me all of my audiobooks... that's great, but what if I'm browsing through them and want a specific one to read on my tablet? So I decided to add a custom column that would be called "Audio Only"... basically if the book has only a single format, and that format is equal to "M4B" in my case, then it would show yes, otherwise if there were additional formats available it would show no... or a check/x-mark as it ended up. I'm a software dev, so writing some code isn't anything new, but I was surprised that I couldn't find something out here already to have a simple if... this and this are true ... then 'yes' else 'no' ...

Solution:
I created a custom column template that displays a green check if the book is "Audio Only", and a red X if it has non-audio formats attached to it. Here's how:

Preferences -> Add your own columns -> Add

Lookup Name: onlyaudio
Column Heading: Audio Only
Column Type: Column built from other columns
Show checkmarks: Checked
Template:
Code:
program:cmp(count(template('[[format]]'), ','), 1, 'no', in_list(template('[[format]]'), ',', 'M4B', 'yes', 'no'), 'no')

---

This can be adapted to give you a yes/no column if the book contains only one specific format and no others... just paste that in there and replace the M4B with whatever format you want to single out... if it is the ONLY one present, the column will have a value of yes, otherwise no... you can swap those around as needed also to gain the desired result.

One possible improvement I may work on is in the event I someday store more than a single audio format inside calibre, in which case I would need to go through all of the formats and check them... at that point it becomes more complex because I could potentially have >1 formats but have them all be audio... I'll leave that one for another day.


It is possible that the template could recognize more than one format ?

program:cmp(count(template('[[format]]'), ','), 1, 'no', in_list(template('[[format]]'), ',', 'Ogg', 'Si', 'no', ',', 'M3u', 'Si', 'no', ',', 'M4a', 'Si', 'no', ',', 'Mp3', 'Si', 'no'), 'no')

Last edited by dunhill; 08-31-2021 at 06:39 PM.
dunhill is offline   Reply With Quote