 mimeContainerMap =
     audio: 'object.container.album.musicAlbum'
 
+# Parse tags using musicmediadata module
+parseTags = (file, cb) ->
+    stream = fs.createReadStream file
+    stream.on 'error', (err) -> console.log "#{err.message} - #{stream.path}"
+    parser = new mmd stream
+    parser.on 'metadata', (data) -> cb data
+    parser.on 'done', (err) ->
+        console.log "#{err.message} - #{stream.path}" if err?
+        stream.destroy()
+
 makeContainer = (dir, sortedFiles, callback) ->
     contentType = getContainerType sortedFiles
     media =

        location: dir
    
    if contentType is 'audio'
        parser = new mmd stream = fs.createReadStream sortedFiles[contentType][0]
        parser.on 'metadata', (data) ->
            media.creator = data.albumartist?[0] or data.artist?[0] or 'Unknown'
            media.title = data.album
            callback null, media
        parser.on 'done', (err) ->
            console.error(err) if err?
            stream.destroy()
    else
        media.creator = 'Unknown'
        media.title = path.basename(dir).split('/')[0]

        location: file
     switch type
        when 'audio'
            parseTags file, (data) ->
                media.creator = media.artist = data.artist?[0] or 'Unknown'
                media.title = data.title or 'Untitled'
                media.album = data.album or 'Untitled'
                media.genre = data.genre?[0] if data.genre?[0]?
                media.track = data.track?.no if data.track?.no > 0
                media.date = data.year if data.year > 0
                callback null, media
        else
            media.creator = 'Unknown'
            media.title = path.basename file, path.extname file
