def scan(filepath): # sox package has an info() but it should not be used: # it's just a wrapper that calls a set of functions # and returns them in a dict # ...and the functions are the wrong ones :) info_dictionary = { 'file_type': file_info.file_type(filepath), 'sample_rate': round(file_info.sample_rate(filepath)), 'channels': file_info.channels(filepath), 'duration': file_info.duration(filepath), # 'bit_rate': file_info.bitrate(filepath), 'encoding': file_info.encoding(filepath), } # bitrate is currently broken (1.37) but we can fake it info_dictionary['bit_rate'] = round( getsize(filepath) / info_dictionary['duration'] * 8) # get comments too comments = file_info.comments(filepath).splitlines() if comments: info_dictionary['tags'] = {} for comment in comments: key, value = comment.strip().split('=', 1) info_dictionary['tags'][key.lower()] = value return info_dictionary
def test_aiff(self): actual = file_info.comments(INPUT_FILE2) expected = "Processed by SoX" self.assertEqual(expected, actual)
def test_empty(self): actual = file_info.comments(EMPTY_FILE) expected = "" self.assertEqual(expected, actual)
def test_wav(self): actual = file_info.comments(INPUT_FILE) expected = "" self.assertEqual(expected, actual)
def test_wav_pathlib(self): actual = file_info.comments(Path(INPUT_FILE)) expected = "" self.assertEqual(expected, actual)