Return True if *data* starts with a recognised container-format magic header. Raw PCM byte streams have no header, so they will return False and the expensive pydub/ffmpeg validation round-trip can be skipped entirely.
(data: bytes)
| 176 | |
| 177 | |
| 178 | def _is_audio_container(data: bytes) -> bool: |
| 179 | """Return True if *data* starts with a recognised container-format magic header. |
| 180 | |
| 181 | Raw PCM byte streams have no header, so they will return False and the |
| 182 | expensive pydub/ffmpeg validation round-trip can be skipped entirely. |
| 183 | """ |
| 184 | if len(data) < 4: |
| 185 | return False |
| 186 | # WAV – RIFF....WAVE |
| 187 | if data[:4] == b"RIFF": |
| 188 | return True |
| 189 | # MP3 – ID3 tag or sync word (0xFF 0xEx) |
| 190 | if data[:3] == b"ID3" or (data[0] == 0xFF and (data[1] & 0xE0) == 0xE0): |
| 191 | return True |
| 192 | # OGG |
| 193 | if data[:4] == b"OggS": |
| 194 | return True |
| 195 | # FLAC |
| 196 | if data[:4] == b"fLaC": |
| 197 | return True |
| 198 | # MP4 / M4A / AAC – 'ftyp' box at offset 4 |
| 199 | if len(data) >= 8 and data[4:8] == b"ftyp": |
| 200 | return True |
| 201 | # WebM / MKV |
| 202 | if data[:4] == b"\x1a\x45\xdf\xa3": |
| 203 | return True |
| 204 | return False |
| 205 | |
| 206 | |
| 207 | def load_bytes(input): |
no outgoing calls
no test coverage detected
searching dependent graphs…