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
|
import asyncio
|
||||||
|
from collections.abc import Iterable
|
||||||
import logging
|
import logging
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
|
@ -178,15 +179,14 @@ class AutoResponder(commands.Cog):
|
||||||
)
|
)
|
||||||
return discord.File(tmp_path), tmp_path
|
return discord.File(tmp_path), tmp_path
|
||||||
|
|
||||||
@commands.Cog.listener("on_message")
|
async def transcode_hevc_to_h264(
|
||||||
async def auto_responder(self, message: discord.Message):
|
self,
|
||||||
if message.author == self.bot.user:
|
message: discord.Message,
|
||||||
return
|
*domains: str,
|
||||||
|
additional: Iterable[str] = None
|
||||||
# Check for HEVC truth social links and convert into h264
|
) -> discord.File | None:
|
||||||
if message.channel.name == "spam" and message.author != self.bot.user:
|
additional = additional or []
|
||||||
# links = self.extract_links(message.content, "static-assets-1.truthsocial.com")
|
links = self.extract_links(message.content, *domains) + list(additional)
|
||||||
links = self.extract_links(message.content)
|
|
||||||
if links:
|
if links:
|
||||||
for link in links:
|
for link in links:
|
||||||
hevc_containers = {
|
hevc_containers = {
|
||||||
|
@ -246,6 +246,28 @@ class AutoResponder(commands.Cog):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.error("Failed to transcode %r: %r", link, 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):
|
def setup(bot):
|
||||||
bot.add_cog(AutoResponder(bot))
|
bot.add_cog(AutoResponder(bot))
|
||||||
|
|
Loading…
Reference in a new issue