Quote:
Originally Posted by citac
I tried adding parentheses around (?P<author>[^_]+) followed by a question mark, but that didn't seem to do the trick.
|
That's no surprise....
Quote:
You said I needed to add some titles for you, so here they are if you're willing to have a look.
|
I did, but I have bad news.
Quote:
(?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*)
Brothers - 01 - Reading of the Will
|
Yes, that works.
Quote:
If I change it to ((?P<author>[^_]+))? - (?P<series>.+) - (?P<series_index>\d+) - (?P<title>.*) it doesn't work. Did I place the parentheses and question mark in the proper place?
|
Close, but not quite. That tells it that your match starts with a space-hyphen-space. When your book filenames don't have an author, you don't omit just the author, you also omit the subsequent space-hyphen-space.
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.