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 09-08-2012, 04:16 PM   #1
kanigetts
Junior Member
kanigetts began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Sep 2012
Device: Kindle 4
My RegEx works in Test but not for Add Books

I have a RegEx that I customized to Add Books and populate metadata. It works perfectly in the test but has different behavior when in actual use. It also works perfectly using RegEx Buddy software with the Python settings so it seems correct. What could account for the change in behavior? My RegEx:

(?P<series>[^_-]+) -?\s*(?P<series_index>[0-9]*) -?\s*(?P<title>[^_-]+) -?\s*(?P<author>[^_].+) ?

The String: BookSeries - 01 - Book Title - Book Author.epub

Test Result:

Author: Book Author
Series: BookSeries
Series Index: 01
Title: BookSeries - 01 - Book Title

Add Books Result:

Author: Book Author
Series: BookSeries
Series Index: 01
Title: Book Series - 01 - Book Title

If I change it slightly so that the input file name has two words before the first "-", it works fine in both the test and add books as well as in Regex Buddy. Like this:

The String: Book Series - 01 - Book Title - Book Author.epub

Test Result:

Author: Book Author
Series: Book Series
Series Index: 01
Title: Book Title

Add Books Result:

Author: Book Author
Series: Book Series
Series Index: 01
Title: Book Title

I've messed with it and had a number of variations that also worked fine in test and with RegEx Buddy, but still no love when I add books. I can't figure out why it seems to need two words before the "-", but only in Add Books. I'm just beginning to understand and use Regular Expressions and this one has me stumped. It's especially frustrating since I get different results with Test and Add Books.
kanigetts is offline   Reply With Quote
Old 09-08-2012, 04:26 PM   #2
kanigetts
Junior Member
kanigetts began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Sep 2012
Device: Kindle 4
I figured out a fix just after posting. If I remove the space in the first part of the regular expression, it will take a one word series name in the first position without screwing up the Title extraction. Why this works and why it's only needed in the first instance and only for Add Books and not Test, I don't understand, but at least I can move on.

Works for one word series: (?P<series>[^_-]+)-?\s*
Doesn't work for one word series: (?P<series>[^_-]+) -?\s*
kanigetts is offline   Reply With Quote
Advert
Old 09-08-2012, 04:40 PM   #3
kanigetts
Junior Member
kanigetts began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Sep 2012
Device: Kindle 4
I spoke too soon. The above fix works for .txt files but not for .mobi or .epub. This is truly beyond my comprehension.
kanigetts is offline   Reply With Quote
Old 09-08-2012, 05:18 PM   #4
JustForFun
Enthusiast
JustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-booksJustForFun has learned how to read e-books
 
Posts: 30
Karma: 752
Join Date: Nov 2010
Device: PB360
The '?' after the '-' look a little bit suspicious to me and may be responsible. If your books file names are all in the format

Book Series - 01 - Book Title - Book Author.epub

try this:

Code:
(?P<series>[^_-]+) -\s*(?P<series_index>[0-9]+) -\s*(?P<title>[^_-]+) -\s*(?P<author>[^_].+) ?
This will only work for the above mentioned pattern. If you have books without series or with series but without series number or any other combination it will not work.

As an interesting note, in my older calibre version (0.8.55), your original regex did extract the book title correctly in the test.
JustForFun is offline   Reply With Quote
Old 09-09-2012, 12:10 AM   #5
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,795
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You probably forgot to change the setting to read metadata from filenames instead of file contents.
kovidgoyal is offline   Reply With Quote
Advert
Old 09-17-2012, 04:07 PM   #6
p_garvie
Junior Member
p_garvie began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Sep 2012
Device: samsung galaxy note(cool reader), Kobo & Kobo Touch
hi im trying to add all my books to calibre however i have my directories set up as
eg.
Drive\books\Author\series\series# - Title
c:\books\anthony, piers\xanthe\01 - A spell for chameleon
i have found a default string in the add books section of the setting:
(?P<author>[^_-]+) -?\s*(?P<series>[^_0-9-]*)(?P<series_index>[0-9]*)\s*-\s*(?P<title>[^_].+) ?

using this string i get
Title: A spell for chameleon
author: Anthony, Piers\xanth\01

what i want is
Title: a spell for chameleon
Author: Anthony piers
Series: xanth
Series number: 01

ne ideas how to get this??
p_garvie is offline   Reply With Quote
Old 09-17-2012, 04:14 PM   #7
p_garvie
Junior Member
p_garvie began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Sep 2012
Device: samsung galaxy note(cool reader), Kobo & Kobo Touch
also just so you know i have them set up this way in my directories because i dont feel i need to know the authors name or series name cuz for the longest time i was adding them to my phone and was a palm handset and didnt show the full name and title so i just went through and hand edited them to the author\series\# - title cuz id usually only be able to see the first half of the name
i now have a galaxy note and my girlfriend has a kobo touch so id like to use calibre to add them to our devices i can still do it the old way on my phone but i need to convert them to epub for her device, and it easier to do them in batch than going into each dir and converting them from the .pdb (palm format)

Last edited by p_garvie; 09-17-2012 at 07:06 PM.
p_garvie is offline   Reply With Quote
Old 09-17-2012, 04:39 PM   #8
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,703
Karma: 54369092
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Calibre (REGEX) only looks at the file name... Not any of the Path.
theducks is offline   Reply With Quote
Old 09-17-2012, 07:04 PM   #9
p_garvie
Junior Member
p_garvie began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Sep 2012
Device: samsung galaxy note(cool reader), Kobo & Kobo Touch
actually it seems to work for most of them its just a few that messes up
cuz like i said i have them set into directories of author then directories of series then their all done as a number and title of the book
c:\books\anthony, piers\xanth\01 - A spell for chameleon.pdb
so when i gather books from directories including their sub directory i just brows to the directory the books are in and it takes the authors directory as the authors name and the second directory as the series but it doesnt do it all the time for some reason and i have to number them manually as the numbers are part of the title.
it didnt work in the in calibre test but it does in calibre some of the time.
thnx for the help neways.
p_garvie is offline   Reply With Quote
Old 09-17-2012, 07:05 PM   #10
p_garvie
Junior Member
p_garvie began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Sep 2012
Device: samsung galaxy note(cool reader), Kobo & Kobo Touch
unless of course theres info in the file itself that calibre looks at??
p_garvie is offline   Reply With Quote
Old 09-17-2012, 07:07 PM   #11
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,703
Karma: 54369092
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 p_garvie View Post
actually it seems to work for most of them its just a few that messes up
cuz like i said i have them set into directories of author then directories of series then their all done as a number and title of the book
c:\books\anthony, piers\xanth\01 - A spell for chameleon.pdb
so when i gather books from directories including their sub directory i just brows to the directory the books are in and it takes the authors directory as the authors name and the second directory as the series but it doesnt do it all the time for some reason and i have to number them manually as the numbers are part of the title.
it didnt work in the in calibre test but it does in calibre some of the time.
thnx for the help neways.
That info is probably in the Metadata insid the book.
It all depends on the setting in 'Adding Books': Filename or Metadata
theducks is offline   Reply With Quote
Old 09-18-2012, 02:59 AM   #12
DoctorOhh
US Navy, Retired
DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.DoctorOhh ought to be getting tired of karma fortunes by now.
 
DoctorOhh's Avatar
 
Posts: 9,864
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Nexus 7
If you want to get the info from the file name then you are going to have to rename the files to include the info you now have in the directory structure prior to adding the books. As theducks stated whether you grab metadata info from the filename or from the book can be found in Preferences - Adding books check or uncheck the top box as desired.
DoctorOhh is offline   Reply With Quote
Reply

Tags
calibre add book, regesp, regex, regular expression, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
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
understandng the sample add books regex cybmole Library Management 11 03-02-2011 06:08 AM
Add book regex no longer works magphil Calibre 3 03-24-2010 03:40 PM
How the new 0.6.45 Add new formats to existing books option works Starson17 Calibre 8 03-14-2010 01:27 PM


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


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