From 9e164ff0f510156dc2dda69946764d0dfe47e653 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sat, 25 May 2024 19:09:44 +0200 Subject: [PATCH] add providers --- bot.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/bot.py b/bot.py index 321eec6..d665f3c 100644 --- a/bot.py +++ b/bot.py @@ -2,8 +2,10 @@ import os from urllib.parse import urlparse, parse_qs +import aiohttp import discord + DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") DISCORD_CHANNEL = int(os.getenv("DISCORD_CHANNEL")) DISCORD_GUILD = int(os.getenv("DISCORD_GUILD")) @@ -45,6 +47,40 @@ class CustomClient(discord.Client): content=f"https://stream.purser.it/{video_id}?provider=youtube&direct=true" ) + elif "seafile" in url.hostname: + stripped = url.path.strip("/") + async with aiohttp.ClientSession( + timeout=aiohttp.ClientTimeout(total=5) + ) as session: + resp = await session.head( + "https://stream.purser.it/{stripped}/?provider=seafile&raw=true" + ) + raw = ( + ctype := resp.headers.get("content-type") + ) and "image" in ctype + + await message.reply( + content=f"https://stream.purser.it/{stripped}/?provider=seafile&raw={raw}" + ) + + elif "twitch" in url.hostname: + stripped = url.path.strip("/") + await message.reply( + content=f"https://stream.purser.it/{stripped}?provider=twitch" + ) + + elif "twitter" in url.hostname: + stripped = url.path.strip("/") + await message.reply( + content=f"https://stream.purser.it/{stripped}?provider=twitter" + ) + + elif "x.com" in url.hostname: + stripped = url.path.strip("/") + await message.reply( + content=f"https://stream.purser.it/{stripped}?provider=twitter" + ) + intents = discord.Intents.default() intents.message_content = True