1
0
mirror of https://github.com/janeczku/calibre-web synced 2025-11-21 17:34:49 +00:00

Uploader is working on windows

This commit is contained in:
OzzieIsaacs
2016-10-30 11:44:02 +01:00
parent 12db39523c
commit 313116dca7
3 changed files with 63 additions and 54 deletions

View File

@@ -1,25 +1,24 @@
import os
from tempfile import gettempdir
import hashlib
from collections import namedtuple
import book_formats
tmp_dir = "/tmp/calibre-web"
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)
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)