Exemplo n.º 1
0
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
Exemplo n.º 2
0
 def test_aiff(self):
     actual = file_info.channels(INPUT_FILE2)
     expected = 3
     self.assertEqual(expected, actual)
Exemplo n.º 3
0
 def test_empty(self):
     actual = file_info.channels(EMPTY_FILE)
     expected = 1
     self.assertEqual(expected, actual)
Exemplo n.º 4
0
 def test_wav(self):
     actual = file_info.channels(INPUT_FILE)
     expected = 1
     self.assertEqual(expected, actual)
Exemplo n.º 5
0
 def test_empty(self):
     actual = file_info.channels(EMPTY_FILE)
     expected = 1
     self.assertEqual(expected, actual)
Exemplo n.º 6
0
 def test_aiff(self):
     actual = file_info.channels(INPUT_FILE2)
     expected = 3
     self.assertEqual(expected, actual)
Exemplo n.º 7
0
 def test_wav(self):
     actual = file_info.channels(INPUT_FILE)
     expected = 1
     self.assertEqual(expected, actual)
Exemplo n.º 8
0
 def test_wav_pathlib(self):
     actual = file_info.channels(Path(INPUT_FILE))
     expected = 1
     self.assertEqual(expected, actual)