add finders
This commit is contained in:
32
bot/utils.py
Normal file
32
bot/utils.py
Normal 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
|
||||
Reference in New Issue
Block a user