From 680d29c7d24906e320e3c536f66e41f743c1d017 Mon Sep 17 00:00:00 2001 From: Juan Date: Sun, 16 Apr 2023 01:22:11 -0400 Subject: [PATCH] basic get gif info from 7tv functions --- 7tv.py | 41 +++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 7tv.py diff --git a/7tv.py b/7tv.py new file mode 100644 index 0000000..739d37b --- /dev/null +++ b/7tv.py @@ -0,0 +1,41 @@ +import requests +import imageio +import io +imageio.plugins.freeimage.download() + + +def get_webp_url(url): + emote_id = url[23:] + api_call = ('https://7tv.io/v3/emotes/' + emote_id) + response = requests.get(api_call).json() + + + image_url = response['host']['url'] + for file in response['host']['files']: + if file['width'] == 128 and file['name'][3:] == 'webp': + return ('https:' + image_url + '/' + file['name']) + + return ('No 128x128 file detected') + + +def webp_to_gif(url): + # Download the webp file + response = requests.get(url) + + print(url) + + # Open the webp file using imageio + im = imageio.imread(response.content, format="WEBP") + + # Create a bytes buffer to hold the GIF data + gif_buffer = io.BytesIO() + + # Write the image as a GIF file to the bytes buffer + imageio.mimwrite(gif_buffer, [im], format='GIF', loop=1, duration=1) + + # Return the GIF data as a bytes object + return gif_buffer.getvalue() + + + + diff --git a/requirements.txt b/requirements.txt index cfb5b6d..bf61c5a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -Pillow +imageio discord.py \ No newline at end of file