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")
|
links = self.extract_links(message.content, "static-assets-1.truthsocial.com")
|
||||||
if links:
|
if links:
|
||||||
for link in links:
|
for link in links:
|
||||||
self.log.info("Found link to transcode: %r", link)
|
if link.lower().endswith(
|
||||||
try:
|
(".mp4", ".mov", ".qtff", ".mkv", ".asf", ".avi", ".mxf", ".ps", ".ts", ".3gp", ".3g2")
|
||||||
file, _p = await self._transcode_hevc_to_h264(link)
|
):
|
||||||
if file:
|
# All containers allowed to contain HEVC
|
||||||
if _p.stat().st_size <= 24.5 * 1024 * 1024:
|
# per https://en.wikipedia.org/wiki/Comparison_of_video_container_formats
|
||||||
await message.reply(file=file)
|
self.log.info("Found link to transcode: %r", link)
|
||||||
else:
|
try:
|
||||||
self.log.warning(
|
async with message.channel.typing():
|
||||||
"Transcoded file too large: %r (%.2f)MB",
|
_r = await self._transcode_hevc_to_h264(link)
|
||||||
_p,
|
if not _r:
|
||||||
_p.stat().st_size / 1024 / 1024
|
continue
|
||||||
)
|
file, _p = _r
|
||||||
_p.unlink()
|
if file:
|
||||||
except Exception as e:
|
if _p.stat().st_size <= 24.5 * 1024 * 1024:
|
||||||
self.log.error("Failed to transcode %r: %r", link, e)
|
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):
|
def setup(bot):
|
||||||
|
|
Loading…
Reference in a new issue