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

async   = require 'async'
fs      = require 'fs'
Helpers = require '../helpers/thumb'

module.exports = class Photo extends cozydb.CozyModel
    @schema:

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

        res.on 'ready', (stream) =>
            Helpers.readMetadata stream, (err, data) =>
                if err?
                    log.error "Error reading metadata of #{@id} / #{@title}"
                    log.error err
                    callback()
                else
                    @updateAttributes { gps: data.exif.gps }, (err) ->
                        log.error err if err?
                        callback() # ~ next()


