Пример #1
0
def test_mp3_mono():
    metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-mono.mp3', dict())
    check_default_metadata(metadata)
    assert metadata['channels'] == 1
    assert metadata['bit_rate'] == 64876
    assert abs(metadata['length_seconds'] - 3.9) < 0.1
    assert metadata['mime'] == 'audio/mp3' # Not unicode because MIMEs aren't.
    assert metadata['track_total'] == u'10' # MP3s can have a track_total
Пример #2
0
def test_mp3_dualmono():
    metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-dualmono.mp3', dict())
    check_default_metadata(metadata)
    assert metadata['channels'] == 2
    assert metadata['bit_rate'] == 129757
    assert abs(metadata['length_seconds'] - 3.9) < 0.1
    assert metadata['mime'] == 'audio/mp3'
    assert metadata['track_total'] == u'10' # MP3s can have a track_total
Пример #3
0
def test_ogg_stereo():
    metadata = MetadataAnalyzer.analyze(
        'tests/test_data/44100Hz-16bit-stereo.ogg', dict())
    check_default_metadata(metadata)
    assert metadata['channels'] == 2
    assert metadata['bit_rate'] == 112000
    assert abs(metadata['length_seconds'] - 3.8) < 0.1
    assert metadata['mime'] == 'audio/vorbis'
    assert metadata['comment'] == 'Test Comment'
Пример #4
0
def test_unparsable_file():
    metadata = MetadataAnalyzer.analyze("tests/test_data/unparsable.txt", dict())
    assert metadata == {
        "filesize": 10,
        "ftype": "audioclip",
        "hidden": False,
        "md5": "4d5e4b1c8e8febbd31fa9ce7f088beae",
        "mime": "text/plain",
    }
Пример #5
0
def test_mp3_utf8():
    metadata = MetadataAnalyzer.analyze(u'tests/test_data/44100Hz-16bit-stereo-utf8.mp3', dict())
    # Using a bunch of different UTF-8 codepages here. Test data is from:
    #   http://winrus.com/utf8-jap.htm
    assert metadata['track_title'] == u'アイウエオカキクケコサシスセソタチツテ'
    assert metadata['artist_name'] == u'てすと'
    assert metadata['album_title'] == u'Ä ä Ü ü ß'
    assert metadata['year'] == u'1999'
    assert metadata['genre'] == u'Я Б Г Д Ж Й'
    assert metadata['track_number'] == u'1'
    assert metadata['channels'] == 2
    assert metadata['bit_rate'] == 129757
    assert abs(metadata['length_seconds'] - 3.9) < 0.1
    assert metadata['mime'] == 'audio/mp3'
    assert metadata['track_total'] == u'10' # MP3s can have a track_total
Пример #6
0
def test_wav_stereo():
    metadata = MetadataAnalyzer.analyze(
        "tests/test_data/44100Hz-16bit-stereo.wav", dict()
    )
    assert metadata == {
        "sample_rate": 44100,
        "channels": 2,
        "filesize": 677316,
        "md5": "6bd5df4f161375e4634cbd4968fb5c23",
        "mime": "audio/x-wav",
        "cueout": "0:00:03.839410",
        "ftype": "audioclip",
        "hidden": False,
        "length": "0:00:03.839410",
        "length_seconds": 3.8394104308390022,
    }
Пример #7
0
def test_mp3_bad_channels():
    filename = 'tests/test_data/44100Hz-16bit-mono.mp3'
    '''
        It'd be a pain in the ass to construct a real MP3 with an invalid number
        of channels by hand because that value is stored in every MP3 frame in the file
    '''
    audio_file = mutagen.File(filename, easy=True)
    audio_file.info.mode = 1777
    with mock.patch('airtime_analyzer.metadata_analyzer.mutagen') as mock_mutagen:
        mock_mutagen.File.return_value = audio_file
        #mock_mutagen.side_effect = lambda *args, **kw: audio_file #File(*args, **kw)

    metadata = MetadataAnalyzer.analyze(filename, dict())
    check_default_metadata(metadata)
    assert metadata['channels'] == 1
    assert metadata['bit_rate'] == 63998
    assert abs(metadata['length_seconds'] - 3.9) < 0.1
    assert metadata['mime'] == 'audio/mp3' # Not unicode because MIMEs aren't.
    assert metadata['track_total'] == '10' # MP3s can have a track_total
Пример #8
0
def test_mp3_bad_channels():
    """
    Test an mp3 file where the number of channels is invalid or missing.
    """
    # It'd be a pain in the ass to construct a real MP3 with an invalid number
    # of channels by hand because that value is stored in every MP3 frame in the file
    filename = "tests/test_data/44100Hz-16bit-mono.mp3"
    audio_file = mutagen.File(filename, easy=True)
    audio_file.info.mode = 1777
    with mock.patch("airtime_analyzer.metadata_analyzer.mutagen") as mock_mutagen:
        mock_mutagen.File.return_value = audio_file

    metadata = MetadataAnalyzer.analyze(filename, dict())
    assert metadata == {
        **default_metadata(metadata),
        "bit_rate": 63998,
        "channels": 1,
        "filesize": 32298,
        "md5": "a93c9503c85cd2fbe7658711a08c24b1",
        "mime": "audio/mp3",
        "track_total": "10",
    }
Пример #9
0
def test_unparsable_file():
    MetadataAnalyzer.analyze('README.rst', dict())
Пример #10
0
def test_move_wrong_metadata_dict():
    not_a_dict = list()
    MetadataAnalyzer.analyze('asdfasdf', not_a_dict)
Пример #11
0
def test_move_wrong_string_param1():
    not_unicode = 'asdfasdf'
    MetadataAnalyzer.analyze(not_unicode, dict())
Пример #12
0
def test_wav_stereo():
    metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-stereo.wav', dict())
    assert metadata['mime'] == 'audio/x-wav'
    assert abs(metadata['length_seconds'] - 3.9) < 0.1
    assert metadata['channels'] == 2
    assert metadata['sample_rate'] == 44100
Пример #13
0
def test_invalid_wma():
    metadata = MetadataAnalyzer.analyze('tests/test_data/44100Hz-16bit-stereo-invalid.wma', dict())
    assert metadata['mime'] == 'audio/x-ms-wma'
Пример #14
0
def test_unparsable_file():
    MetadataAnalyzer.analyze('tests/test_data/unparsable.txt', dict())
Пример #15
0
def test_analyze_wrong_params(params, exception):
    with pytest.raises(exception):
        MetadataAnalyzer.analyze(*params)
Пример #16
0
def test_invalid_wma():
    metadata = MetadataAnalyzer.analyze(
        "tests/test_data/44100Hz-16bit-stereo-invalid.wma", dict()
    )
    assert metadata["mime"] == "audio/x-ms-wma"
Пример #17
0
def test_analyze(filepath, expected):
    metadata = MetadataAnalyzer.analyze(filepath, dict())
    assert abs(metadata["length_seconds"] - 3.9) < 0.1
    assert metadata == {**default_metadata(metadata), **expected}