from typing import Dict
from typing import List
from typing import Tuple
import re


def _extract_attributes(line: str) -> Dict[str, str]:
  """Extracts attributes from an m3u8 #EXT-X tag to a python dictionary."""
  
  attributes: Dict[str, str] = {}
  line = line.strip().split(':', 1)[1]
  # For a tighter search, append ',' and search for it in the regex.
  line += ','
  # Search for all KEY=VALUE,
  matches: List[Tuple[str, str]] = re.findall(
      r'([-A-Z]+)=("[^"]*"|[^",]*),', line)
  for key, value in matches:
    attributes[key] = value
  return attributes