 mmd = require 'musicmetadata'
 path = require 'path'
 upnp = require 'upnp-device'
+mime.define 'audio/flac': ['flac']
 
 getContainerType = (fileTypes) ->
     maxVal = 0

        (err) -> callback err, sortedFiles

mimeContainerMap =
    audio: 'album.musicAlbum'

makeContainer = (dir, sortedFiles, callback) ->
    contentType = getContainerType sortedFiles
    media =
        type: 'container'
        instance: mimeContainerMap[contentType]
        location: dir
    
    if contentType is 'audio'
        stream = fs.createReadStream sortedFiles[contentType][0]
        parser = new mmd stream
        parser.on 'metadata', (data) ->
            media.creator = data.albumartist[0]
            media.title = data.album
            callback null, media
        parser.on 'done', (err) ->

        callback null, media

mimeItemMap =
    audio: 'object.item.audioItem.musicTrack'
    image: 'object.item.imageItem'
    text: 'object.item.textItem'

makeItem = (type, file, callback) ->
    media =
        class: mimeItemMap[type] or 'object.item'
        location: file
     switch type
        when 'audio'
            parser = new mmd stream = fs.createReadStream file
            parser.on 'metadata', (data) ->
                media.creator = data.artist?[0] or 'Unknown'
                media.title = data.title or 'Untitled'
                media.album = data.album or 'Untitled'
                callback null, media
