Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 01-06-2024, 06:44 PM   #1
JaymesRs
Junior Member
JaymesRs began at the beginning.
 
JaymesRs's Avatar
 
Posts: 4
Karma: 10
Join Date: Feb 2022
Device: Kobo Libra 2
I need help with writing a template program to exclude some books from being tagged

I use the page count plugin plus a template program I adapted from one found online (included below) to build a column that categorizes books by length. (I use this to build collections I use when I’m picking my next to read)

I’d like to exclude certain books from getting a classification though if they are PDFs or have tags like “Graphic Novel” or “Cookbook”. I’d appreciate any help figuring this out.

Thanks.

Code:
program:
val = field('#pagecount');
first_non_empty(
	cmp(val, 0, ' ', '', ''),
	cmp(val, 15, 'Flash Fiction', '', ''),
	cmp(val, 50, 'Short Story', '', ''),
	cmp(val, 100, 'Novelette', '', ''),
	cmp(val, 250, 'Novella', '', ''),
	cmp(val, 500, 'Short Novel', '', ''),
	cmp(val, 750, 'Long Novel', '', ''),	
	cmp(val, 1000, 'Tome', '', ''),
	'Toe Breaker');

Last edited by chaley; 01-07-2024 at 06:39 AM. Reason: Put template in code tags
JaymesRs is offline   Reply With Quote
Old 01-07-2024, 06:44 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
It isn't clear what you want to do.
  • Do you want to classify the book as above except if the book is PDF? Any other formats? What happens if a book has multiple formats?
  • You don't want to classify if the book has one of a set of tags? Is that set subject to change?
  • What happens if a book isn't classified?
  • Does your classification template work (produce the wanted answer) for all books that should be classified?
chaley is offline   Reply With Quote
Advert
Old 01-07-2024, 11:23 AM   #3
JaymesRs
Junior Member
JaymesRs began at the beginning.
 
JaymesRs's Avatar
 
Posts: 4
Karma: 10
Join Date: Feb 2022
Device: Kobo Libra 2
Thank for replying. Sorry for not being super clear.

> Do you want to classify the book as above except if the book is PDF? Any other formats?
I only have PDFs, epubs, and kepubs. The PDFs I have are only PDFs and contain no other formats.

>What happens if a book has multiple formats?
They will be included. Only PDFs will be excluded.

>You don't want to classify if the book has one of a set of tags? Is that set subject to change?
It shouldn’t ever change. I don’t use many tags in the tag browser. I only have a small number for things like graphic novels, cookbooks, or reference books. None of the books that I have specific tags for our books that one will ever just sit down and read, which is my goal and building this classification system.

>What happens if a book isn't classified?
I use these to build collections on my Kobo. In an ideal world, they just won’t be added to any collection. Based on the info from the Reddit page where I pulled the original program if I set the tag in that specific column to a single space, it should be ignored and that’s my ideal situation (https://www.reddit.com/r/Calibre/com..._pages_column/).

>Does your classification template work (produce the wanted answer) for all books that should be classified?
At this point yes the problem is it extra books that I don’t want to be lumped in with the others for example, graphic novels will have a page count but they aren’t really short stories or Novelettes. They are their own thing.
JaymesRs is offline   Reply With Quote
Old 01-07-2024, 11:38 AM   #4
JaymesRs
Junior Member
JaymesRs began at the beginning.
 
JaymesRs's Avatar
 
Posts: 4
Karma: 10
Join Date: Feb 2022
Device: Kobo Libra 2
Quote:
It isn't clear what you want to do.
Thank you for your reply. Sorry for my lack of clarity. I’ll do my best to fill in the blanks.

Quote:
Do you want to classify the book as above except if the book is PDF? Any other formats? What happens if a book has multiple formats?
I only really have three formats in my Calibre library; I have PDFs, epubs, & kepubs. There have been times that I have briefly had an additional, but that’s really only in the process of conversion, where in the original will then be deleted afterwards. The books that are PDFs are only PDFs. They don’t have any other formats in that entry in Calibre. The books that are epubs are also kepubs. So yes, all books that aren’t PDFs should be in those categories with the exception of those that have specific tags in the tag browser and I’ll get into that answer next.

Quote:
You don't want to classify if the book has one of a set of tags? Is that set subject to change?
I have a very limited usage of the general tag column on purpose. I really only use tags as a way of setting apart a small number of books, such as graphic novels, cookbooks, and reference books. Books that, for the most part aren’t just something someone will sit down and read. That it really isn’t subject to change as far as I can foresee. While it is possible I would add an additional entry to that item the list has been fairly static for a significant amount of time and if I needed to add a new tag in there, I would also update this template program.

Quote:
What happens if a book isn't classified?
Based on my understanding from the original Reddit page where I got this program, it used a single space in certain situations, and seemed to state that Calibra would ignore single spaces as a category.

Quote:
Does your classification template work (produce the wanted answer) for all books that should be classified?
At this point, it does other than it includes works that I’d prefer not to include. For example, a cookbook isn’t really a novel.

Thank you for your help.
JaymesRs is offline   Reply With Quote
Old 01-07-2024, 04:56 PM   #5
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
I think this does what you want. You might need to add/change the tags in the list_intersection().

Code:
program:
	val = $#pagecount;
	if $formats && $formats != 'PDF' && list_intersection($tags, 'Graphic Novel, Cookbook', ',') == '' then
		switch_if(
			val ==# 0, '',
			val <# 15, 'Flash Fiction',
			val <# 50, 'Short Story',
			val <# 100, 'Novelette', 
			val <# 250, 'Novella', 
			val <# 500, 'Short Novel',
			val <# 750, 'Long Novel',
			val <# 1000, 'Tome',
			'Toe Breaker')
	fi
chaley is offline   Reply With Quote
Advert
Old 01-08-2024, 10:59 AM   #6
JaymesRs
Junior Member
JaymesRs began at the beginning.
 
JaymesRs's Avatar
 
Posts: 4
Karma: 10
Join Date: Feb 2022
Device: Kobo Libra 2
Thank you so much, that worked great.
JaymesRs is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use re() function in Template Program Mode? msciwoj Library Management 3 07-07-2016 03:55 PM
Total size of tagged books mkrubsack Calibre 7 03-14-2014 02:08 PM
writing program help? Anna Drake Writers' Corner 0 10-17-2013 04:38 PM
General Program Template StevieCoops Library Management 3 09-30-2013 11:02 PM
Date formatting/template program mode bookworm2000 Library Management 4 12-28-2012 04:41 PM


All times are GMT -4. The time now is 09:53 PM.


MobileRead.com is a privately owned, operated and funded community.