Exemplo n.º 1
0
    async def streamable(self, ctx, media_url):
        """Create a streamable video from media/twitter/ig url."""
        starttimer = time()

        url = "https://api.streamable.com/import"
        params = {"url": media_url.strip("`")}
        auth = aiohttp.BasicAuth(STREAMABLE_USER, STREAMABLE_PASSWORD)

        async with aiohttp.ClientSession() as session:
            async with session.get(url, params=params, auth=auth) as response:
                if response.status != 200:
                    try:
                        data = await response.json()
                        messages = []
                        for category in data["messages"]:
                            for msg in data["messages"][category]:
                                messages.append(msg)
                        messages = " | ".join(messages)
                        errormsg = f"ERROR {response.status_code}: {messages}"
                    except (aiohttp.ContentTypeError, KeyError):
                        errormsg = await response.text()

                    logger.error(errormsg)
                    return await ctx.send(f"```{errormsg.split(';')[0]}```")

                data = await response.json()
                link = "https://streamable.com/" + data.get("shortcode")
                message = await ctx.send(f"Processing Video {emojis.LOADING}")

            i = 1
            await asyncio.sleep(5)
            while True:
                async with session.get(link) as response:
                    soup = BeautifulSoup(await response.text(), "html.parser")
                    meta = soup.find("meta", {"property": "og:url"})

                    if meta:
                        timestring = util.stringfromtime(
                            time() - starttimer, 2)
                        await message.edit(
                            content=
                            f"Streamable created in **{timestring}**\n{meta.get('content')}"
                        )
                        break

                    status = soup.find("h1").text
                    if status != "Processing Video":
                        await message.edit(content=f":warning: {status}")
                        break

                    await asyncio.sleep(i)
                    i += 1
Exemplo n.º 2
0
    async def system(self, ctx):
        """Get status of the system."""
        process_uptime = time.time() - self.bot.start_time
        system_uptime = time.time() - psutil.boot_time()
        mem = psutil.virtual_memory()
        pid = os.getpid()
        memory_use = psutil.Process(pid).memory_info()[0]

        data = [
            ("Version", self.bot.version),
            ("Process uptime", util.stringfromtime(process_uptime, 2)),
            ("Process memory", f"{memory_use / math.pow(1024, 2):.2f}MB"),
            ("System uptime", util.stringfromtime(system_uptime, 2)),
            ("CPU Usage", f"{psutil.cpu_percent()}%"),
            ("RAM Usage", f"{mem.percent}%"),
        ]

        content = discord.Embed(
            title=":computer: System status",
            colour=int("5dadec", 16),
            description="\n".join(f"**{x[0]}** {x[1]}" for x in data),
        )
        await ctx.send(embed=content)