1
0
mirror of https://github.com/janeczku/calibre-web.git synced 2024-11-28 08:58:41 +02:00

redid comic importing support to handle metadata properly using comicapi from comictagger. needs work to automate installation

This commit is contained in:
Iris Wildthyme 2019-04-02 18:52:45 -04:00
parent 4b301a7961
commit 05d0f12608
2 changed files with 39 additions and 30 deletions

4
.gitignore vendored
View File

@ -29,3 +29,7 @@ gdrive_credentials
vendor
client_secrets.json
# External dependencies - need proper integrating
comicapi
libunrar

65
cps/comic.py Normal file → Executable file
View File

@ -17,33 +17,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import zipfile
import tarfile
import os
import uploader
from comicapi.comicarchive import *
from comicapi.issuestring import *
from iso639 import languages as isoLanguages
def extractCover(tmp_file_name, original_file_extension):
archive = ComicArchive(tmp_file_name)
cover_data = None
if original_file_extension.upper() == '.CBZ':
cf = zipfile.ZipFile(tmp_file_name)
for name in cf.namelist():
ext = os.path.splitext(name)
if len(ext) > 1:
extension = ext[1].lower()
if extension == '.jpg':
cover_data = cf.read(name)
break
elif original_file_extension.upper() == '.CBT':
cf = tarfile.TarFile(tmp_file_name)
for name in cf.getnames():
ext = os.path.splitext(name)
if len(ext) > 1:
extension = ext[1].lower()
if extension == '.jpg':
cover_data = cf.extractfile(name).read()
break
ext = os.path.splitext(archive.getPageName(0))
if len(ext) > 1:
extension = ext[1].lower()
if extension == '.jpg' or extension == '.jpeg':
cover_data = archive.getPage(0)
print(archive.getPageName(0))
prefix = os.path.dirname(tmp_file_name)
if cover_data:
tmp_cover_name = prefix + '/cover' + extension
@ -56,17 +44,34 @@ def extractCover(tmp_file_name, original_file_extension):
def get_comic_info(tmp_file_path, original_file_name, original_file_extension):
archive = ComicArchive(tmp_file_path)
if archive.seemsToBeAComicArchive():
if archive.hasMetadata(MetaDataStyle.CIX):
style = MetaDataStyle.CIX
elif archive.hasMetadata(MetaDataStyle.CBI):
style = MetaDataStyle.CBI
else:
style = None
coverfile = extractCover(tmp_file_path, original_file_extension)
if style is not None:
loadedMetadata = archive.readMetadata(style)
lang = loadedMetadata.language
if len(lang) == 2:
loadedMetadata.language = isoLanguages.get(part1=lang).name
elif len(lang) == 3:
loadedMetadata.language = isoLanguages.get(part3=lang).name
else:
loadedMetadata.language = ""
return uploader.BookMeta(
file_path=tmp_file_path,
extension=original_file_extension,
title=original_file_name,
author=u"Unknown",
cover=coverfile,
description="",
title=loadedMetadata.title or original_file_name,
author=" & ".join([credit["person"] for credit in loadedMetadata.credits if credit["role"] == "Writer"]) or u"Unknown",
cover=extractCover(tmp_file_path, original_file_extension),
description=loadedMetadata.comments or "",
tags="",
series="",
series_id="",
languages="")
series=loadedMetadata.series or "",
series_id=loadedMetadata.issue or "",
languages=loadedMetadata.language)