def get_video_id(url: str) -> Optional[str]:
        """
        Extract the YouTube video ID from a URL.
        
        Args:
            url: The URL of the YouTube video
            
        Returns:
            The video ID or None if not found
        """
        import re
        from urllib.parse import urlparse, parse_qs
        
        # Handle different YouTube URL formats
        parsed_url = urlparse(url)
        hostname = parsed_url.hostname
        
        if hostname == "youtu.be":
            return parsed_url.path[1:]
        
        if hostname in ("www.youtube.com", "youtube.com"):
            if parsed_url.path == "/watch":
                query_params = parse_qs(parsed_url.query)
                return query_params.get("v", [None])[0]
            if parsed_url.path.startswith("/embed/"):
                return parsed_url.path.split("/")[2]
            if parsed_url.path.startswith("/v/"):
                return parsed_url.path.split("/")[2]
        
        # Try to extract ID using regex as fallback
        youtube_regex = r"(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^\"&?\/\s]{11})"
        match = re.search(youtube_regex, url)
        if match:
            return match.group(1)
            
        return None

        Extract the YouTube video ID from a URL.
        
        Args:
            url: The URL of the YouTube video
            
        Returns:
            The video ID or None if not found
        
src/upsonic/tools.py