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")
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")
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")
def test_only_albumartist(self): tags = mutagen.File(os.path.join(DATA_PATH, "albumartist.flac")) self.assertEqual(albumid.get_album_id(tags), None)
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")
def test_no_tags_mp3(self): tags = ID3FileType(os.path.join(DATA_PATH, "no-tags.mp3")) self.assertEqual(albumid.get_album_id(tags), None)
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)
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")
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")