def determine_format(data, extension=None):
	"""Determine the format of an audio file.

	Parameters:
		data (bytes-like object, str, os.PathLike, or file-like object):
			A bytes-like object, filepath, path-like object
			or file-like object of an audio file.
		extension (str): The file extension of the file.
			Used as a tie-breaker for formats that can
			be used in multiple containers (e.g. ID3).
	"""

	if isinstance(data, (os.PathLike, str)):
		data = open(data, 'rb')

	data_reader = DataReader(data)
	data_reader.seek(0, os.SEEK_SET)
	d = data_reader.read(4)

	if d.startswith((b'ID3', b'\xFF\xFB')):  # TODO: Catch all MP3 possibilities.
		if extension is None or extension.endswith('.mp3'):
			return MP3

	if d.startswith((b'fLaC', b'ID3')):
		if extension is None or extension.endswith('.flac'):
			return FLAC

	if d.startswith(b'RIFF'):
		if extension is None or extension.endswith('.wav'):
			return WAV

	return None
def determine_format ( data , extension = None ) : if isinstance ( data , ( os . PathLike , str ) ) : data = open ( data , 'rb' ) data_reader = DataReader ( data ) data_reader . seek ( 0 , os . SEEK_SET ) d = data_reader . read ( 4 ) if d . startswith ( ( b'ID3' , b'\xFF\xFB' ) ) : if extension is None or extension . endswith ( '.mp3' ) : return MP3 if d . startswith ( ( b'fLaC' , b'ID3' ) ) : if extension is None or extension . endswith ( '.flac' ) : return FLAC if d . startswith ( b'RIFF' ) : if extension is None or extension . endswith ( '.wav' ) : return WAV return None
Determine the format of an audio file.

	Parameters:
		data (bytes-like object, str, os.PathLike, or file-like object):
			A bytes-like object, filepath, path-like object
			or file-like object of an audio file.
		extension (str): The file extension of the file.
			Used as a tie-breaker for formats that can
			be used in multiple containers (e.g. ID3).