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,17 +270,20 @@ def extract_member(path, match=re.compile(r'\.(jpg|jpeg|gif|png)\s*$', re.I),
|
||||
return path, open(path, 'rb').read()
|
||||
|
||||
def extract_first_alphabetically(path):
|
||||
remove_path = False
|
||||
if hasattr(path, 'read'):
|
||||
data = path.read()
|
||||
with PersistentTemporaryFile('.rar') as f:
|
||||
f.write(data)
|
||||
path = f.name
|
||||
remove_path = True
|
||||
|
||||
names_ = [x for x in names(path) if os.path.splitext(x)[1][1:].lower() in
|
||||
('png', 'jpg', 'jpeg', 'gif')]
|
||||
names_.sort()
|
||||
ans = extract_member(path, name=names_[0], match=None)
|
||||
try:
|
||||
if remove_path:
|
||||
os.remove(path)
|
||||
except:
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user