python-magic is shit so its replaced with filetype due to magic requires its own binary in order to work

This commit is contained in:
2026-04-24 21:43:29 +03:00
parent 18bb817239
commit 3112e6d4bf

View File

@@ -1,5 +1,5 @@
# meta developer: @limokanews # meta developer: @limokanews
# requires: whoosh cryptography python-magic # requires: whoosh cryptography filetype
from collections import Counter, defaultdict from collections import Counter, defaultdict
@@ -24,7 +24,7 @@ from telethon.errors.rpcerrorlist import WebpageMediaEmptyError
from telethon import TelegramClient from telethon import TelegramClient
from telethon.errors.rpcerrorlist import YouBlockedUserError from telethon.errors.rpcerrorlist import YouBlockedUserError
from telethon import functions from telethon import functions
import magic import filetype
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
@@ -859,7 +859,7 @@ class Limoka(loader.Module):
ct = response.headers.get("Content-Type", "").lower() ct = response.headers.get("Content-Type", "").lower()
if not ct: # Some servers don't respond to HEAD requests with Content-Type, so instead we will try guess mime from content if not ct: # Some servers don't respond to HEAD requests with Content-Type, so instead we will try guess mime from content
data = open(response.data, "rb").read(2048) data = open(response.data, "rb").read(2048)
mime = magic.from_buffer(data, mime=True) mime = filetype.guess_mime(data, mime=True)
if not ct.startswith("image/") or not mime.startswith("image/"): if not ct.startswith("image/") or not mime.startswith("image/"):
self._invalid_banners.add(url) self._invalid_banners.add(url)
return None return None