hikari_uploader/hikari/hikari.py
2022-02-27 05:35:40 +01:00

49 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
import hashlib
from pathlib import Path
import orjson
import pyperclip
import requests
import typer
HIKARI_URL = "https://hikari.butaishoujo.moe/upload"
def upload(file: Path,
obstruct: bool = typer.Option(
False, "--obstruct", "-o",
help="Obstruct filename (by hashing)"
),
filename: str = typer.Option(
None, "--name", "-n",
help="Rename the uploaded file."
),
copy: bool = typer.Option(
False, "--copy", "-c",
help="Copy file URL to clipboard."
)):
if copy:
pyperclip.copy("")
if obstruct:
filename = hashlib.sha256(file.name.encode()).hexdigest()
elif filename is None:
filename = file.name
with file.open('br') as f:
files = {'file': (filename, f)}
with requests.post(HIKARI_URL, files=files, stream=True) as req:
resp = req.raw.read()
data = orjson.loads(resp)
if copy:
pyperclip.copy(data['url'])
else:
print(resp.decode())
def main():
typer.run(upload)