From 5b0d917da3bbca4613b1d477cd36d8e78426f523 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Thu, 18 Aug 2011 14:25:52 +0200 Subject: Tag support using mutagen. --- directory.py | 14 ++++++++++++-- 1 file 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): -- cgit v1.2.3