diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-08-18 14:25:52 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-08-18 14:25:52 +0200 |
commit | 5b0d917da3bbca4613b1d477cd36d8e78426f523 (patch) | |
tree | 430d7af84b0072691f7c81b8f4fd4aea62ad0d53 | |
parent | fe57e38ba374fbbefdc7ba1b96ca9dcfe6795565 (diff) |
Tag support using mutagen.
-rw-r--r-- | directory.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/directory.py b/directory.py index 5a757bd..c7bef2d 100644 --- a/directory.py +++ b/directory.py @@ -1,4 +1,4 @@ -import os, mimetypes, recode, events, cuesheet +import os, mimetypes, recode, events, cuesheet, mutagen from config import config @@ -59,7 +59,17 @@ class Directory(DirectoryEntry): metadata['title'] = t.title files.append(File(rel_path, track = t.track[0], metadata = metadata)) else: - files.append(File(rel_path)) + metadata = {} + tags = mutagen.File(abs_path) or [] + if isinstance(tags, mutagen.mp3.MP3): + for id3, tn in (('TPE1', 'artist'), ('TALB', 'album'), ('TIT2', 'title')): + if id3 in tags: + metadata[tn] = tags[id3].text[0] + else: + for tn in ('artist', 'album', 'title'): + if tn in tags: + metadata[tn] = tags[tn][0].encode('utf-8') + files.append(File(rel_path, metadata = metadata)) return sorted(directories) + sorted(files) class File(DirectoryEntry): |