extract cover from cbr,cbz

This commit is contained in:
j 2019-01-29 15:50:43 +05:30
parent 58689cd4ff
commit 8fdda01d4d
3 changed files with 49 additions and 3 deletions

View file

@ -10,7 +10,7 @@ import ox
from . import pdf
from . import cbr
cbz = cbr
from . import cbz
from . import epub
from . import txt
from . import opf
@ -34,8 +34,10 @@ def metadata(f, from_=None):
data['size'] = os.stat(f).st_size
try:
if ext in ('cbr', 'cbz'):
if ext in ('cbr', ):
info = cbr.info(f)
elif ext in ('cbz', ):
info = cbz.info(f)
elif ext in ('epub', 'kepub'):
info = epub.info(f)
data['extension'] = 'epub'

View file

@ -2,11 +2,23 @@
import os
import ox
def cover(path):
data = None
#open rar file and extract first page here
try:
from unrar import rarfile
rar = rarfile.RarFile(path)
for cover in ox.sorted_strings(rar.namelist()):
try:
data = rar.read(cover)
except:
data = None
finally:
return data
except:
data = None
return data
def info(path):

32
oml/media/cbz.py Normal file
View file

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
import os
import zipfile
import ox
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]
if files:
for cover in ox.sortedstrings(files):
try:
data = z.read(cover)
except:
data = None
finally:
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