Upload to pastebin where possible
This commit is contained in:
parent
751287479a
commit
024f32a1e9
1 changed files with 26 additions and 0 deletions
|
@ -8,6 +8,8 @@ import re
|
|||
import tempfile
|
||||
from urllib.parse import urlparse
|
||||
import logging
|
||||
|
||||
import httpx
|
||||
from discord.ext import commands
|
||||
|
||||
from .ffmeta import FFMeta
|
||||
|
@ -171,6 +173,30 @@ class AutoResponder(commands.Cog):
|
|||
_p,
|
||||
_p.stat().st_size / 1024 / 1024
|
||||
)
|
||||
if _p.stat().st_size <= 490 * 1024 * 1024:
|
||||
file.fp.seek(0)
|
||||
self.log.info("Trying to upload file to pastebin.")
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(
|
||||
"https://paste.nexy7574.co.uk/upload",
|
||||
data={
|
||||
"expiration": "3days",
|
||||
"burn_after": "0",
|
||||
"syntax_highlight": "none",
|
||||
"privacy": "unlisted",
|
||||
"content": ""
|
||||
},
|
||||
files={
|
||||
"file": (_p.name, file.fp, "video/mp4")
|
||||
},
|
||||
follow_redirects=False
|
||||
)
|
||||
if response.status_code == 302:
|
||||
loc = response.headers["Location"]
|
||||
loc = loc.replace("/upload/", "/file/", 1)
|
||||
await message.reply(
|
||||
"https://embeds.video/" + loc
|
||||
)
|
||||
_p.unlink()
|
||||
except Exception as e:
|
||||
self.log.error("Failed to transcode %r: %r", link, e)
|
||||
|
|
Loading…
Reference in a new issue