mirror of
https://github.com/phin05/discord-rich-presence-plex
synced 2024-11-22 01:23:02 +00:00
18 lines
614 B
Python
18 lines
614 B
Python
from .config import config
|
|
from typing import Optional
|
|
from utils.logging import logger
|
|
import models.imgur
|
|
import requests
|
|
|
|
def uploadToImgur(url: str) -> Optional[str]:
|
|
try:
|
|
data: models.imgur.UploadResponse = requests.post(
|
|
"https://api.imgur.com/3/image",
|
|
headers = { "Authorization": f"Client-ID {config['display']['posters']['imgurClientID']}" },
|
|
files = { "image": requests.get(url).content }
|
|
).json()
|
|
if not data["success"]:
|
|
raise Exception(data["data"]["error"])
|
|
return data["data"]["link"]
|
|
except:
|
|
logger.exception("An unexpected error occured while uploading an image to Imgur")
|