openmedialibrary/oml/media/cbr.py

27 lines
549 B
Python
Raw Normal View History

2015-03-14 13:05:15 +05:30
# -*- coding: utf-8 -*-
import os
2019-01-29 15:50:43 +05:30
import ox
2015-03-14 13:05:15 +05:30
def cover(path):
data = None
#open rar file and extract first page here
2019-01-29 15:50:43 +05:30
try:
from unrar import rarfile
rar = rarfile.RarFile(path)
2019-01-29 18:46:12 +05:30
files = rar.namelist()
if files:
cover = ox.sorted_strings(files)[0]
data = rar.read(cover)
2019-01-29 15:50:43 +05:30
except:
data = None
2015-03-14 13:05:15 +05:30
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