From 019f1c8fb2c2fcab2ecccb54b25cb262feaf07f2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 6 Oct 2020 20:23:55 +0530 Subject: [PATCH] Also fallback to version 0 regexps for reading metadata from filenames Fixes #1898739 [Viewer fail opening books](https://bugs.launchpad.net/calibre/+bug/1898739) --- src/calibre/ebooks/metadata/meta.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/metadata/meta.py b/src/calibre/ebooks/metadata/meta.py index a41e408a3c..077257e36f 100644 --- a/src/calibre/ebooks/metadata/meta.py +++ b/src/calibre/ebooks/metadata/meta.py @@ -133,7 +133,10 @@ def metadata_from_filename(name, pat=None, fallback_pat=None): name = name.rpartition('.')[0] mi = MetaInformation(None, None) if pat is None: - pat = regex.compile(prefs.get('filename_pattern'), flags=regex.UNICODE | regex.VERSION1 | regex.FULLCASE) + try: + pat = regex.compile(prefs.get('filename_pattern'), flags=regex.UNICODE | regex.VERSION1 | regex.FULLCASE) + except Exception: + pat = regex.compile(prefs.get('filename_pattern'), flags=regex.UNICODE | regex.VERSION0 | regex.FULLCASE) name = name.replace('_', ' ') match = pat.search(name) if match is None and fallback_pat is not None: