Compare commits

..

No commits in common. "2b399d4bd577caf09db36de62eccc3bb683d6c1d" and "d4f2f25ac46d5e0afa0709157955883aab02c2ef" have entirely different histories.

1 changed files with 2 additions and 29 deletions

View File

@ -207,12 +207,7 @@ async def main():
j = j[0]
k = k[0]
attributes = []
try:
mimetype = (await _get_file_mimetype(k)) if k else ''
except TypeError:
# (for now) telethon doesn't easily support attributes for grouped media
mimetype = ''
thumb = None
mimetype = await _get_file_mimetype(k)
if mimetype.startswith('video/'):
try:
data = await _get_video_data(k)
@ -228,14 +223,7 @@ async def main():
logging.exception('Exception when getting video data')
else:
attributes.append(DocumentAttributeVideo(duration, w, h, supports_streaming=mimetype == 'video/mp4' or None))
dn, _ = os.path.split(k)
try:
nthumb = os.path.join(dn, f'{time.time()}.jpg')
if await _make_thumbnail(nthumb, k):
thumb = nthumb
except Exception:
logging.exception('Exception while making thumbnail')
await client.send_message(chat, j, file=k, link_preview=False, attributes=attributes, thumb=thumb)
await client.send_message(chat, j, file=k, link_preview=False, attributes=attributes)
async def _get_video_data(filename):
proc = await asyncio.create_subprocess_exec('ffprobe', '-show_format', '-show_streams', '-print_format', 'json', filename, stdout=asyncio.subprocess.PIPE)
@ -250,21 +238,6 @@ async def main():
data['format']['duration'] = ndata['format']['duration']
return data
async def _make_thumbnail(filename, video):
data = await _get_video_data(video)
if not data.get('format'):
return False
if data['format'].get('duration') is None:
return False
for i in (0, 5, 10, 15):
if i and data['format']['duration'] > i:
continue
proc = await asyncio.create_subprocess_exec('ffmpeg', '-an', '-sn', '-ss', str(i), '-i', video, '-frames:v', '1', filename)
await proc.communicate()
if not proc.returncode:
return True
return False
async def _download_file(filename, url):
print(url)
async with session.get(url) as resp: