mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix reading metadata from filenames when the author regexp does not match anything
This commit is contained in:
parent
c0dc8bc5e0
commit
5ec89c0e9e
@ -22,6 +22,8 @@ except:
|
|||||||
_author_pat = re.compile(r'(?i),?\s+(and|with)\s+')
|
_author_pat = re.compile(r'(?i),?\s+(and|with)\s+')
|
||||||
|
|
||||||
def string_to_authors(raw):
|
def string_to_authors(raw):
|
||||||
|
if not raw:
|
||||||
|
return []
|
||||||
raw = raw.replace('&&', u'\uffff')
|
raw = raw.replace('&&', u'\uffff')
|
||||||
raw = _author_pat.sub('&', raw)
|
raw = _author_pat.sub('&', raw)
|
||||||
authors = [a.strip().replace(u'\uffff', '&') for a in raw.split('&')]
|
authors = [a.strip().replace(u'\uffff', '&') for a in raw.split('&')]
|
||||||
|
@ -149,19 +149,20 @@ def metadata_from_filename(name, pat=None):
|
|||||||
try:
|
try:
|
||||||
au = match.group('author')
|
au = match.group('author')
|
||||||
aus = string_to_authors(au)
|
aus = string_to_authors(au)
|
||||||
mi.authors = aus
|
if aus:
|
||||||
if prefs['swap_author_names'] and mi.authors:
|
mi.authors = aus
|
||||||
def swap(a):
|
if prefs['swap_author_names'] and mi.authors:
|
||||||
if ',' in a:
|
def swap(a):
|
||||||
parts = a.split(',', 1)
|
if ',' in a:
|
||||||
else:
|
parts = a.split(',', 1)
|
||||||
parts = a.split(None, 1)
|
else:
|
||||||
if len(parts) > 1:
|
parts = a.split(None, 1)
|
||||||
t = parts[-1]
|
if len(parts) > 1:
|
||||||
parts = parts[:-1]
|
t = parts[-1]
|
||||||
parts.insert(0, t)
|
parts = parts[:-1]
|
||||||
return ' '.join(parts)
|
parts.insert(0, t)
|
||||||
mi.authors = [swap(x) for x in mi.authors]
|
return ' '.join(parts)
|
||||||
|
mi.authors = [swap(x) for x in mi.authors]
|
||||||
except (IndexError, ValueError):
|
except (IndexError, ValueError):
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user