1
0
mirror of https://github.com/janeczku/calibre-web.git synced 2024-11-26 08:51:05 +02:00
calibre-web/cps/uploader.py
OzzieIsaacs ba44a15891 changes for #77
Code cosmetics
#75:
- More debug infos for kindlegen and sending e-mail.
- Button for sending test e-mail.
- timeout of 5min for sending e-mail
2016-12-23 09:53:39 +01:00

28 lines
736 B
Python

import os
from tempfile import gettempdir
import hashlib
from collections import namedtuple
import book_formats
BookMeta = namedtuple('BookMeta', 'file_path, extension, title, author, cover, description, tags, series, series_id')
"""
:rtype: BookMeta
"""
def upload(file):
tmp_dir = os.path.join(gettempdir(), 'calibre_web')
if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir)
filename = file.filename
filename_root, file_extension = os.path.splitext(filename)
md5 = hashlib.md5()
md5.update(filename.encode('utf-8'))
tmp_file_path = os.path.join(tmp_dir, md5.hexdigest())
file.save(tmp_file_path)
meta = book_formats.process(tmp_file_path, filename_root, file_extension)
return meta