예제 #1
0
def collect_files(music_dir, files, visited_cache, is_supported):
    i = 0
    for dirpath, dirnames, filenames in os.walk(music_dir):
        for filename in filenames:
            filepath = relpath(os.path.join(dirpath, filename), music_dir)
            properpath = os.path.join(dirpath, filename)
            mtime = os.path.getmtime(properpath)

            # check the cache
            if filepath in visited_cache:
                visited_cache[filepath] = True
                record = files[filepath]
                if mtime <= record[1]:
                    # the file's still ok
                    continue

            if is_supported(properpath):
                i += 1
                print("  [%i] %s |" % (i, filepath), end='')
                try:
                    tags = mutagen.File(os.path.join(music_dir, filepath))
                    if tags is None:
                        raise Exception()
                    album_id = albumid.get_album_id(tags)
                    print(album_id or "<single track>")
                    # fields here: album_id, mtime, already_processed
                    files[filepath] = (album_id, mtime, False)
                except Exception:
                    # TODO: Maybe optionally abort here?
                    print("IGNORED: unreadable file or unsupported format")
예제 #2
0
 def test_mb_album_id_only(self):
     tags = mutagen.File(os.path.join(DATA_PATH, "mb-album-id.flac"))
     self.assertEqual(albumid.get_album_id(tags), "MB Album ID")
예제 #3
0
 def test_only_album_mp3(self):
     tags = ID3FileType(os.path.join(DATA_PATH, "album-tag.mp3"))
     self.assertEqual(albumid.get_album_id(tags), "Test Album")
예제 #4
0
 def test_only_albumartist(self):
     tags = mutagen.File(os.path.join(DATA_PATH, "albumartist.flac"))
     self.assertEqual(albumid.get_album_id(tags), None)
예제 #5
0
 def test_album_flac(self):
     tags = mutagen.File(os.path.join(DATA_PATH, "album-tag.flac"))
     self.assertEqual(albumid.get_album_id(tags), "Test Album")
예제 #6
0
 def test_no_tags_mp3(self):
     tags = ID3FileType(os.path.join(DATA_PATH, "no-tags.mp3"))
     self.assertEqual(albumid.get_album_id(tags), None)
예제 #7
0
 def test_no_tags_flac(self):
     tags = mutagen.File(os.path.join(DATA_PATH, "no-tags.flac"))
     self.assertEqual(albumid.get_album_id(tags), None)
예제 #8
0
 def test_album_and_artist(self):
     tags = ID3FileType(os.path.join(DATA_PATH, "album-artist.mp3"))
     self.assertEqual(albumid.get_album_id(tags),
                      "Test Artist - Test Album")
예제 #9
0
 def test_album_and_albumartist(self):
     tags = ID3FileType(os.path.join(DATA_PATH,
                                     "album-and-albumartist.mp3"))
     self.assertEqual(albumid.get_album_id(tags),
                      "Album Artist - Album Title")