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 10-16-2014, 04:31 PM   #1
bittenfig
Junior Member
bittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-books
 
Posts: 9
Karma: 752
Join Date: Feb 2014
Device: none
Need a little help manipulating title for generating covers

I've got several books that have a title and subtitle, as in:

No Contest: The Case Against Competition

I'd like the "No Contest" to be used in the title template and the "The Case Against Competition" to be used in the subtitle template. The default setting is for the subtitle template to print the series and something else, so I'd like to change that. I tried doing some string manipulation, but my rudimentary Python skills are failing, and the manual doesn't offer much help for a seemingly simple operation.
bittenfig is offline   Reply With Quote
Old 10-16-2014, 05:00 PM   #2
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,568
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
@bittenfig - Is subtitle a separate column (custom)?

Are you referring to the built-in generate cover feature or the optional ==>> [GUI Plugin] Generate Cover plug-in?

BR
BetterRed is offline   Reply With Quote
Old 10-16-2014, 05:38 PM   #3
bittenfig
Junior Member
bittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-booksbittenfig has learned how to read e-books
 
Posts: 9
Karma: 752
Join Date: Feb 2014
Device: none
@BetterRed: Yes, by "subtitle" I'm referring to the template used in the generate cover feature, not custom metadata. If you click and hold "Generate Cover", the customization option appears. Under the "Text" tab, you can change the subtitle and title templates, which is what I'm trying to do. I just need it to grab the title (as in title the metadata) and for the title template, just use whatever is before ": ", and for the subtitle template use whatever is after ": " for the titles that do contain ": ".
bittenfig is offline   Reply With Quote
Old 10-16-2014, 06:14 PM   #4
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,568
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
@bittenfig - OK, what you need is a Regular Expression to pull apart the title column into the two components main title and subtitle, embedded within a Template.

See ==>> All about using regular expressions in calibre

See ==>> The calibre template language — Single Function Mode. Scroll down and you'll see this function

Quote:
re(pattern, replacement) – return the field after applying the regular expression. All instances of pattern are replaced with replacement. As in all of calibre, these are python-compatible regular expressions.
I don't claim any proficiency at formulating RegEx's or Templates - I muddle through by trial and error.

But there are regular contributors here who have expertise at both, hopefully one or other should be able to provide the magic bullets.

You might find something useful in this thread ==>> Plugboard, template, and custom composite column recipes

BR

Last edited by BetterRed; 10-16-2014 at 06:19 PM.
BetterRed is offline   Reply With Quote
Old 10-19-2014, 11:10 AM   #5
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Hey, BR, thanks for the recommendation. (I was offline for the holidays, and can end up missing a lot of stuff.)

@bittenfig, I thiink this should give you what you want.

title:
Just regex the title and replace ":.*" with nothing.
Code:
program:

strcat(
	'<b>',
	re(
		field('title'),
		':.*$',
		''
	)
)
subtitle:
Use the default template (converted to general program mode) but first check for title-contains-a-colon. If so we use the title and replace "^[^:]*:" with nothing, if not, we continue as we did before. (You can also replace the test block with a blank, or do whatever else you would've otherwise done if the title doesn't have a colon.)
Code:
program:

contains(
	field('title'),
	':',
	re(
		field('title'),
		'^[^:]*:',
		''
	),
	test(
		field('series'),
		strcat(
			'<i>',field('series'),'</i> - ',
			raw_field('formatted_series_index')
		),
		''
	)
)
What do you want done if the title has a subtitle and there is also a series?

Last edited by eschwartz; 10-19-2014 at 11:24 AM.
eschwartz is offline   Reply With Quote
Reply

Tags
generate cover, metadata, python, templates


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Title bulk edit match - to remove series info from title Rob557 Library Management 30 12-09-2014 06:06 AM
Pubit!/Add Title Previewer shows ellipsis in title bar schooner1892 General Discussions 0 09-15-2012 07:04 PM
Manipulating Catalogue Outputs LMF Calibre 1 01-13-2012 06:40 PM
Generating Author and title from directory structure Nerumshah Library Management 8 11-25-2011 02:29 PM
manipulating/converting pdfs under linux johnnytruant iRex 3 02-02-2009 02:57 PM


All times are GMT -4. The time now is 12:33 PM.


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