openmedialibrary/oml/media/cbz.py

37 lines
775 B
Python
Raw Normal View History

2019-01-29 10:20:43 +00:00
# -*- coding: utf-8 -*-
2019-02-01 12:57:58 +00:00
import logging
2019-01-29 10:20:43 +00:00
import os
import zipfile
import ox
2019-02-01 12:57:58 +00:00
from .cbr import filter_images
2019-02-01 12:23:17 +00:00
logger = logging.getLogger(__name__)
2019-01-29 10:20:43 +00:00
def cover(path):
data = None
logger.debug('cover %s', path)
data = None
try:
z = zipfile.ZipFile(path)
except zipfile.BadZipFile:
logger.debug('invalid zbc file %s', path)
return data
files = [f.filename for f in z.filelist]
2019-02-01 12:57:58 +00:00
files = filter_images(files)
2019-01-29 10:20:43 +00:00
if files:
2019-02-01 12:26:28 +00:00
cover = ox.sorted_strings(files)[0]
2019-01-29 13:16:12 +00:00
try:
data = z.read(cover)
except:
data = None
return data
2019-01-29 10:20:43 +00:00
def info(path):
data = {}
data['title'] = os.path.splitext(os.path.basename(path))[0]
#data['pages'] = fixme read rar to count pages
return data