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 05-25-2022, 05:47 AM   #406
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,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Vespero View Post
Is there a way to change the template based on the format of the book being sent?"

I send both .epub and .cbz to my device and prefer different naming schemes for them.

With .epub, I like
books/{author_sort}/{series}/{title}

But with .cbz, I want
books/{author_sort}/{series}/{title}
(being comics, each chapter/volume is already named {series}{series_index})

Currently, I either have to manually edit the template each time I switch formats (which also requires restarting Calibre and remounting the folder), or I have to switch how the device is mounted (Connect to Folder for .cbz and Wireless Connection for .epub)

There's got to be an easier way though, right?
The template doesn't know and can't see the format type (extension).

@ownedbycats solution works for books that have one or the other format. If a book has both and you choose the format when you send to device then it won't give you joy. However, if you let calibre choose by priority then you can build that same priority into the template.

I haven't looked at file name template processing for years. Now that we have template global variables I might be able to pass the format extension there. EDIT: No can do. The file path is generated before the extension is chosen.

Last edited by chaley; 05-25-2022 at 05:59 AM.
chaley is offline   Reply With Quote
Old 05-25-2022, 08:08 AM   #407
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Yah, I was working off the assumption that Vespero would have only cbz for the comics (seeing as comics don't tend to work well as epubs).

Last edited by ownedbycats; 05-25-2022 at 08:13 AM.
ownedbycats is offline   Reply With Quote
Advert
Old 05-25-2022, 10:20 PM   #408
Vespero
Junior Member
Vespero began at the beginning.
 
Vespero's Avatar
 
Posts: 6
Karma: 10
Join Date: May 2022
Device: Kindle Paperwhite 5
Quote:
Originally Posted by ownedbycats View Post
Yah, I was working off the assumption that Vespero would have only cbz for the comics (seeing as comics don't tend to work well as epubs).
I *do* just use cbz for comics (not even cbr because my conversion script only works on cbz and I'm too lazy to change it).

The composite column sounds like a great idea! I just use epub and cbz so I'd only need two entries (well, I guess a third in the case of exceptions). I'm pretty bad at programming but I'll do some testing, thanks!
Vespero is offline   Reply With Quote
Old 05-26-2022, 02:49 PM   #409
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
strcat: What would be the best way to add the comma separators here? I thought of "if id then output" but that seems clumsy.
Attached Thumbnails
Click image for larger version

Name:	2022-05-26 15_48_01-Template tester.png
Views:	504
Size:	44.8 KB
ID:	193982  

Last edited by ownedbycats; 05-26-2022 at 02:53 PM.
ownedbycats is offline   Reply With Quote
Old 05-26-2022, 03:15 PM   #410
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,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
strcat: What would be the best way to add the comma separators here? I thought of "if id then output" but that seems clumsy.
You can do it with list_join. I don't have your actual text and don't want to read/type it in, but it would look something like

Code:
program:
list_join(
    ',',
    if x then urls_from_identifiers('foo:bar', 0) fi, ',',
    if y then urls_from_identifiers('mumble:fratz', 0) fi, ',')
The list_join function ignores empty lists.
chaley is offline   Reply With Quote
Advert
Old 05-26-2022, 04:05 PM   #411
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
list_join works, though I had to set the separator to ', ', (with an additional whitespace character); unsure if that's intended behaviour so I'm noting it.
ownedbycats is offline   Reply With Quote
Old 05-26-2022, 04:55 PM   #412
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,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
list_join works, though I had to set the separator to ', ', (with an additional whitespace character); unsure if that's intended behaviour so I'm noting it.
You need to do that only if you want to see a space after the comma. The space isn't needed for anything except its appearance.
chaley is offline   Reply With Quote
Old 05-26-2022, 05:40 PM   #413
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I just noticed that without the additional space it lumped together like 'Goodreads,Fantastic Fiction,Google."
ownedbycats is offline   Reply With Quote
Old 05-26-2022, 06:05 PM   #414
Vespero
Junior Member
Vespero began at the beginning.
 
Vespero's Avatar
 
Posts: 6
Karma: 10
Join Date: May 2022
Device: Kindle Paperwhite 5
Quote:
Originally Posted by Vespero View Post
I *do* just use cbz for comics (not even cbr because my conversion script only works on cbz and I'm too lazy to change it).

The composite column sounds like a great idea! I just use epub and cbz so I'd only need two entries (well, I guess a third in the case of exceptions). I'm pretty bad at programming but I'll do some testing, thanks!
Thought I'd gotten it to go off without a hitch, but there *is* one issue.

I have a column (lookup is "path") set to:

Code:
program:

	if 
		'cbz' in approximate_formats() 
	then
		'books/{author_sort}/{series}/{title}'

	else	
		'books/{author_sort}/{series}/{series}{series_index:0>2s| - | - }{title}'

	fi
This correctly populates the column with the intended data (either 'books/{author_sort}/{series}/{title}' or 'books/{author_sort}/{series}/{series}{series_index:0>2s| - | - }{title}') but when Calibre looks at the template and sees {path}, it is pulling the value, but is not interpreting the variables inside of it as variables.

I believe this is what the manual warns against in the bolded text:
Quote:
Do not use subtemplates (`{ … }`) as function arguments.
I'm looking at "General Program Mode" (as the manual says)...does this mean each of the "template expressions" (I assume those are the variables with the curly braces) need to be replaced with something formatted for GPM?

Or is the issue with the fact that the variables in the column are showing as variables and not actually displaying the information they should point to? I guess that should have been my first hint that something was wrong. Some quick Googling did not turn up an example of a column formed from multiple variables that I could use as a base.

(I'd do more experimentation and research on my own but I'm unfortunately about to be out of the house and extremely busy for the next week and don't have the time, so sorry if this is an obvious mistake on my part)
Vespero is offline   Reply With Quote
Old 05-27-2022, 04:00 AM   #415
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,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Vespero View Post
Thought I'd gotten it to go off without a hitch, but there *is* one issue.
...

(I'd do more experimentation and research on my own but I'm unfortunately about to be out of the house and extremely busy for the next week and don't have the time, so sorry if this is an obvious mistake on my part)
You can't use template syntax inside a GPM template.

This should do it. The spacing might be wrong.
Code:
program:
	if 
		'cbz' in approximate_formats() 
	then
		strcat('books/', $author_sort, '/', $series, '/', $title)
	else	
		strcat('books/', $author_sort, '/', $series, '/', $series, finish_formatting($series_index, '0>2s', ' - ', ' - '), $title)
	fi
chaley is offline   Reply With Quote
Old 05-28-2022, 02:58 PM   #416
Vespero
Junior Member
Vespero began at the beginning.
 
Vespero's Avatar
 
Posts: 6
Karma: 10
Join Date: May 2022
Device: Kindle Paperwhite 5
Smile

Quote:
Originally Posted by chaley View Post
You can't use template syntax inside a GPM template.

This should do it. The spacing might be wrong.
Code:
program:
	if 
		'cbz' in approximate_formats() 
	then
		strcat('books/', $author_sort, '/', $series, '/', $title)
	else	
		strcat('books/', $author_sort, '/', $series, '/', $series, finish_formatting($series_index, '0>2s', ' - ', ' - '), $title)
	fi
Hey, thank you so much! That worked like a charm! And now that I have an idea of how it works, if I need to do tweaks in the future, I can!
Vespero is offline   Reply With Quote
Old 07-13-2022, 08:17 AM   #417
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Question: Could book_values be used to check how many books in a series have a #percentread of 100, compare that to the number of books in the series, then return a value (e.g. read series, unread series, partially read series) based on that?

I think this would probably be best done as a template search.
ownedbycats is offline   Reply With Quote
Old 07-13-2022, 08:54 AM   #418
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,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question: Could book_values be used to check how many books in a series have a #percentread of 100, then return a value (e.g. read series, unread series, partially read series) based on that? This would probably be best done as a template search.
Sure. Something like this Edited:
Code:
program:
	vals = globals(vals = '');
	if !vals then
		all_series = book_values('series', 'series:true', ',', 0);
		for series in all_series:
			count = book_count('series:="' & series & '"', 0);
			reads = book_values('#myint', 'series:="' & series & '"', ',', 0);
			ans = '';
# I assume that an unread book has an undefined read percentage, not 0%
# If the reads list is empty then no book has a defined value
			if list_count(reads, ',') == 0 then
				ans = 'Unread series'
			fi;
			for i in reads:
# If any book isn't 100 then partially read
				if i != 100 then
					ans = 'Partially read series'
				fi
			rof;
			if !ans then
				ans = 'Read series'
			fi;
			vals = list_join(',', vals, ',', series & ':' & ans, ',')
		rof
	fi;
	select(vals, $series)

Last edited by chaley; 07-14-2022 at 11:25 AM. Reason: Added the missing call to globals(). Remove blank after 'program'
chaley is offline   Reply With Quote
Old 10-09-2022, 09:52 PM   #419
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,063
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Code:
program:

# Returns 'Fanfiction/Fandom' for fanfics
	if $$#fanficcat then
		list_re($tags, ',', '^Fanfiction.(.*)$', 'Fanfiction/\1')

# Returns 'Kobo' for Kobo store books
	elif '\[Kobo Store\]' in $#kobostatus then 'Kobo Store' 

# Returns 'PDF' for PDFs
	elif $formats == 'PDF' then
		'PDF'

# Returns 'Loans' for Loans
	elif 'Loans' in $#vls then
		'Loans'

# Returns topmost tag for all other books
	else
		re(sublist($tags, 0, 1, ','), '^(.*?)($|\..*$)', '\1')

	fi
For the 'topmost tag', what would be the best way to specifically exclude '[Cleanup]'?
ownedbycats is offline   Reply With Quote
Old 10-10-2022, 10:27 AM   #420
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,465
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Code:
program:

[...]

# Returns topmost tag for all other books
	else
		re(sublist($tags, 0, 1, ','), '^(.*?)($|\..*$)', '\1')

	fi
For the 'topmost tag', what would be the best way to specifically exclude '[Cleanup]'?
First question: what is a "topmost tag"? It seems that it is the first first hierarchical component of the first tag on the list, but as you can't depend on the order of tags in the list that seems wrong.

What do you want to have happen if the first tag is '[Cleanup]'? Do you want the second tag? if so then this would work:
Code:
	t = sublist($tags, 0, 1, ',');
	if t == "[CLEANUP]" then
		t = sublist($tags, 1, 2, ',')
	fi;
	re(t, '^(.*?)($|\..*$)', '\1')
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Library Management: various questions not worth their own thread ownedbycats Library Management 229 08-13-2025 06:41 PM
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates Boilerplate4U Development 13 07-07-2020 02:35 AM
Questions on Kobo [Interfered with another thread topic] spdavies Kobo Reader 8 10-12-2014 11:37 AM
[OLD Thread] Some questions before buying the fire. darthreader13 Kindle Fire 7 05-10-2013 09:19 PM
Thread management questions meme Feedback 6 01-31-2011 05:07 PM


All times are GMT -4. The time now is 03:06 AM.


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