mirror of
https://github.com/JonathanHerrewijnen/calibre-web.git
synced 2024-11-10 21:24:15 +00:00
Import covers from comic files during upload
This commit is contained in:
parent
5809acfa9e
commit
319077aea9
@ -5,6 +5,7 @@ import logging
|
||||
import uploader
|
||||
import os
|
||||
from flask_babel import gettext as _
|
||||
import comic
|
||||
|
||||
__author__ = 'lemmsh'
|
||||
|
||||
@ -49,6 +50,9 @@ def process(tmp_file_path, original_file_name, original_file_extension):
|
||||
meta = epub.get_epub_info(tmp_file_path, original_file_name, original_file_extension)
|
||||
if ".FB2" == original_file_extension.upper() and use_fb2_meta is True:
|
||||
meta = fb2.get_fb2_info(tmp_file_path, original_file_extension)
|
||||
if original_file_extension.upper() in ['.CBZ', '.CBT']:
|
||||
meta = comic.get_comic_info(tmp_file_path, original_file_name, original_file_extension)
|
||||
|
||||
except Exception as ex:
|
||||
logger.warning('cannot parse metadata, using default: %s', ex)
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import os
|
||||
|
||||
|
43
cps/comic.py
Normal file
43
cps/comic.py
Normal file
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import zipfile
|
||||
import tarfile
|
||||
import os
|
||||
import uploader
|
||||
|
||||
|
||||
def extractCover(tmp_file_name, original_file_extension):
|
||||
if original_file_extension.upper() == '.CBZ':
|
||||
cf = zipfile.ZipFile(tmp_file_name)
|
||||
compressed_name = cf.namelist()[0]
|
||||
cover_data = cf.read(compressed_name)
|
||||
elif original_file_extension.upper() == '.CBT':
|
||||
cf = tarfile.TarFile(tmp_file_name)
|
||||
compressed_name = cf.getnames()[0]
|
||||
cover_data = cf.extractfile(compressed_name).read()
|
||||
|
||||
prefix = os.path.dirname(tmp_file_name)
|
||||
|
||||
tmp_cover_name = prefix + '/cover' + os.path.splitext(compressed_name)[1]
|
||||
image = open(tmp_cover_name, 'wb')
|
||||
image.write(cover_data)
|
||||
image.close()
|
||||
return tmp_cover_name
|
||||
|
||||
|
||||
def get_comic_info(tmp_file_path, original_file_name, original_file_extension):
|
||||
|
||||
coverfile = extractCover(tmp_file_path, original_file_extension)
|
||||
|
||||
return uploader.BookMeta(
|
||||
file_path=tmp_file_path,
|
||||
extension=original_file_extension,
|
||||
title=original_file_name,
|
||||
author=u"Unknown",
|
||||
cover=coverfile,
|
||||
description="",
|
||||
tags="",
|
||||
series="",
|
||||
series_id="",
|
||||
languages="")
|
Loading…
Reference in New Issue
Block a user