mirror of
https://git.squeakyrat.moe/faggot-chan/
synced 2026-11-04 18:35:45 +01:00
steal media now only steals gifs
This commit is contained in:
1 parent
7c1fbbcf5b
commit
7958daa50d
1 file changed
+5
-4
@@ -287,17 +287,18 @@ async def steal_media(url: str, name: str):
|
|||||||
f.write(f"[{now_str()}] saved media: {name}\n")
|
f.write(f"[{now_str()}] saved media: {name}\n")
|
||||||
|
|
||||||
async def steal_attachments(message):
|
async def steal_attachments(message):
|
||||||
#steal images and gifs and stuff (always do this regardless of what else fires)
|
#steal gifs only (always do this regardless of what else fires)
|
||||||
media = [
|
media = [
|
||||||
(a.url, f"{a.id}_{Path(a.filename).name}") for a in message.attachments
|
(a.url, f"{a.id}_{Path(a.filename).name}") for a in message.attachments
|
||||||
if a.content_type and a.content_type.startswith(("image/", "video/")) and a.size <= MEDIA_SAVE_MAX_BYTES
|
if a.content_type and a.content_type.split(";")[0].strip().lower() == "image/gif" and a.size <= MEDIA_SAVE_MAX_BYTES
|
||||||
]
|
]
|
||||||
|
|
||||||
for embed in message.embeds:
|
for embed in message.embeds:
|
||||||
|
#tenor/klipy links come as gifv embeds with an mp4 in embed.video direct gif links are plain image embeds
|
||||||
for part in (embed.image, embed.video):
|
for part in (embed.image, embed.video):
|
||||||
if part and part.url:
|
if part and part.url:
|
||||||
ext = Path(urlparse(part.url).path).suffix # no extension, no preview on discord, not worth keeping
|
ext = Path(urlparse(part.url).path).suffix # no extension no preview on discord not worth keeping
|
||||||
if ext:
|
if ext and (embed.type == "gifv" or ext.lower() == ".gif"):
|
||||||
media.append((part.url, hashlib.sha1(part.url.encode()).hexdigest()[:16] + ext))
|
media.append((part.url, hashlib.sha1(part.url.encode()).hexdigest()[:16] + ext))
|
||||||
|
|
||||||
for url, name in media:
|
for url, name in media:
|
||||||
|
|||||||
Reference in new issue
Block a user