Add on-demand HEVC-to-H264

This commit is contained in:
Nexus 2024-04-19 16:16:43 +01:00 committed by GitHub
parent 531c0e9d4e
commit 5d9a70e25c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,5 @@
import asyncio
from collections.abc import Iterable
import logging
import pathlib
import re
@ -178,15 +179,14 @@ class AutoResponder(commands.Cog):
)
return discord.File(tmp_path), tmp_path
@commands.Cog.listener("on_message")
async def auto_responder(self, message: discord.Message):
if message.author == self.bot.user:
return
# Check for HEVC truth social links and convert into h264
if message.channel.name == "spam" and message.author != self.bot.user:
# links = self.extract_links(message.content, "static-assets-1.truthsocial.com")
links = self.extract_links(message.content)
async def transcode_hevc_to_h264(
self,
message: discord.Message,
*domains: str,
additional: Iterable[str] = None
) -> discord.File | None:
additional = additional or []
links = self.extract_links(message.content, *domains) + list(additional)
if links:
for link in links:
hevc_containers = {
@ -246,6 +246,28 @@ class AutoResponder(commands.Cog):
except Exception as e:
self.log.error("Failed to transcode %r: %r", link, e)
@commands.Cog.listener("on_message")
async def auto_responder(self, message: discord.Message):
if message.author == self.bot.user:
return
# Check for HEVC truth social links and convert into h264
if message.channel.name == "spam" and message.author != self.bot.user:
await self.transcode_hevc_to_h264(message)
@commands.Cog.listener("on_reaction_add")
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User):
if user == self.bot.user:
return
if reaction.message.author != self.bot.user:
if str(reaction.emoji) == "\N{VIDEOCASSETTE}":
extra = []
if reaction.message.attachments:
extra = [attachment.url for attachment in reaction.message.attachments]
await self.transcode_hevc_to_h264(reaction.message, additional=extra)
def setup(bot):
bot.add_cog(AutoResponder(bot))