11-28-2010, 10:25 AM | #1 |
Junior Member
Posts: 2
Karma: 10
Join Date: Nov 2010
Device: none
|
A little help adding books and using regex.
Hello.
I love Calibre and use it to organize my ebook library. It's awesome. I do have one issue though: the regular expression that deals with the name of the file being added. I'm sure this is a common issue with a simple solution that would make me feel like an idiot for not figuring it out. The thing is I have never gotten along too well with regular expressions so I need a little help. For the record I have looked up regular expressions as used by calibre and tried to figure them out, then tried to look for a solution. I really hope some helpful soul will lend me a hand. The files I add are usually named in two ways depending on if they are part of a series or not: author_name - series_name series_index - book_title.extension or author_name - book_title.extension. The regular expression I use is this: (?P<author>[^_]+) - (?P<series>.+) (?P<series_index>.+) - (?P<title>.+) which works well when adding series but not when adding individual books, which is when I edit the prefferences and delete the middle part resulting in this: (?P<author>[^_]+) - (?P<title>.+) I kept trying to make the deleted part optional so it would work in both cases automatically but I just can't get my head around it. Is it possible to come up with a regular expression that deals with both cases favorably? Thank you. |
11-28-2010, 10:33 AM | #2 |
Calibre Plugins Developer
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
There's a bunch of threads on this around the forums.
The one I use is this: Code:
^(?P<author>((?!\s-\s).)+)\s-\s(?:(?:\[\s*)?(?P<series>.+)\s(?P<series_index>[\d\.]+)(?:\s*\])?\s-\s)?(?P<title>[^(]+)(?:\(.*\))? |
11-28-2010, 10:37 AM | #3 |
Junior Member
Posts: 2
Karma: 10
Join Date: Nov 2010
Device: none
|
Thank you. I was certain there would be some threads on this but I just couldn't seem to be able to find them. Perhaps I should have tried harder.
Anyway, thank you very much. It works perfectly. |
12-15-2010, 08:43 AM | #4 | |
Junior Member
Posts: 2
Karma: 10
Join Date: Dec 2010
Device: Palm Treo Pro (WM 6.1) and LG Optimus Smartphone (Android)
|
Quote:
Would you please give me a plaintext example of a complete "author series seriesindex title" that your regex digests with whatever punctuation is used? I can't read the regex and figure out what's code and punctuation from the expression and what is data expected to be in the filename. I'm a new user that needs to edit a bunch of filenames and want to make sure they are correct. Thanks! |
|
12-15-2010, 09:22 AM | #5 |
Wizard
Posts: 3,130
Karma: 91256
Join Date: Feb 2008
Location: Germany
Device: Cybook Gen3
|
The easiest way would be adapting the regex to the filename, not vice versa.
|
12-15-2010, 09:37 AM | #6 | |
Wizard
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
|
Quote:
Most people keep a couple of fancy regex expressions around for different order filenames, such as, title first, title last, etc. I'd suggest testing your filenames against some of the available regex expressions. If none work, then I agree with Manichean that modifying the regex is the next step, but I wouldn't start from the complex encrusted regexes you find, as they can be intimidating if you haven't gotten a handle on the basics. If he asks for help, he should post some sample filenames he has, then I'm sure that help will quickly be offered. |
|
12-17-2010, 05:27 PM | #7 |
Junior Member
Posts: 2
Karma: 10
Join Date: Dec 2010
Device: Palm Treo Pro (WM 6.1) and LG Optimus Smartphone (Android)
|
Thanks all, I ran a few experiments and the regex works nicely.
|
12-17-2010, 06:57 PM | #8 | |
Calibre Plugins Developer
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Quote:
I posted that regex because it would work for the OP's named request. Specifically it is designed to handle: Author - Series # - Title Author - Title In my case it would handle filenames like these: Bloggs, Joe - My title Bloggs, Joe - Some Series 1 - My title Bloggs, Joe - Some Series 1.5 - My title Bloggs, Joe - Some Series 1.5 - My title with sub-title hyphen One further comment. I actually find it faster to change the filenames into a standard format, than it is to switch regexes, particularly if you have a bunch of books with randomly formatted names. I slice and dice the filenames of the files to match my regex and then do a bulk import. I found it way too fiddly to keep changing the regex in Calibre, particularly as it keeps no history so you have to store them all externally and keep pasting them in before an add operation. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Specify Tags when Adding Books | barium | Calibre | 3 | 09-13-2010 07:11 PM |
Adding books to my EZReader | readinggal | Astak EZReader | 26 | 02-19-2010 08:57 PM |
Regex search author field to locate books? | Starson17 | Calibre | 2 | 12-21-2009 10:40 AM |
Adding books without a copy | Sanderfox | Calibre | 5 | 12-02-2009 02:32 PM |
Help with adding books please | stustaff | Calibre | 12 | 10-27-2009 02:30 PM |