api / app /utils.py
Hana Celeste
Rename app/youtube_dns.py to app/utils.py
c7ef355 verified
raw
history blame contribute delete
329 Bytes
import re
def extract_video_id(url: str) -> str:
patterns = [
r"v=([a-zA-Z0-9_-]{11})",
r"youtu\.be/([a-zA-Z0-9_-]{11})",
r"shorts/([a-zA-Z0-9_-]{11})"
]
for p in patterns:
m = re.search(p, url)
if m:
return m.group(1)
raise ValueError("Invalid YouTube URL")