mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
a311197af5
commit
5a9097f5c0
@ -270,18 +270,21 @@ def extract_member(path, match=re.compile(r'\.(jpg|jpeg|gif|png)\s*$', re.I),
|
|||||||
return path, open(path, 'rb').read()
|
return path, open(path, 'rb').read()
|
||||||
|
|
||||||
def extract_first_alphabetically(path):
|
def extract_first_alphabetically(path):
|
||||||
|
remove_path = False
|
||||||
if hasattr(path, 'read'):
|
if hasattr(path, 'read'):
|
||||||
data = path.read()
|
data = path.read()
|
||||||
with PersistentTemporaryFile('.rar') as f:
|
with PersistentTemporaryFile('.rar') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
path = f.name
|
path = f.name
|
||||||
|
remove_path = True
|
||||||
|
|
||||||
names_ = [x for x in names(path) if os.path.splitext(x)[1][1:].lower() in
|
names_ = [x for x in names(path) if os.path.splitext(x)[1][1:].lower() in
|
||||||
('png', 'jpg', 'jpeg', 'gif')]
|
('png', 'jpg', 'jpeg', 'gif')]
|
||||||
names_.sort()
|
names_.sort()
|
||||||
ans = extract_member(path, name=names_[0], match=None)
|
ans = extract_member(path, name=names_[0], match=None)
|
||||||
try:
|
try:
|
||||||
os.remove(path)
|
if remove_path:
|
||||||
|
os.remove(path)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return ans
|
return ans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user