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 02-23-2020, 12:35 PM   #1
kellykline
Junior Member
kellykline began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Mar 2019
Device: Onyx Boox
Question Using Multiple Regular Expressions to Guess Metadata from Filename

Hi, how do I add multiple rules for the Adding books - Reading metadata section of the settings? Seems to have only one line for one regular expression, but I need it to be able to guess from different filename formats.
kellykline is offline   Reply With Quote
Old 02-23-2020, 03:03 PM   #2
kacir
Wizard
kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.
 
kacir's Avatar
 
Posts: 3,463
Karma: 10684861
Join Date: May 2006
Device: PocketBook 360, before it was Sony Reader, cassiopeia A-20
Quote:
Originally Posted by kellykline View Post
Hi, how do I add multiple rules for the Adding books - Reading metadata section of the settings? Seems to have only one line for one regular expression, but I need it to be able to guess from different filename formats.
It has only one RE by design.
How do you want the Calibre to decide which RE to use?

Here is what you can do:

Examine the filenames.

Use file manager to separate the files into various groups according to filenames. Or write a script using Linux "find" command or whatever.

Download plugin "Quick preferences" by Grant Drake for Calibre. Here you can define multiple Regular expressions and then select the one to use for the next file that you drag and drop (or import) into Calibre. BEWARE. Since the plugin was first developed something happened in Calibre code, so the first book you drag and drop in uses the previous RE. But, I haven't used it in quite some time.

Define various REs for various book formats in the plugin options. You can then select various import options for next file from the menu.

A few examples:
Code:
Title - Author (Default)
(?P<title>.+) - (?P<author>[^_]+)

Author [- Series #]- Title
^(?P<author>((?!\s-\s).)+)\s-\s(?:(?:\[\s*)?(?P<series>.+)\s(?P<series_index>[\d\.]+)(?:\s*\])?\s-\s)?(?P<title>[^(]+)(?:\(.*\))?

Series # -  Author - Title
^(?P<series>((?!\s-\s).)+)\s(?P<series_index>[\d\.]+)\s-\s(?:(?:\[\s*)?(?P<author>.+)(?:\s*\])?\s-\s)?(?P<title>[^(]+)(?:\(.*\))?

Author [(- Series #)]- Title
^(?P<author>((?!\s-\s).)+)\s-\s(?:(?:[[(]\s*)?(?P<series>.+)\s(?P<series_index>[\d\.]+)(?:\s*[])])?\s-\s)?(?P<title>[^(]+)(?:\(.*\))?
As you can see, the Regular expressions can be quite elaborate and cover some variations in filename input. There can be some optional stuff that is picked up when present (such as series name and series index in the last three examples). This is indicated by square brackets in description. The second example is most powerful and picks up wide variety of inputs.
Author Name - Book title
Author Name - Series name 2 - Book title
You have also option to swap author names in the quick preferences plugin (firstname lastname vs lastname, firstname)

Those REs *do* work
I realize they might appear unreadable. I wrote and / or heavily modified those a few years ago and now they look as a bunch of scattered characters to me on the first glance. You have to take them apart piece by piece to understand them. Regular Expression language is quite dense and some people jokingly describe it as "Write Only".

Calibre uses Python flavour of RE language
I found book "Mastering Regular Expression" very enlightening when I was learning Regular Expressions (in the distant past). I am not sure it covers "Python flavour" of RE languages. There are a few threads here about Calibre RE specifics on Mobileread.
kacir is offline   Reply With Quote
Advert
Old 02-23-2020, 05:10 PM   #3
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: 21,721
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
@kellykline - I normalise the filenames with external tools to a single simple regex-able pattern before I add them. Also, editing metadata in the booklist makes filling in the blanks eeasy - IMO. FX: copy/paste metadata from an existing book to one or more new books.

I use the same external tools to normalise other file names to consistent patterns, e.g. audio (music) files etc.

BR

Last edited by BetterRed; 02-23-2020 at 05:12 PM.
BetterRed is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bulk metadata edit dialog: Use of regular expressions - how to? DeepSeaDiver Library Management 8 07-14-2014 08:27 AM
Multiple Field Regular Expressions TheDauthi Library Management 2 09-14-2012 03:21 AM
Regular Expression - Adding metadata from filename LMF Calibre 1 03-20-2012 06:46 PM
Metadata from filename (regular expressions) geronimo72 Library Management 2 03-05-2012 04:14 PM
Regular expressions - Single back-reference, multiple instances? David Kudler Sigil 10 12-17-2011 12:05 PM


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


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