diff --git a/cps/editbooks.py b/cps/editbooks.py index 7330572b..93ed4acb 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -375,7 +375,8 @@ def edit_book_publisher(to_save, book): if to_save["publisher"]: publisher = to_save["publisher"].rstrip().strip() if len(book.publishers) == 0 or (len(book.publishers) > 0 and publisher != book.publishers[0].name): - changed |= modify_database_object([publisher], book.publishers, db.Publishers, calibre_db.session, 'publisher') + changed |= modify_database_object([publisher], book.publishers, db.Publishers, calibre_db.session, + 'publisher') elif len(book.publishers): changed |= modify_database_object([], book.publishers, db.Publishers, calibre_db.session, 'publisher') return changed diff --git a/cps/helper.py b/cps/helper.py index a931f970..d40128d7 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -237,22 +237,22 @@ def get_valid_filename(value, replace_whitespace=True): value = value[:-1]+u'_' value = value.replace("/", "_").replace(":", "_").strip('\0') if use_unidecode: - value = (unidecode.unidecode(value)).strip() + value = (unidecode.unidecode(value)) else: value = value.replace(u'§', u'SS') value = value.replace(u'ß', u'ss') value = unicodedata.normalize('NFKD', value) re_slugify = re.compile(r'[\W\s-]', re.UNICODE) if isinstance(value, str): # Python3 str, Python2 unicode - value = re_slugify.sub('', value).strip() + value = re_slugify.sub('', value) else: - value = unicode(re_slugify.sub('', value).strip()) + value = unicode(re_slugify.sub('', value)) if replace_whitespace: # *+:\"/<>? are replaced by _ - value = re.sub(r'[\*\+:\\\"/<>\?]+', u'_', value, flags=re.U) + value = re.sub(r'[*+:\\\"/<>?]+', u'_', value, flags=re.U) # pipe has to be replaced with comma - value = re.sub(r'[\|]+', u',', value, flags=re.U) - value = value[:128] + value = re.sub(r'[|]+', u',', value, flags=re.U) + value = value[:128].strip() if not value: raise ValueError("Filename cannot be empty") if sys.version_info.major == 3: @@ -269,11 +269,11 @@ def split_authors(values): commas = author.count(',') if commas == 1: author_split = author.split(',') - authors_list.append(author_split[1] + ' ' + author_split[0]) + authors_list.append(author_split[1].strip() + ' ' + author_split[0].strip()) elif commas > 1: - authors_list.append(author.split(',')) + authors_list.extend([x.strip() for x in author.split(',')]) else: - authors_list.append(author) + authors_list.append(author.strip()) return authors_list @@ -284,7 +284,10 @@ def get_sorted_author(value): combined = "(" + ")|(".join(regexes) + ")" value = value.split(" ") if re.match(combined, value[-1].upper()): - value2 = value[-2] + ", " + " ".join(value[:-2]) + " " + value[-1] + if len(value) > 1: + value2 = value[-2] + ", " + " ".join(value[:-2]) + " " + value[-1] + else: + value2 = value[0] elif len(value) == 1: value2 = value[0] else: @@ -293,7 +296,10 @@ def get_sorted_author(value): value2 = value except Exception as ex: log.error("Sorting author %s failed: %s", value, ex) - value2 = value + if isinstance(list, value2): + value2 = value[0] + else: + value2 = value return value2 diff --git a/cps/uploader.py b/cps/uploader.py index e693d8e8..2cb982b9 100644 --- a/cps/uploader.py +++ b/cps/uploader.py @@ -24,6 +24,7 @@ from flask_babel import gettext as _ from . import logger, comic from .constants import BookMeta +from .helper import split_authors log = logger.create() @@ -131,7 +132,7 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension): file_path=tmp_file_path, extension=original_file_extension, title=title, - author=author, + author=' & '.join(split_authors([author])), cover=pdf_preview(tmp_file_path, original_file_name), description=subject, tags="",