 require('zappa') port, ->
   @get '/res/:id': ->
     db.hget @params.id, 'path', (err, path) =>
-      @response.sendfile path
+      # Transcode to mp3 using ffmpeg
+      @response.contentType 'mp3'
+      prov = new ffmpeg(path)
+        .withAudioCodec('libmp3lame')
+        .toFormat('mp3')
+        .writeToStream @response, (ret, err) ->
+          console.log err if err?

    mediaServer.addMedia parentId, item, cb

add = (parentId, path, sortedFiles, cb) ->
  async.forEachLimit Object.keys(sortedFiles), 5,
    (type, cb) -> async.forEach sortedFiles[type],
      (item, cb) ->
        if type is 'folder'
          addContainer parentId, item, cb

"use strict"

async = require 'async'
ffmpeg = require 'fluent-ffmpeg'
fs = require 'fs'
mime = require 'mime'
mmd = require 'musicmetadata'
