Add on-demand HEVC-to-H264
This commit is contained in:
parent
531c0e9d4e
commit
5d9a70e25c
1 changed files with 81 additions and 59 deletions
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue