import re


def get_url_mode(url):
    """Extracts the mode from an URL or QUERY_STRING."""

    # Maybe it contains a MIME type: application/java-archive,
    # application/vnd.ms-powerpoint, audio/3gpp2, application/epub+zip

    # First argument, if QUERY_STRING, not a complete URL.
    mtch_url = re.match(r"mode=([^\&]*).*", url)
    if mtch_url:
        return mtch_url.group(1)
    # After the arguments delimiter, or in a URL.
    mtch_url = re.match(r".*[\?\&]mode=([^\&]*).*", url)
    if mtch_url:
        return mtch_url.group(1)
    return ""