Reduce the number of files that have an attempted transcode
This commit is contained in:
parent
ffd0b403d1
commit
e70056f2ff
1 changed files with 24 additions and 15 deletions
|
@ -107,21 +107,30 @@ class AutoResponder(commands.Cog):
|
|||
links = self.extract_links(message.content, "static-assets-1.truthsocial.com")
|
||||
if links:
|
||||
for link in links:
|
||||
self.log.info("Found link to transcode: %r", link)
|
||||
try:
|
||||
file, _p = await self._transcode_hevc_to_h264(link)
|
||||
if file:
|
||||
if _p.stat().st_size <= 24.5 * 1024 * 1024:
|
||||
await message.reply(file=file)
|
||||
else:
|
||||
self.log.warning(
|
||||
"Transcoded file too large: %r (%.2f)MB",
|
||||
_p,
|
||||
_p.stat().st_size / 1024 / 1024
|
||||
)
|
||||
_p.unlink()
|
||||
except Exception as e:
|
||||
self.log.error("Failed to transcode %r: %r", link, e)
|
||||
if link.lower().endswith(
|
||||
(".mp4", ".mov", ".qtff", ".mkv", ".asf", ".avi", ".mxf", ".ps", ".ts", ".3gp", ".3g2")
|
||||
):
|
||||
# All containers allowed to contain HEVC
|
||||
# per https://en.wikipedia.org/wiki/Comparison_of_video_container_formats
|
||||
self.log.info("Found link to transcode: %r", link)
|
||||
try:
|
||||
async with message.channel.typing():
|
||||
_r = await self._transcode_hevc_to_h264(link)
|
||||
if not _r:
|
||||
continue
|
||||
file, _p = _r
|
||||
if file:
|
||||
if _p.stat().st_size <= 24.5 * 1024 * 1024:
|
||||
await message.reply(file=file)
|
||||
else:
|
||||
self.log.warning(
|
||||
"Transcoded file too large: %r (%.2f)MB",
|
||||
_p,
|
||||
_p.stat().st_size / 1024 / 1024
|
||||
)
|
||||
_p.unlink()
|
||||
except Exception as e:
|
||||
self.log.error("Failed to transcode %r: %r", link, e)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
|
Loading…
Reference in a new issue