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