Skip to content

Instantly share code, notes, and snippets.

@soaska
Last active January 14, 2024 19:14
Show Gist options
  • Save soaska/abf85cef2b43bc3715744d5dd1dcd007 to your computer and use it in GitHub Desktop.
Save soaska/abf85cef2b43bc3715744d5dd1dcd007 to your computer and use it in GitHub Desktop.
tdtg
# █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
# █▀█ █ █ █ █▀█ █▀▄ █
# © Copyright 2022
# https://t.me/hikariatama
#
# 🔒 Licensed under the GNU AGPLv3
# 🌐 https://www.gnu.org/licenses/agpl-3.0.html
# scope: hikka_min 1.2.10
# meta pic: https://img.icons8.com/plasticine/400/000000/youtube-play--v2.png
# meta banner: https://mods.hikariatama.ru/badges/youtube.jpg
# meta developer: @hikarimods
# scope: hikka_only
# scope: ffmpeg
# requires: requests pillow webuiapi
import os
import subprocess
import webuiapi
import json
import requests
import io
import base64
from PIL import Image
from .. import loader, utils
url = "http://192.168.2.81:8080"
login = {
"username": "boudysuperfast",
"password": "ilovecars69"
}
api = webuiapi.WebUIApi(host='192.168.2.81', port='8080')
api.set_auth('boudysuperfast', 'ilovecars69')
payload = {
"prompt" : "a cat",
"negative_prompt" : " [deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry, (worst quality, mutated hands and fingers, bad anatomy, wrong anatomy, mutation:1.2), watermark, signature",
"width" : 512,
"height" : 512,
"batch_size" : 1,
"styles" : [""],
"model" : "cetusMix_Whalefall2",
"sampler" : "Euler a",
"steps" : 15,
"restore_faces" : True,
"cfg" : 7.0
}
def image_to_byte_array(image: Image) -> bytes:
# BytesIO is a file-like buffer stored in memory
imgByteArr = io.BytesIO()
# image.save expects a file-like as a argument
image.save(imgByteArr, format=image.format)
# Turn the BytesIO object back into a bytes object
imgByteArr = imgByteArr.getvalue()
return imgByteArr
@loader.tds
class YouTubeMod(loader.Module):
"""Download YouTube video"""
strings = {
"name": "YouTube",
"args": "🎞 <b>You need to specify link</b>",
"downloading": "🎞 <b>Downloading...</b>",
"not_found": "🎞 <b>Video not found...</b>",
}
strings_ru = {
"args": "🎞 <b>Укажи ссылку на видео</b>",
"downloading": "🎞 <b>Скачиваю...</b>",
"not_found": "🎞 <b>Видео не найден...</b>",
"_cmd_doc_yt": "[mp3] <ссылка> - Скачать видео YouTube",
"_cls_doc": "Скачать YouTube видео",
}
@loader.unrestricted
async def ytcmd(self, message: Message):
"""[mp3] <link> - Download video from youtube"""
args = utils.get_args_raw(message)
message = await utils.answer(message, self.strings("downloading"))
ext = False
if len(args.split()) > 1:
ext, args = args.split(maxsplit=1)
if not args:
return await utils.answer(message, self.strings("args"))
path = "/tmp"
try:
cur_mod = api.util_get_current_model()
if not payload["model"] == "" and not payload["model"] in cur_mod:
api.util_set_model(payload["model"])
result = api.txt2img(
prompt=payload["prompt"],
negative_prompt=payload["negative_prompt"],
restore_faces=payload["restore_faces"],
styles=payload["styles"],
cfg_scale=payload["cfg"],
width=payload["width"],
height=payload["height"],
batch_size=payload["batch_size"],
sampler_index=payload["sampler"],
steps=payload["steps"]
)
images = []
for im in result.images:
images.append(image_to_byte_array(im))
except:
await utils.answer(message, self.strings("not_found"))
await self._client.send_file(message.peer_id, images[0])
os.remove(path)
if message.out:
await message.delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment