View Single Post
Old 04-21-2010, 05:22 PM   #9
citac
Fanatic
citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.citac ought to be getting tired of karma fortunes by now.
 
Posts: 556
Karma: 1020204
Join Date: Sep 2008
Location: Bosnia and Herzegovina
Device: Lenovo Yoga Tab 2 (Android)
Quote:
Originally Posted by Starson17 View Post
....I have bad news.

Here is what you wanted .. or more accurately, what I thought would work:
Code:
((?P<author>[^_]+) - )?(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
Note I moved your close parenthesis and put it around the space-hyphen-space and the author.

Unfortunately, when I did that, it worked great for the titles that have an author, but Calibre threw an error when it did not have an author.

I then tried this ({0,1} says the preceding is there zero or one times):
Code:
((?P<author>[^_]+) - ){0,1}(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
but that threw the same error.
Code:
ERROR: ERROR: Unhandled exception: <b>AttributeError</b>:'NoneType' object has no attribute 'replace'

Traceback (most recent call last):
  File "site-packages\calibre\gui2\widgets.py", line 74, in do_test
  File "site-packages\calibre\ebooks\metadata\meta.py", line 147, in metadata_from_filename
  File "site-packages\calibre\ebooks\metadata\__init__.py", line 20, in string_to_authors
AttributeError: 'NoneType' object has no attribute 'replace'
I'd need to look at the code to find out why. You may want to post a bug report. I think those should have worked. Calibre will normally substitute "Unknown" for an author name if it's blank, but making the author optional in this way potentially bypasses that code in a way that throws this error.

Sorry, but I'm out of ideas. I've never actually needed an optional author regex, and I'm a bit short on time to test it further.
First of all, thank you very much for your patience in walking me through totally unfamiliar territory for me. I gave up on Calibre the first time due to several reasons, but this time I wanted to try and learn how to use it and customize it as possible to fit my needs.

I will look into posting a bug report for this. In the mean time, I went through the Calibre forum one more time with a fine tooth comb, and found a thread where the OP requested help with something similar. There were several regexes there, and I tried each. Finally, it turned out this worked:

^((?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>.+)

It doesn't add "Unknown" but leaves the author's name completely blank. Why, I have no idea, and I guess you would understand it better than I do. Thanks again.
citac is offline   Reply With Quote