encode gif
This commit is contained in:
parent
7384497a02
commit
564134fc78
18
main.py
18
main.py
@ -54,14 +54,14 @@ async def send_post(post: E621Post, tag_list: List[str]):
|
|||||||
file.write((await client.get(post.file.url)).content)
|
file.write((await client.get(post.file.url)).content)
|
||||||
file.name = f'file.{post.file.ext}'
|
file.name = f'file.{post.file.ext}'
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
if post.file.ext == 'webm':
|
if post.file.ext in ('webm', 'gif'):
|
||||||
with TemporaryDirectory() as td:
|
with TemporaryDirectory() as td:
|
||||||
webm_path = Path(td) / 'video.webm'
|
src_path = Path(td) / f'video.{post.file.ext}'
|
||||||
mp4_path = Path(td) / 'video.mp4'
|
mp4_path = Path(td) / 'video.mp4'
|
||||||
with open(webm_path, 'wb') as webm:
|
with open(src_path, 'wb') as webm:
|
||||||
webm.write(file.read())
|
webm.write(file.read())
|
||||||
ffmpeg\
|
ffmpeg\
|
||||||
.input(str(webm_path))\
|
.input(str(src_path))\
|
||||||
.output(str(mp4_path), vcodec='libx264', crf='26')\
|
.output(str(mp4_path), vcodec='libx264', crf='26')\
|
||||||
.run()
|
.run()
|
||||||
s3 = boto3.client('s3', aws_access_key_id=os.environ['AWS_ACCESS_KEY'], aws_secret_access_key=os.environ['AWS_SECRET_KEY'])
|
s3 = boto3.client('s3', aws_access_key_id=os.environ['AWS_ACCESS_KEY'], aws_secret_access_key=os.environ['AWS_SECRET_KEY'])
|
||||||
@ -71,16 +71,8 @@ async def send_post(post: E621Post, tag_list: List[str]):
|
|||||||
await bot.send_message(int(os.environ['SEND_CHAT']),
|
await bot.send_message(int(os.environ['SEND_CHAT']),
|
||||||
f'https://{bucket}.s3.amazonaws.com/{upload_filename}\n\n' + caption,
|
f'https://{bucket}.s3.amazonaws.com/{upload_filename}\n\n' + caption,
|
||||||
parse_mode=ParseMode.HTML)
|
parse_mode=ParseMode.HTML)
|
||||||
webm_path.unlink()
|
src_path.unlink()
|
||||||
mp4_path.unlink()
|
mp4_path.unlink()
|
||||||
elif post.file.ext == 'gif':
|
|
||||||
await bot.send_animation(int(os.environ['SEND_CHAT']),
|
|
||||||
file,
|
|
||||||
width=post.file.width,
|
|
||||||
height=post.file.height,
|
|
||||||
thumb=post.preview.url,
|
|
||||||
caption=caption,
|
|
||||||
parse_mode=ParseMode.HTML)
|
|
||||||
elif post.file.ext in ('png', 'jpg'):
|
elif post.file.ext in ('png', 'jpg'):
|
||||||
if post.file.size > 10000000:
|
if post.file.size > 10000000:
|
||||||
logging.warning('compressing')
|
logging.warning('compressing')
|
||||||
|
Loading…
Reference in New Issue
Block a user