<commit_before>var util    = require('util'),
    winston = require('winston');

var Camera,
    stream,
    isStreaming = false;


function Stream( opts ) {
    if ( !(this instanceof Stream) ) {
        return new Stream( opts );
    }

    var required = ['module', 'preview_path', 'preview', 'photo_path', 'photo'];
    for (var i in required) {
       if ('undefined' === typeof opts || 'undefined' === typeof opts[required[i]]) {
           winston.error('Error: raspberry: must define ' + required[i]);
       }
    }

    this.opts = {};
    this.setOpts(opts);
}

Stream.prototype.setOpts = function(opts) {
    this.opts = util._extend(this.opts, opts);
    this.opts.preview.output = this.formatPath(this.opts.preview_path);
    this.opts.photo.output = this.formatPath(this.opts.photo_path);

    if ('undefined' !== typeof opts.module) {
        var module = this.opts.module;
        winston.info('switch to ' + module + ' camera');
        try {
            Camera = require(module);
        } catch (e) {
            Camera = require('../' + module);
        }
    }
};

Stream.prototype.formatPath = function(path) {
    return path
        .replace('%root%', process.cwd())
        .replace('%ts%', new Date().getTime());
};

Stream.prototype.start = function(callback) {
    if (isStreaming) {
        return;
    }
    winston.info('start stream');

    var self = this;
    stream = new Camera(self.opts.preview);
    stream
        .on('change', function(err, date, filename) {
            if ('~' === filename.slice(1)) {
                return;
            }
            callback.call(this, err, date, filename);
        })
        .start();
    isStreaming = true;
    return true;
};

Stream.prototype.stop = function() {
    winston.info('stop stream');

    stream.stop();
    isStreaming = false;
    return true;
};

Stream.prototype.capture = function(callback) {<commit_msg>Ignore temp files<commit_after>var util    = require('util'),
    winston = require('winston');

var Camera,
    stream,
    isStreaming = false;


function Stream( opts ) {
    if ( !(this instanceof Stream) ) {
        return new Stream( opts );
    }

    var required = ['module', 'preview_path', 'preview', 'photo_path', 'photo'];
    for (var i in required) {
       if ('undefined' === typeof opts || 'undefined' === typeof opts[required[i]]) {
           winston.error('Error: raspberry: must define ' + required[i]);
       }
    }

    this.opts = {};
    this.setOpts(opts);
}

Stream.prototype.setOpts = function(opts) {
    this.opts = util._extend(this.opts, opts);
    this.opts.preview.output = this.formatPath(this.opts.preview_path);
    this.opts.photo.output = this.formatPath(this.opts.photo_path);

    if ('undefined' !== typeof opts.module) {
        var module = this.opts.module;
        winston.info('switch to ' + module + ' camera');
        try {
            Camera = require(module);
        } catch (e) {
            Camera = require('../' + module);
        }
    }
};

Stream.prototype.formatPath = function(path) {
    return path
        .replace('%root%', process.cwd())
        .replace('%ts%', new Date().getTime());
};

Stream.prototype.start = function(callback) {
    if (isStreaming) {
        return;
    }
    winston.info('start stream');

    var self = this;
    stream = new Camera(self.opts.preview);
    stream
        .on('change', function(err, date, filename) {
            if ('~' === filename.slice(-1)) {
                return;
            }
            callback.call(this, err, date, filename);
        })
        .start();
    isStreaming = true;
    return true;
};

Stream.prototype.stop = function() {
    winston.info('stop stream');

    stream.stop();
    isStreaming = false;
    return true;
};

Stream.prototype.capture = function(callback) {
{'fraction_non_alphanumeric': 0.1585014409221902, 'fraction_numerical': 0.0005239717055279015, 'mean_word_length': 2.372791519434629, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2472554', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1146, 'n_words': 252}