 async   = require 'async'
 fs      = require 'fs'
 Helpers = require '../helpers/thumb'
+log     = require('printit')
+    date: true
+    prefix: "model:photo"
 
 module.exports = class Photo extends cozydb.CozyModel
     @schema:

    extractGpsFromBinary: (callback) ->
        kind = if @binary.raw then 'raw' else 'file'
        res  = @getBinary kind, (err) ->
            console.log err if err?

        res.on 'ready', (stream) =>
            Helpers.readMetadata stream, (err, data) =>
                if err?
                    console.log err
                    callback()
                else
                    @updateAttributes { gps: data.exif.gps }, (err) ->
                        console.log err if err?
                        callback() # ~ next()



            async.eachSeries binaries, (bin, cb) =>
                @removeBinary bin, (err) =>
                    if err
                        log.error """
                            Cannot destroy binary linked to photo #{@id}"""
                    cb()
            , (err) =>
