![]() |
#1 |
Junior Member
![]() 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. |
![]() |
![]() |
![]() |
#2 |
Junior Member
![]() 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* |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() 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.
|
![]() |
![]() |
![]() |
#4 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() 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>[^_].+) ? As an interesting note, in my older calibre version (0.8.55), your original regex did extract the book title correctly in the test. |
![]() |
![]() |
![]() |
#5 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,149
Karma: 27110894
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.
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Junior Member
![]() 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?? |
![]() |
![]() |
![]() |
#7 |
Junior Member
![]() 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. |
![]() |
![]() |
![]() |
#8 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,882
Karma: 59840450
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.
|
![]() |
![]() |
![]() |
#9 |
Junior Member
![]() 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. |
![]() |
![]() |
![]() |
#10 |
Junior Member
![]() 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??
|
![]() |
![]() |
![]() |
#11 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,882
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
It all depends on the setting in 'Adding Books': Filename or Metadata |
|
![]() |
![]() |
![]() |
#12 |
US Navy, Retired
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,888
Karma: 13806776
Join Date: Feb 2009
Location: North Carolina
Device: Icarus Illumina XL HD, Kindle PaperWhite SE 11th Gen
|
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.
|
![]() |
![]() |
![]() |
Tags |
calibre add book, regesp, regex, regular expression, regular expressions |
|
![]() |
||||
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 |