add finders

This commit is contained in:
smolkik-code
2025-12-26 23:26:13 +07:00
parent f49db9adf6
commit d77e00f029
32 changed files with 681 additions and 330 deletions

32
bot/utils.py Normal file
View File

@@ -0,0 +1,32 @@
def is_instagram_story_url(url: str) -> bool:
return "instagram.com/stories" in url
VIDEO_SUFFIXES = ('.mp4', '.mov', '.mkv')
IMAGE_SUFFIXES = ('.jpg', '.jpeg', '.png', '.webp')
def extract_instagram_username(url: str) -> str | None:
# Поддержка:
# https://www.instagram.com/stories/USERNAME/...
# https://www.instagram.com/USERNAME/
try:
base = url.split("?")[0].strip("/")
parts = base.split("/")
if "instagram.com" not in url:
return None
if "stories" in parts:
i = parts.index("stories")
if i + 1 < len(parts):
return parts[i + 1]
# профиль
host_idx = 0
for i, p in enumerate(parts):
if "instagram.com" in p:
host_idx = i
break
if host_idx + 1 < len(parts):
candidate = parts[host_idx + 1]
if candidate and candidate not in ("stories", "reel", "p", "tv"):
return candidate
except Exception:
return None
return None