Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 01-14-2014, 11:43 PM   #1
anandkarthikeyan
Junior Member
anandkarthikeyan began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jan 2014
Device: kindle
regex to add books; filenames with only underscores as separators

I have a bunch of files formatted like this "surname_firstname_t_i_t_l_e.format", for instance, like "kermode_frank_sense_of_an_ending.pdf"

The problem is that I have used no other separators to identify where the author field stops or the title begins. To add these books, I want help with a regEx that will recognise the first two units as containing the metadata for the author and the rest for the title. Thanks.
anandkarthikeyan is offline   Reply With Quote
Old 01-15-2014, 04:08 AM   #2
Adoby
Handy Elephant
Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.
 
Adoby's Avatar
 
Posts: 1,736
Karma: 26785668
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Thinkpad E595, Ubuntu Mate, Huawei Mediapad 5, Bouye Likebook Plus
You may not need the filename. If there is a ISBN-number in the book, you can use the ISBN-plugin to extract it, and then download the metadata using only that.

Or you can read in the whole filename to the title and the use bulk metadata search and replace, with regexp, to set the author.

[^_]+ will match a string until there is a underscore.

Search title for

^([^_]+)_([^_]+)_(.+)$

And replace author with

\1 \2

(or possibly \2 \1 if you want firstname surname)

Then do the same but replace title with

\3

Not tested...

I leave it to you to figure out how to remove underscores from the title.

Last edited by Adoby; 01-15-2014 at 04:13 AM.
Adoby is offline   Reply With Quote
Advert
Old 01-15-2014, 09:32 AM   #3
anandkarthikeyan
Junior Member
anandkarthikeyan began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jan 2014
Device: kindle
Thanks a lot. This I somewhat understand, but what I have no clue about is the syantax in Calibre. If
Code:
(?P<title>.+) - (?P<author>[^_]+)
can read a file named like "t_i_t_l_e - firstname_lastname.format" correctly, what would work on the filenames I mentioned? Can you explain that to me? I am totally new to this and have no coidng knowledge. Thanks.
anandkarthikeyan is offline   Reply With Quote
Old 01-15-2014, 09:58 AM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,689
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by anandkarthikeyan View Post
Thanks a lot. This I somewhat understand, but what I have no clue about is the syantax in Calibre. If
Code:
(?P<title>.+) - (?P<author>[^_]+)
can read a file named like "t_i_t_l_e - firstname_lastname.format" correctly, what would work on the filenames I mentioned? Can you explain that to me? I am totally new to this and have no coidng knowledge. Thanks.
IMHO,
sometimes it is easier to do a 'post-import' correction of things (the names) using the Search and Replace tools of the Bulk metadata editoe, where you are only working on ONE (source) field at a time.

In the example, you import the grungy Title as is. with the Author cleaned to :Firstname Lastname, and drop the ' - ' as part of the process (per your example)

BTW If the format contains good metadata, forget the 'Read from filename', Calibre WILL extract the existing metadata during an ADD if you DON'T use that setting.
theducks is offline   Reply With Quote
Old 01-15-2014, 10:04 AM   #5
anandkarthikeyan
Junior Member
anandkarthikeyan began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jan 2014
Device: kindle
Yea, I understand that. It is just that I have quite a few documents other than books, like journal articles and so on, which do not contain the metadata but I have always entered the details in the filenames. All The data I need is available in the filename and it would be a lot easier to have them imported as such. Thank you.
anandkarthikeyan is offline   Reply With Quote
Advert
Old 01-15-2014, 10:10 AM   #6
Adoby
Handy Elephant
Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.
 
Adoby's Avatar
 
Posts: 1,736
Karma: 26785668
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Thinkpad E595, Ubuntu Mate, Huawei Mediapad 5, Bouye Likebook Plus
Quote:
Originally Posted by anandkarthikeyan View Post
Thanks a lot. This I somewhat understand, but what I have no clue about is the syantax in Calibre. If
Code:
(?P<title>.+) - (?P<author>[^_]+)
can read a file named like "t_i_t_l_e - firstname_lastname.format" correctly, what would work on the filenames I mentioned? Can you explain that to me? I am totally new to this and have no coidng knowledge. Thanks.
No, I almost never bother trying to read metadata from the filename when adding. I try to use the ISBN in the file to download metadata. If that fail hopefully metadata was embedded in the file. If all else fails I read in the whole filename to title and do some bulk metadata search and replace.
Adoby is offline   Reply With Quote
Old 01-15-2014, 10:22 AM   #7
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,689
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by anandkarthikeyan View Post
Yea, I understand that. It is just that I have quite a few documents other than books, like journal articles and so on, which do not contain the metadata but I have always entered the details in the filenames. All The data I need is available in the filename and it would be a lot easier to have them imported as such. Thank you.
Maybe you could use a bulk renamer like Metamorphose to clean up those file names before passing the files to Calibre.
theducks is offline   Reply With Quote
Old 01-15-2014, 11:31 AM   #8
Adoby
Handy Elephant
Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.Adoby ought to be getting tired of karma fortunes by now.
 
Adoby's Avatar
 
Posts: 1,736
Karma: 26785668
Join Date: Dec 2009
Location: Southern Sweden, far out in the quiet woods
Device: Thinkpad E595, Ubuntu Mate, Huawei Mediapad 5, Bouye Likebook Plus
(?P<author>[^_]+_[^_]+)_(?P<title>.+)

Might work. Not tested. Will read in author as it stands, last name first name.
Adoby is offline   Reply With Quote
Old 01-15-2014, 11:46 AM   #9
anandkarthikeyan
Junior Member
anandkarthikeyan began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Jan 2014
Device: kindle
Yea, I already tried that. Doesn't work. I quite don't get the syntax there. Thanks a lot for your time. I think I should consider bulk renaming the files.
anandkarthikeyan is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
More help needed: regex for add books macnab69 Library Management 11 06-17-2013 12:15 PM
Help: regex for add books macnab69 Library Management 4 06-16-2013 01:53 AM
Name for series index in regex for add books macnab69 Library Management 0 06-15-2013 12:53 PM
Want RegEx to add books to Calibre huon Library Management 0 02-02-2012 12:52 AM
Add Books - Regex Help Please nynaevelan Calibre 2 08-16-2011 01:30 PM


All times are GMT -4. The time now is 04:31 PM.


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