from typing import List


def extract_raw_metadata_map(raw_metadata: List[str]):
    """Given output of ebook-meta program, extract metadata map
    Args:
        raw_metadata (List[str]): String representation of the lines produced
            by Calibre (also produced by a call to ``fetch-ebook-metadata``)
    Returns:
        Dict mapping between metadata keys and values as directly output from
            the ebook-meta call
    """
    metadata_lines = []
    for line in raw_metadata:
        # VERY brittle, but it looks like this is the only way to read the
        # output in case there is a newline in the value
        # (as seems to happen often in the description)
        if len(line.strip()) > 20 and line[20] == ':':
            key, _, value = line.partition(':')
            metadata_lines.append((key.strip(), value))
        elif len(metadata_lines) > 0:
            # append to the end of the previous line
            (key, value) = metadata_lines[-1]
            metadata_lines[-1] = (key, value + ' ' + line)

    return {key.strip(): value.strip() for key, value in metadata_lines}