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

refactoring to make adding new formats possible

This commit is contained in:
Pavel Yakunin
2016-06-05 18:41:47 +03:00
parent db70e47557
commit 027e103ce3
3 changed files with 101 additions and 22 deletions

30
cps/uploader.py Normal file
View File

@@ -0,0 +1,30 @@
import os
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):
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)
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