![]() |
#1 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 108
Karma: 810
Join Date: Jul 2012
Device: Kobo
|
Adding books - filename RegEx author FN (initials) LN
Apologies if an answer is already posted, but I couldn't find one as I struggle to understand RegEx (even with the help of RegEx Buddy). FWIW this is a special case situation where I do not have metadata and rely on the existing filename to determine the author and title.
(?P<author>.+) - (?P<title>[^_]+) is the default RegEx that I currently have under "preferences" for adding books to Calibre, for obtaining the author and title from the filename rather than from metadata, but that RegEx flips the order of FN LN for the author: filename 1: Tom Jones - My Book.epub resulting author: Jones Tom filename 2: Tom G. Jones - My Book.epub resulting author: G. Jones Tom I've tried other RegEx expressions that I have seen posted that are even more sophisticated, to optionally accommodate series name and number, but those RegEx all seem to have the same strange effect when determining the author. e.g. ^((?P<author>([^\-_0-9]+)(?=\s*-\s*)(?!\s*-\s*[0-9.]+)|\b))(\s*-\s*)?(\[?(?P<series>[^0-9\-]+) (- )?(?P<series_index>[0-9.]+)\]?\s*-\s*)?(?P<title>.+) I think I must be missing something because it seems non-intuitive for the default for these various RegEx approaches to switch the order of FN and LN as it appears in the filename. The results don't even generate the comma version of FN, LN so that the problem can be fixed in Calibre. Thanks for any help on this. |
![]() |
![]() |
![]() |
#2 | |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,645
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
@Rob557 - maybe its not the regex that flipping the names, maybe its settings in Tweaks
Quote:
BR |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 108
Karma: 810
Join Date: Jul 2012
Device: Kobo
|
Quote:
Within the Preferences / Adding Books screen there is basic test process for seeing the results of the RegEx script for a sample filename, and that test confirms the problem as well. |
|
![]() |
![]() |
![]() |
#4 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,645
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
@Rob557 - Every time I think I understand the author name handling something comes along that I don't understand.
I can't get the behaviour you are getting even if I try - see first attachment. No matter what value I put in Author sort name algorithm, what you see is what I get with that first template Surely the regex expression in the Add Books controls is limited to extraction? To change the name (after extracting) you would need a replace regex... wouldn't you? Something like "\2 \1", where \2 was the last token and \1 was everything before the last token. Added : I added the file Tom Jones - My Book.epub with that template, the resultant Metadata is shown in second attachment Can you confirm that's what you want, because I may be misunderstanding you ? BR Last edited by BetterRed; 10-15-2014 at 09:08 PM. |
![]() |
![]() |
![]() |
#5 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 108
Karma: 810
Join Date: Jul 2012
Device: Kobo
|
Hi BetterRed,
The RegEx that you used is a bit different from what I had as my current default, but when I use your RegEx you will see from the image that the result that it produces is different from yours. Very strange!?? One difference is that I am using Calibre version 2.3 and yours is 2.5 but I wouldn't think that would be the reason? I can look at updating the version tomorrow but would be surprised. Can you see anything else I might be missing? |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,645
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
@Rob557 - I think I found it, right under our under our collective blithering noses, see attachment - uncheck the highlighted box
![]() sorry - I guess I wont forget that one again Ψ² BR |
![]() |
![]() |
![]() |
#7 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 108
Karma: 810
Join Date: Jul 2012
Device: Kobo
|
Hi BetterRed,
You are correct. At first I thought you were mistaken because that box had no effect on the "test" results that are shown under Preferences / Adding Books, but now I realize that the "swap author first name and last name" means that the actual results when adding the book will differ from the "test" results by appropriately putting the first name first. To hopefully avoid confusion for others I've replaced my prior comments and attachments posted a couple minutes ago with this acknowledgment that you are correct about the importance of that box that you highlighted. I've left in the attachment that shows the comment for that option box is in fact applicable when relying on the filename to define the author and title. Hopefully you will see my revised comments as you form any further response. Thank you !!! Last edited by Rob557; 10-16-2014 at 10:26 AM. Reason: oops |
![]() |
![]() |
![]() |
#8 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 108
Karma: 810
Join Date: Jul 2012
Device: Kobo
|
Just adding a cautionary note with regards to how the RegEx "test" works under Preferences / Adding Books.
While applying that RegEx test, it turns out that the test results are NOT immediately/ directly affected by checking or unchecking the option box "Swap author, firstname and lastname". Instead, the test results will be dependent only on whether that box was checked or unchecked THE LAST TIME the option selection was saved using the "apply" button. That explains why, in my prior image attachment, the test results still show the firstname and lastname flipped around even though the option box is not checked. So long as the option box is unchecked, the actual results will be okay if that option selection is saved, and even the test results will be okay the next time the "Preferences / Adding books" RegEx test is run with that option box unchecked. |
![]() |
![]() |
![]() |
#9 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,645
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Maybe Test could be disabled if there are pending changes to the actual settings. Also the option should be moved so that it lines up with other controls such as Mark Books (see attachment) - IMO of course.
I only noticed the presence of the Swap author firstname lastname checkbox (its default value is off) when I installed a fresh portable and changed the first setting, Read metadata from file contents rather than file name, to do a test with a real file. BR |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
regex for filename with muliple dots? (adding books) | kite | Library Management | 5 | 09-28-2014 09:09 AM |
Adding books - regex help | tonyx3 | Library Management | 1 | 03-13-2013 08:21 AM |
Adding books with different filename structures | Sinnott | Library Management | 2 | 11-09-2012 08:12 AM |
Adding books with series in the filename | genright | Library Management | 5 | 06-13-2011 03:20 PM |
A little help adding books and using regex. | Dragonator | Calibre | 7 | 12-17-2010 06:57 PM |