mirror of
				https://github.com/janeczku/calibre-web
				synced 2025-10-31 07:13:02 +00:00 
			
		
		
		
	Merge remote-tracking branch 'merge-metadata'
This commit is contained in:
		| @@ -105,7 +105,7 @@ def get_comic_info(tmp_file_path, original_file_name, original_file_extension): | ||||
|                 file_path=tmp_file_path, | ||||
|                 extension=original_file_extension, | ||||
|                 title=loadedMetadata.title or original_file_name, | ||||
|                 author=" & ".join([credit["person"] for credit in loadedMetadata.credits if credit["role"] == "Writer"]) or u"Unknown", | ||||
|                 author=" & ".join([credit["person"] for credit in loadedMetadata.credits if credit["role"] == "Writer"]) or u'Unknown', | ||||
|                 cover=extractCover(tmp_file_path, original_file_extension), | ||||
|                 description=loadedMetadata.comments or "", | ||||
|                 tags="", | ||||
| @@ -118,7 +118,7 @@ def get_comic_info(tmp_file_path, original_file_name, original_file_extension): | ||||
|             file_path=tmp_file_path, | ||||
|             extension=original_file_extension, | ||||
|             title=original_file_name, | ||||
|             author=u"Unknown", | ||||
|             author=u'Unknown', | ||||
|             cover=extractCover(tmp_file_path, original_file_extension), | ||||
|             description="", | ||||
|             tags="", | ||||
|   | ||||
| @@ -360,6 +360,9 @@ def upload_single_file(request, book, book_id): | ||||
|             worker.add_upload(current_user.nickname, | ||||
|                 "<a href=\"" + url_for('web.show_book', book_id=book.id) + "\">" + uploadText + "</a>") | ||||
|  | ||||
|             return uploader.process( | ||||
|                 saved_filename, *os.path.splitext(requested_file.filename)) | ||||
|  | ||||
|  | ||||
| def upload_cover(request, book): | ||||
|     if 'btn-upload-cover' in request.files: | ||||
| @@ -393,17 +396,18 @@ def edit_book(book_id): | ||||
|         flash(_(u"Error opening eBook. File does not exist or file is not accessible"), category="error") | ||||
|         return redirect(url_for("web.index")) | ||||
|  | ||||
|     upload_single_file(request, book, book_id) | ||||
|     meta = upload_single_file(request, book, book_id) | ||||
|     if upload_cover(request, book) is True: | ||||
|         book.has_cover = 1 | ||||
|     try: | ||||
|         to_save = request.form.to_dict() | ||||
|         merge_metadata(to_save, meta) | ||||
|         # Update book | ||||
|         edited_books_id = None | ||||
|         #handle book title | ||||
|         if book.title != to_save["book_title"].rstrip().strip(): | ||||
|             if to_save["book_title"] == '': | ||||
|                 to_save["book_title"] = _(u'unknown') | ||||
|                 to_save["book_title"] = _(u'Unknown') | ||||
|             book.title = to_save["book_title"].rstrip().strip() | ||||
|             edited_books_id = book.id | ||||
|  | ||||
| @@ -412,7 +416,7 @@ def edit_book(book_id): | ||||
|         input_authors = list(map(lambda it: it.strip().replace(',', '|'), input_authors)) | ||||
|         # we have all author names now | ||||
|         if input_authors == ['']: | ||||
|             input_authors = [_(u'unknown')]  # prevent empty Author | ||||
|             input_authors = [_(u'Unknown')]  # prevent empty Author | ||||
|  | ||||
|         modify_database_object(input_authors, book.authors, db.Authors, db.session, 'author') | ||||
|  | ||||
| @@ -531,6 +535,20 @@ def edit_book(book_id): | ||||
|         return redirect(url_for('web.show_book', book_id=book.id)) | ||||
|  | ||||
|  | ||||
| def merge_metadata(to_save, meta): | ||||
|     if to_save['author_name'] == _(u'Unknown'): | ||||
|         to_save['author_name'] = '' | ||||
|     if to_save['book_title'] == _(u'Unknown'): | ||||
|         to_save['book_title'] = '' | ||||
|     for s_field, m_field in [ | ||||
|             ('tags', 'tags'), ('author_name', 'author'), ('series', 'series'), | ||||
|             ('series_index', 'series_id'), ('languages', 'languages'), | ||||
|             ('book_title', 'title')]: | ||||
|         to_save[s_field] = to_save[s_field] or getattr(meta, m_field, '') | ||||
|     to_save["description"] = to_save["description"] or Markup( | ||||
|         getattr(meta, 'description', '')).unescape() | ||||
|  | ||||
|  | ||||
| @editbook.route("/upload", methods=["GET", "POST"]) | ||||
| @login_required_if_no_ano | ||||
| @upload_required | ||||
| @@ -573,7 +591,7 @@ def upload(): | ||||
|             filepath = os.path.join(config.config_calibre_dir, author_dir, title_dir) | ||||
|             saved_filename = os.path.join(filepath, title_dir + meta.extension.lower()) | ||||
|  | ||||
|             if title != u'Unknown' and authr != u'Unknown': | ||||
|             if title != _(u'Unknown') and authr != _(u'Unknown'): | ||||
|                 entry = helper.check_exists_book(authr, title) | ||||
|                 if entry: | ||||
|                     log.info("Uploaded book probably exists in library") | ||||
|   | ||||
| @@ -71,19 +71,19 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension): | ||||
|             else: | ||||
|                 epub_metadata[s] = p.xpath('dc:%s/text()' % s, namespaces=ns)[0] | ||||
|         else: | ||||
|             epub_metadata[s] = "Unknown" | ||||
|             epub_metadata[s] = u'Unknown' | ||||
|  | ||||
|     if epub_metadata['subject'] == "Unknown": | ||||
|     if epub_metadata['subject'] == u'Unknown': | ||||
|         epub_metadata['subject'] = '' | ||||
|  | ||||
|     if epub_metadata['description'] == "Unknown": | ||||
|     if epub_metadata['description'] == u'Unknown': | ||||
|         description = tree.xpath("//*[local-name() = 'description']/text()") | ||||
|         if len(description) > 0: | ||||
|             epub_metadata['description'] = description | ||||
|         else: | ||||
|             epub_metadata['description'] = "" | ||||
|  | ||||
|     if epub_metadata['language'] == "Unknown": | ||||
|     if epub_metadata['language'] == u'Unknown': | ||||
|         epub_metadata['language'] = "" | ||||
|     else: | ||||
|         lang = epub_metadata['language'].split('-', 1)[0].lower() | ||||
|   | ||||
| @@ -21,6 +21,8 @@ from __future__ import division, print_function, unicode_literals | ||||
| import os | ||||
| import hashlib | ||||
| from tempfile import gettempdir | ||||
| from flask_babel import gettext as _ | ||||
|  | ||||
| from . import logger, comic | ||||
| from .constants import BookMeta | ||||
|  | ||||
| @@ -91,6 +93,8 @@ def process(tmp_file_path, original_file_name, original_file_extension): | ||||
|         log.warning('cannot parse metadata, using default: %s', ex) | ||||
|  | ||||
|     if meta and meta.title.strip() and meta.author.strip(): | ||||
|         if meta.author.lower() == 'unknown': | ||||
|             meta = meta._replace(author=_(u'Unknown')) | ||||
|         return meta | ||||
|     else: | ||||
|         return default_meta(tmp_file_path, original_file_name, original_file_extension) | ||||
| @@ -101,7 +105,7 @@ def default_meta(tmp_file_path, original_file_name, original_file_extension): | ||||
|         file_path=tmp_file_path, | ||||
|         extension=original_file_extension, | ||||
|         title=original_file_name, | ||||
|         author=u"Unknown", | ||||
|         author=_(u'Unknown'), | ||||
|         cover=None, | ||||
|         description="", | ||||
|         tags="", | ||||
| @@ -119,13 +123,14 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension): | ||||
|         doc_info = None | ||||
|  | ||||
|     if doc_info is not None: | ||||
|         author = doc_info.author if doc_info.author else u"Unknown" | ||||
|         author = doc_info.author if doc_info.author else u'Unknown' | ||||
|         title = doc_info.title if doc_info.title else original_file_name | ||||
|         subject = doc_info.subject | ||||
|     else: | ||||
|         author = u"Unknown" | ||||
|         author = u'Unknown' | ||||
|         title = original_file_name | ||||
|         subject = "" | ||||
|  | ||||
|     return BookMeta( | ||||
|         file_path=tmp_file_path, | ||||
|         extension=original_file_extension, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Ozzieisaacs
					Ozzieisaacs