def scan(path, _read_id3_hook=None):
    """Produce an AudioFile object for the file at 'path'.

    This function inspects the entire file, computing the fingerprint
    and frame statistics.  The 'volume' and 'import_timestamp' fields
    are not set.

    This function is much more computationally expensive than scan_fast(),
    but is more accurate and produces more complete information.

    Args:
      path: The path to an MP3 file.
      _read_id3_hook: An optional callable that takes a path and
        returns mutagen ID3 data.  Passing in None (the default) uses
        a default implementation.  This argument should only be used
        for testing.

    Returns:
      An AudioFile object describing the file at 'path', or None if it
      does not appear to be a valid MPEG file.
    """
    au_file = AudioFile()
    au_file.path = path
    au_file.mutagen_id3 = (_read_id3_hook or _get_mp3)(path)
    if au_file.mutagen_id3 is None:
        return None

    file_obj = open(path)
    try:
        analyzer.analyze(file_obj, au_file)
    finally:
        file_obj.close()

    return au_file
Exemple #2
0
def scan(path, _read_id3_hook=None):
    """Produce an AudioFile object for the file at 'path'.

    This function inspects the entire file, computing the fingerprint
    and frame statistics.  The 'volume' and 'import_timestamp' fields
    are not set.

    This function is much more computationally expensive than scan_fast(),
    but is more accurate and produces more complete information.

    Args:
      path: The path to an MP3 file.
      _read_id3_hook: An optional callable that takes a path and
        returns mutagen ID3 data.  Passing in None (the default) uses
        a default implementation.  This argument should only be used
        for testing.

    Returns:
      An AudioFile object describing the file at 'path', or None if it
      does not appear to be a valid MPEG file.
    """
    au_file = AudioFile()
    au_file.path = path
    au_file.mutagen_id3 = (_read_id3_hook or _get_mp3)(path)
    if au_file.mutagen_id3 is None:
        return None

    file_obj = open(path)
    try:
        analyzer.analyze(file_obj, au_file)
    finally:
        file_obj.close()

    return au_file
    def test_known(self):
        f = os.path.join(ROOT_DIR,
                         "library/testdata/analyzer_test/test001.mp3")
        stream = open(f)
        au_file = audio_file.AudioFile()
        analyzer.analyze(stream, au_file)
        stream.close()

        self.assertTrue(au_file is not None)
        self.assertEqual("244227850107a0b44f1f554d5c960630e2693025",
                         au_file.fingerprint)
        self.assertEqual(150, au_file.frame_count)
        self.assertEqual(137173, au_file.frame_size)
        self.assertEqual(44100, au_file.mp3_header.sampling_rate_hz)
        self.assertAlmostEqual(280.32, au_file.mp3_header.bit_rate_kbps)  # VBR
        self.assertEqual(3918, au_file.duration_ms)
        self.assertEqual(au_file.frame_size, len(au_file.payload))

        # Volume, Deposit timestamp, Mutagen ID3 info and filename are
        # not set.
        self.assertEqual(None, au_file.volume)
        self.assertEqual(None, au_file.import_timestamp)
        self.assertEqual(None, au_file.mutagen_id3)
        self.assertEqual(None, au_file.path)
    def test_known(self):
        f = os.path.join(ROOT_DIR,
                         "library/testdata/analyzer_test/test001.mp3")
        stream = open(f)
        au_file = audio_file.AudioFile()
        analyzer.analyze(stream, au_file)
        stream.close()

        self.assertTrue(au_file is not None)
        self.assertEqual("244227850107a0b44f1f554d5c960630e2693025",
                         au_file.fingerprint)
        self.assertEqual(150, au_file.frame_count)
        self.assertEqual(137173, au_file.frame_size)
        self.assertEqual(44100, au_file.mp3_header.sampling_rate_hz)
        self.assertAlmostEqual(280.32, au_file.mp3_header.bit_rate_kbps)  # VBR
        self.assertEqual(3918, au_file.duration_ms)
        self.assertEqual(au_file.frame_size, len(au_file.payload))

        # Volume, Deposit timestamp, Mutagen ID3 info and filename are
        # not set.
        self.assertEqual(None, au_file.volume)
        self.assertEqual(None, au_file.import_timestamp)
        self.assertEqual(None, au_file.mutagen_id3)
        self.assertEqual(None, au_file.path)