mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-18 02:56:39 +00:00
Fix hachoir don't close files by itself (#875)
This commit is contained in:
parent
baedd10110
commit
dfcf414111
@ -414,32 +414,30 @@ class UploadMethods(MessageParseMethods, UserMethods):
|
|||||||
os.path.basename(file))
|
os.path.basename(file))
|
||||||
}
|
}
|
||||||
if utils.is_audio(file) and hachoir:
|
if utils.is_audio(file) and hachoir:
|
||||||
m = hachoir.metadata.extractMetadata(
|
with hachoir.parser.createParser(file) as parser:
|
||||||
hachoir.parser.createParser(file)
|
m = hachoir.metadata.extractMetadata(parser)
|
||||||
)
|
attr_dict[types.DocumentAttributeAudio] = \
|
||||||
attr_dict[types.DocumentAttributeAudio] = \
|
types.DocumentAttributeAudio(
|
||||||
types.DocumentAttributeAudio(
|
voice=voice_note,
|
||||||
voice=voice_note,
|
title=m.get('title') if m.has(
|
||||||
title=m.get('title') if m.has(
|
'title') else None,
|
||||||
'title') else None,
|
performer=m.get('author') if m.has(
|
||||||
performer=m.get('author') if m.has(
|
'author') else None,
|
||||||
'author') else None,
|
duration=int(m.get('duration').seconds
|
||||||
duration=int(m.get('duration').seconds
|
if m.has('duration') else 0)
|
||||||
if m.has('duration') else 0)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
if not force_document and utils.is_video(file):
|
if not force_document and utils.is_video(file):
|
||||||
if hachoir:
|
if hachoir:
|
||||||
m = hachoir.metadata.extractMetadata(
|
with hachoir.parser.createParser(file) as parser:
|
||||||
hachoir.parser.createParser(file)
|
m = hachoir.metadata.extractMetadata(parser)
|
||||||
)
|
doc = types.DocumentAttributeVideo(
|
||||||
doc = types.DocumentAttributeVideo(
|
round_message=video_note,
|
||||||
round_message=video_note,
|
w=m.get('width') if m.has('width') else 0,
|
||||||
w=m.get('width') if m.has('width') else 0,
|
h=m.get('height') if m.has('height') else 0,
|
||||||
h=m.get('height') if m.has('height') else 0,
|
duration=int(m.get('duration').seconds
|
||||||
duration=int(m.get('duration').seconds
|
if m.has('duration') else 0)
|
||||||
if m.has('duration') else 0)
|
)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
doc = types.DocumentAttributeVideo(
|
doc = types.DocumentAttributeVideo(
|
||||||
0, 1, 1, round_message=video_note)
|
0, 1, 1, round_message=video_note)
|
||||||
|
Loading…
Reference in New Issue
Block a user