openmedialibrary/oml/media/cbr.py
2019-02-01 18:27:58 +05:30

34 lines
786 B
Python

# -*- coding: utf-8 -*-
import logging
import os
import ox
logger = logging.getLogger(__name__)
IMAGE_EXTENSIONS = ['.jpg', '.png', '.gif']
def filter_images(files):
return [f for f in files if os.path.splitext(f)[-1] in IMAGE_EXTENSION]
def cover(path):
data = None
#open rar file and extract first page here
try:
from unrar import rarfile
rar = rarfile.RarFile(path)
files = rar.namelist()
files = filter_images(files)
if files:
cover = ox.sorted_strings(files)[0]
data = rar.read(cover)
except:
data = None
return data
def info(path):
data = {}
data['title'] = os.path.splitext(os.path.basename(path))[0]
#data['pages'] = fixme read rar to count pages
return data