Repository: yt-dlp/yt-dlp
File: yt_dlp/utils.py (Python)

Code before:
        'x-ms-wmv': 'wmv',
        'x-msvideo': 'avi',

        # application (streaming playlists)
        'dash+xml': 'mpd',
        'f4m+xml': 'f4m',
        'hds+xml': 'f4m',
        'vnd.apple.mpegurl': 'm3u8',
        'vnd.ms-sstr+xml': 'ism',
        'x-mpegurl': 'm3u8',

        # audio
        ('audio', 'mp4'): 'm4a',
        # Per RFC 3003, audio/mpeg can be .mp1, .mp2 or .mp3.
        # Using .mp3 as it's the most popular one
        ('audio', 'mpeg'): 'mp3',
        ('audio', 'webm'): 'weba',
        ('audio', 'x-matroska'): 'mka',
        ('audio', 'x-mpegurl'): 'm3u',
        'midi': 'mid',
        'ogg': 'ogg',
        'wav': 'wav',
        'wave': 'wav',
        'x-aac': 'aac',
        'x-flac': 'flac',
        'x-m4a': 'm4a',
        'x-realaudio': 'ra',
        'x-wav': 'wav',

        # image
        'avif': 'avif',
        'bmp': 'bmp',
        'gif': 'gif',
        'jpeg': 'jpg',
        'png': 'png',
        'svg+xml': 'svg',
        'tiff': 'tif',
        'vnd.wap.wbmp': 'wbmp',
        'webp': 'webp',
        'x-icon': 'ico',
        'x-jng': 'jng',
        'x-ms-bmp': 'bmp',

        # caption
        'filmstrip+json': 'fs',
        'smptett+xml': 'tt',
        'ttaf+xml': 'dfxp',
        'ttml+xml': 'ttml',
        'x-ms-sami': 'sami',
    }


Review comment (suggestion):
Suggestion
```diff
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index eee257f16..b01f22370 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -3467,13 +3467,13 @@ def mimetype2ext(mt, default=NO_DEFAULT):
         'x-mpegurl': 'm3u8',

         # audio
-        ('audio', 'mp4'): 'm4a',
+        'audio/mp4': 'm4a',
         # Per RFC 3003, audio/mpeg can be .mp1, .mp2 or .mp3.
         # Using .mp3 as it's the most popular one
-        ('audio', 'mpeg'): 'mp3',
-        ('audio', 'webm'): 'weba',
-        ('audio', 'x-matroska'): 'mka',
-        ('audio', 'x-mpegurl'): 'm3u',
+        'audio/mpeg': 'mp3',
+        'audio/webm': 'weba',
+        'audio/x-matroska': 'mka',
+        'audio/x-mpegurl': 'm3u',
         'midi': 'mid',
         'ogg': 'ogg',
         'wav': 'wav',
@@ -3504,35 +3504,23 @@ def mimetype2ext(mt, default=NO_DEFAULT):
         'ttaf+xml': 'dfxp',
         'ttml+xml': 'ttml',
         'x-ms-sami': 'sami',
-    }
-
-    mimetype = mt.partition(';')[0].strip().lower()
-    prefix, _, identifier = mimetype.rpartition('/')
-
-    if prefix:
-        value = prefix, identifier
-        ext = MAP.get(value)
-        if ext:
-            return ext
-
-    ext = MAP.get(identifier)
-    if ext:
-        return ext

-    SUFFIX_MAP = {
+        # misc
         'gzip': 'gz',
         'json': 'json',
         'xml': 'xml',
         'zip': 'zip',
     }
-    suffix = identifier.rpartition('+')[2]
-    ext = SUFFIX_MAP.get(suffix)
+
+    mimetype = mt.partition(';')[0].strip().lower()
+    _, _, subtype = mimetype.rpartition('/')
+
+    ext = traverse_obj(MAP, mimetype, subtype, subtype.rsplit('+')[-1])
     if ext:
         return ext
-
-    if default is not NO_DEFAULT:
+    elif default is not NO_DEFAULT:
         return default
-    return identifier.replace('+', '.')
+    return subtype.replace('+', '.')


 def ext2mimetype(ext_or_url):
```

Code after:
    except ValueError:
        return not assume_new


def ytdl_is_updateable():
    """ Returns if yt-dlp can be updated with -U """

    from .update import is_non_updateable

    return not is_non_updateable()


def args_to_str(args):
    # Get a short string representation for a subprocess command
    return ' '.join(compat_shlex_quote(a) for a in args)


def error_to_compat_str(err):
    return str(err)


def error_to_str(err):
    return f'{type(err).__name__}: {err}'


def mimetype2ext(mt, default=NO_DEFAULT):
    if not isinstance(mt, str):
        if default is not NO_DEFAULT:
            return default
        return None

    MAP = {
        # video
        '3gpp': '3gp',
        'mp2t': 'ts',
        'mp4': 'mp4',
        'mpeg': 'mpeg',
        'mpegurl': 'm3u8',
        'quicktime': 'mov',
        'webm': 'webm',
        'vp9': 'vp9',
        'x-flv': 'flv',
        'x-m4v': 'm4v',
        'x-matroska': 'mkv',
        'x-mng': 'mng',
        'x-mp4-fragmented': 'mp4',
        'x-ms-asf': 'asf',
        'x-ms-wmv': 'wmv',
        'x-msvideo': 'avi',

        # application (streaming playlists)