import re


def parse_time(time: str) -> int:
    """Converts a YouTube timestamp into seconds.

    Args:
        time: Timestamp from YouTube API.

    Returns:
        Time in seconds.

    """
    duration = 0
    for match in re.finditer("(\\d+)(H|M|S)", time):
        number, interval = match.group(1, 2)
        if interval == "H":
            duration += int(number) * 60 * 60
        elif interval == "M":
            duration += int(number) * 60
        elif interval == "S":
            duration += int(number)
        else:
            raise TypeError("Incorrect YouTube timestamp format")
    return duration