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 12-18-2022, 01:19 AM   #1
Req13
Enthusiast
Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!
 
Posts: 28
Karma: 100000
Join Date: Mar 2010
Device: Kindle PW4, Sony PRS-T1, PRS-600 & Nook STR
Replacing characters with the save to disk template

I have been trying to figure out how to use the saving books to disk template.

When I save a book that is named something like:

Mark Twain - Anthologies: How Many Are There?

I would like to replace the colon with a semicolon and remove the question mark so that it comes out as this:

Mark Twain - Anthologies; How Many Are There

Is there a way to achieve that? This is all I've been able to work out so far.

Code:
Replace ? with nothing

{authors} - {title:re(\?,)}
--------------------------------------------------------
Replace ? and : with nothing

{authors} - {title:re(\?|\:,)}
--------------------------------------------------------
Replace : with ;

{authors} - {title:re(:,;)}

I'd also like to possibly add to it if I need to change other special characters to something other than an underscore.

Thanks for any help.
Req13 is offline   Reply With Quote
Old 12-18-2022, 06:56 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,515
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Req13 View Post
I have been trying to figure out how to use the saving books to disk template.

When I save a book that is named something like:

Mark Twain - Anthologies: How Many Are There?

I would like to replace the colon with a semicolon and remove the question mark so that it comes out as this:

Mark Twain - Anthologies; How Many Are There

Is there a way to achieve that? This is all I've been able to work out so far.

Code:
Replace ? with nothing

{authors} - {title:re(\?,)}
--------------------------------------------------------
Replace ? and : with nothing

{authors} - {title:re(\?|\:,)}
--------------------------------------------------------
Replace : with ;

{authors} - {title:re(:,;)}

I'd also like to possibly add to it if I need to change other special characters to something other than an underscore.

Thanks for any help.
One way that is easy to extend in the future.
Code:
program:
	t = $title;
	t = re(t, '\?', '');
	t = re(t, ':', ';');
# Add any more changes that you want.
FWIW: I prefer GPM templates over the other template modes.
chaley is offline   Reply With Quote
Old 12-18-2022, 10:50 PM   #3
Req13
Enthusiast
Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!
 
Posts: 28
Karma: 100000
Join Date: Mar 2010
Device: Kindle PW4, Sony PRS-T1, PRS-600 & Nook STR
Thank you for responding. I plugged this into the template editor in saving books to disk:

Code:
program:
	t = $title;
	t = re(t, '\?', '');
	t = re(t, ':', ';');
# Add any more changes that you want.
This outputs just the title of the book.

I was hoping to have an output of the author and title like this:

Author - Title

I can't figure out how to add the author to your code.

Thanks again.
Req13 is offline   Reply With Quote
Old 12-19-2022, 06:02 AM   #4
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,515
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Req13 View Post
Thank you for responding. I plugged this into the template editor in saving books to disk:

Code:
program:
	t = $title;
	t = re(t, '\?', '');
	t = re(t, ':', ';');
# Add any more changes that you want.
This outputs just the title of the book.

I was hoping to have an output of the author and title like this:

Author - Title

I can't figure out how to add the author to your code.

Thanks again.
You don't say whether you want any transforms to the authors names, or if you want all the authors or only the first. I assume no transforms and all the authors.

Use:
Code:
program:
# The authors
	a = $authors;
# Do any transforms you want to authors
# For example, to get the first author
#	a = list_item(a, 0, '&');

# The title
	t = $title;
	t = re(t, '\?', '');
	t = re(t, ':', ';');
# Add any more changes that you want.

# Construct the final output
	a & ' - ' & t
chaley is offline   Reply With Quote
Old 12-19-2022, 09:54 PM   #5
Req13
Enthusiast
Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!
 
Posts: 28
Karma: 100000
Join Date: Mar 2010
Device: Kindle PW4, Sony PRS-T1, PRS-600 & Nook STR
Quote:
Originally Posted by chaley View Post
Code:
program:
# The authors
    a = $authors;
# Do any transforms you want to authors
# For example, to get the first author
#    a = list_item(a, 0, '&');

# The title
    t = $title;
    t = re(t, '\?', '');
    t = re(t, ':', ';');
# Add any more changes that you want.

# Construct the final output
    a & ' - ' & t
I do want all the authors with no transforms. I tried this code in the edit template box, but it wouldn't work. It comes up with this error in the template value box:

EXCEPTION: Formatter: Failed to scan program. Invalid input '& ' - ' & t' near the end of the program

I'm not sure if I needed to change something in the code or not.
Req13 is offline   Reply With Quote
Old 12-20-2022, 05:11 AM   #6
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,515
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Req13 View Post
I do want all the authors with no transforms. I tried this code in the edit template box, but it wouldn't work. It comes up with this error in the template value box:

EXCEPTION: Formatter: Failed to scan program. Invalid input '& ' - ' & t' near the end of the program

I'm not sure if I needed to change something in the code or not.
You must be running an older calibre version, before calibre 5.40. Assuming you want to/must stay on the older calibre version, the code should be:
Code:
program:
# The authors
	a = $authors;
# Do any transforms you want to authors
# For example, to get the first author
#	a = list_item(a, 0, '&');

# The title
	t = $title;
	t = re(t, '\?', '');
	t = re(t, ':', ';');
# Add any more changes that you want.

# Construct the final output
	strcat(a, ' - ', t)
chaley is offline   Reply With Quote
Old 12-21-2022, 01:21 AM   #7
Req13
Enthusiast
Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!Req13 rocks like Gibraltar!
 
Posts: 28
Karma: 100000
Join Date: Mar 2010
Device: Kindle PW4, Sony PRS-T1, PRS-600 & Nook STR
Sorry, I didn't realize it had been so long since I updated Calibre.

This is exactly what I'm looking for.

Thank you for your time and help.
Req13 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Save to Disk Template Amanda5177 Library Management 8 01-09-2019 01:09 PM
save to disk template help bilaly Library Management 2 10-19-2018 07:19 PM
Need help - Save to Disk template Gallips Calibre 8 06-28-2016 01:46 PM
Please help on a Save to Disk template Dammie Library Management 15 12-16-2013 09:51 AM
save to disk template speakingtohe Calibre 9 05-29-2010 06:02 AM


All times are GMT -4. The time now is 11:52 AM.


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