Commit d01d7b91 authored by OzzieIsaacs's avatar OzzieIsaacs

Added error messages in log and UI if cover url can't downloaded, changed...

Added error messages in log and UI if cover url can't downloaded, changed label for cover URL to clarify function #449
parent f6ece5fe
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
<input type="number" name="rating" id="rating" class="rating input-lg" data-clearable="" value="{% if book.ratings %}{{(book.ratings[0].rating / 2)|int}}{% endif %}"> <input type="number" name="rating" id="rating" class="rating input-lg" data-clearable="" value="{% if book.ratings %}{{(book.ratings[0].rating / 2)|int}}{% endif %}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="cover_url">{{_('Cover URL (jpg)')}}</label> <label for="cover_url">{{_('Cover URL (jpg, cover is downloaded and stored in database, field is afterwards empty again)')}}</label>
<input type="text" class="form-control" name="cover_url" id="cover_url" value=""> <input type="text" class="form-control" name="cover_url" id="cover_url" value="">
</div> </div>
......
...@@ -3002,8 +3002,11 @@ def edit_book(book_id): ...@@ -3002,8 +3002,11 @@ def edit_book(book_id):
updateGdriveCalibreFromLocal() updateGdriveCalibreFromLocal()
if not error: if not error:
if to_save["cover_url"] and save_cover(to_save["cover_url"], book.path): if to_save["cover_url"]:
book.has_cover = 1 if save_cover(to_save["cover_url"], book.path) is true:
book.has_cover = 1
else:
flash(_(u"Cover is not a jpg file, can't save"), category="error")
if book.series_index != to_save["series_index"]: if book.series_index != to_save["series_index"]:
book.series_index = to_save["series_index"] book.series_index = to_save["series_index"]
...@@ -3155,6 +3158,7 @@ def edit_book(book_id): ...@@ -3155,6 +3158,7 @@ def edit_book(book_id):
def save_cover(url, book_path): def save_cover(url, book_path):
img = requests.get(url) img = requests.get(url)
if img.headers.get('content-type') != 'image/jpeg': if img.headers.get('content-type') != 'image/jpeg':
app.logger.error("Cover is no jpg file, can't save")
return false return false
if config.config_use_google_drive: if config.config_use_google_drive:
...@@ -3163,11 +3167,13 @@ def save_cover(url, book_path): ...@@ -3163,11 +3167,13 @@ def save_cover(url, book_path):
f.write(img.content) f.write(img.content)
f.close() f.close()
gdriveutils.uploadFileToEbooksFolder(Gdrive.Instance().drive, os.path.join(book_path, 'cover.jpg'), os.path.join(tmpDir, f.name)) gdriveutils.uploadFileToEbooksFolder(Gdrive.Instance().drive, os.path.join(book_path, 'cover.jpg'), os.path.join(tmpDir, f.name))
app.logger.info("Cover is saved on gdrive")
return true return true
f = open(os.path.join(config.config_calibre_dir, book_path, "cover.jpg"), "wb") f = open(os.path.join(config.config_calibre_dir, book_path, "cover.jpg"), "wb")
f.write(img.content) f.write(img.content)
f.close() f.close()
app.logger.info("Cover is saved")
return true return true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment