created do_calibre_export
function
This commit is contained in:
parent
fc7ce8da2d
commit
0b4731913e
|
@ -894,9 +894,10 @@ def save_cover(img, book_path):
|
||||||
|
|
||||||
|
|
||||||
def do_download_file(book, book_format, client, data, headers):
|
def do_download_file(book, book_format, client, data, headers):
|
||||||
|
book_name = data.name
|
||||||
if config.config_use_google_drive:
|
if config.config_use_google_drive:
|
||||||
# startTime = time.time()
|
# startTime = time.time()
|
||||||
df = gd.getFileFromEbooksFolder(book.path, data.name + "." + book_format)
|
df = gd.getFileFromEbooksFolder(book.path, book_name + "." + book_format)
|
||||||
# log.debug('%s', time.time() - startTime)
|
# log.debug('%s', time.time() - startTime)
|
||||||
if df:
|
if df:
|
||||||
return gd.do_gdrive_download(df, headers)
|
return gd.do_gdrive_download(df, headers)
|
||||||
|
@ -904,14 +905,25 @@ def do_download_file(book, book_format, client, data, headers):
|
||||||
abort(404)
|
abort(404)
|
||||||
else:
|
else:
|
||||||
filename = os.path.join(config.config_calibre_dir, book.path)
|
filename = os.path.join(config.config_calibre_dir, book.path)
|
||||||
if not os.path.isfile(os.path.join(filename, data.name + "." + book_format)):
|
if not os.path.isfile(os.path.join(filename, book_name + "." + book_format)):
|
||||||
# ToDo: improve error handling
|
# ToDo: improve error handling
|
||||||
log.error('File not found: %s', os.path.join(filename, data.name + "." + book_format))
|
log.error('File not found: %s', os.path.join(filename, book_name + "." + book_format))
|
||||||
|
|
||||||
if client == "kobo" and book_format == "kepub":
|
if client == "kobo" and book_format == "kepub":
|
||||||
headers["Content-Disposition"] = headers["Content-Disposition"].replace(".kepub", ".kepub.epub")
|
headers["Content-Disposition"] = headers["Content-Disposition"].replace(".kepub", ".kepub.epub")
|
||||||
|
|
||||||
if config.config_binariesdir:
|
if config.config_binariesdir:
|
||||||
|
filename, book_name = do_calibre_export(book, book_format)
|
||||||
|
|
||||||
|
response = make_response(send_from_directory(filename, book_name + "." + book_format))
|
||||||
|
# ToDo Check headers parameter
|
||||||
|
for element in headers:
|
||||||
|
response.headers[element[0]] = element[1]
|
||||||
|
log.info('Downloading file: {}'.format(os.path.join(filename, book_name + "." + book_format)))
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def do_calibre_export(book, book_format):
|
||||||
try:
|
try:
|
||||||
quotes = [3, 5, 7, 9]
|
quotes = [3, 5, 7, 9]
|
||||||
tmp_dir = os.path.join(gettempdir(), 'calibre_web')
|
tmp_dir = os.path.join(gettempdir(), 'calibre_web')
|
||||||
|
@ -928,16 +940,11 @@ def do_download_file(book, book_format, client, data, headers):
|
||||||
_, err = p.communicate()
|
_, err = p.communicate()
|
||||||
if err:
|
if err:
|
||||||
log.error('Metadata embedder encountered an error: %s', err)
|
log.error('Metadata embedder encountered an error: %s', err)
|
||||||
|
return tmp_dir, file_name
|
||||||
except OSError as ex:
|
except OSError as ex:
|
||||||
# ToDo real error handling
|
# ToDo real error handling
|
||||||
log.error_or_exception(ex)
|
log.error_or_exception(ex)
|
||||||
|
|
||||||
response = make_response(send_from_directory(tmp_dir, file_name + "." + book_format))
|
|
||||||
# ToDo Check headers parameter
|
|
||||||
for element in headers:
|
|
||||||
response.headers[element[0]] = element[1]
|
|
||||||
log.info('Downloading file: {}'.format(os.path.join(filename, data.name + "." + book_format)))
|
|
||||||
return response
|
|
||||||
|
|
||||||
##################################
|
##################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user