<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _magic(header, footer, mime, ext=None):
 """ Discover what type of file it is based on the incoming string """

    if not header:
        raise ValueError("Input was empty")
    info = _identify_all(header, footer, ext)[0]
    if mime:
        return info.mime_type
    return info.extension if not \
        isinstance(info.extension, list) else info[0].extension