summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--directory.py14
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):