1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-16 14:54:55 +00:00
calibre-web/cps/uploader.py
林檎 29f21480ab Reuse original code logic.
iteration loop dc:*  add dc:language

removal of bookmeta[‘comments’] , reusing bootmeta[‘description’]
2017-03-04 15:37:30 +08:00

31 lines
794 B
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
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, languages')
"""
: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