<commit_before>"use strict";

const fs      = require('fs');
const http    = require('http');
const url     = require('url');
const path    = require('path');
const Events  = require('events');

const express = require('express');
const mv      = require('mv');

const SR        = require('screen-capture-recorder');
const deepMixIn = require('mout/object/deepMixIn');
const pick      = require('mout/object/pick');
const $E        = require('udom/element/create');
const sprintf   = require('nyks/string/format');
const promisify = require('nyks/function/promisify');
const SWFReader = require('swf-properties');
const winapi    = require('winapi');


const nw = !!global.window;
const gui = nw ? window.require('nw.gui') : null;


class AnimationRecorder extends Events.EventEmitter {

  constructor(config) {
    super();


    this.config = {
      output_path  : 'test.avi',
      capture_mode : 'html5', //or swf
      swf_version  : '2.0', //1.0 or 2.0
      duration     : 180, //max duration
      width        : 640,
      height       : 480,
      debug        : false,
      orientation  : "auto", //or 'keep'
    };

    this._screenrecorder = null;

    deepMixIn(this.config, config);

    if(this.config.debug) {
      gui.Window.get().show();
        gui.Window.get().showDevTools()
      gui.Window.get().hide();
    }

    var source_path = this.config.source_path;
    if(!source_path)
      throw new Error("Missing source path");

    this.config.source_path = path.resolve(source_path);
    this.config.source_name = path.basename(this.config.source_path)

    if(!this.config.output_path)
      throw new Error("Missing output path");

    this.config.output_path = path.resolve(this.config.output_path);

    var app = express();

    app.use(express.static(path.dirname(source_path)));

    var self = this;
    var template = fs.readFileSync(path.join(__dirname, '_flash_bootstrap.html'), "utf-8");
      template = template.replace("{MOVIE_NAME}", self.config.source_name);
    app.use('/_flash_bootstrap.html', function(req, res){ res.end(template); });

    this.server = http.createServer(app);


    console.log("Path is ", this.config.source_path);

    if(!fs.existsSync(source_path)) 
      throw "Invalid configuration source path";
  }

  * run() {
    var self = this;

    if(self.config.capture_mode == "swf") {
      var props = yield new Promise(function(resolve, reject) {
        SWFReader(self.config.source_path, function(err, props) {
          if ( err )
            return reject(err);
          resolve(props);
        });
      });

      if(self.config.swf_version == "1.0")
        this.config.duration = props.frameRate != 0 ? props.frameCount / props.frameRate : 0;

      this.config.width  = props.frameSize.width;
      this.config.height = props.frameSize.height;
    }

    var size = pick(this.config, 'width', 'height');
    var isValidSize = function(size, screen) {
      return size.width <= screen.width && size.height <= screen.height;
    }

    var screenInfos = yield promisify(winapi.GetDisplaySettings, winapi)();
    var screen = {
      width  : screenInfos.Size.Width,
      height : screenInfos.Size.Height,
      orientation : screenInfos.Orientation,
    };

    console.log({content:  size, screen: screen});

    if(this.config.orientation == "auto") {

      if(!isValidSize(size, screen)) {
        var rotated = {width : screen.height, height: screen.width };
        var enoughRotate = isValidSize(size, rotated);
        if(!enoughRotate)
          throw "Cannot find matching rotation";

        console.log("Request screen flip");
        if(screen.orientation == 0 || screen.orientation == 2)
          yield promisify(winapi.ReOrientDisplay, winapi)(1);
        else
          yield promisify(winapi.ReOrientDisplay, winapi)(0);
      }
    }


    this._screenrecorder = new SR({x:0,y:0,w:this.config.width,h:this.config.height}, {
      'vcodec' : 'mp2v',
      'vb'     : 4096,
      'fps'    : 25,
    });
<commit_msg>Increase FPS for new generation animations<commit_after>"use strict";

const fs      = require('fs');
const http    = require('http');
const url     = require('url');
const path    = require('path');
const Events  = require('events');

const express = require('express');
const mv      = require('mv');

const SR        = require('screen-capture-recorder');
const deepMixIn = require('mout/object/deepMixIn');
const pick      = require('mout/object/pick');
const $E        = require('udom/element/create');
const sprintf   = require('nyks/string/format');
const promisify = require('nyks/function/promisify');
const SWFReader = require('swf-properties');
const winapi    = require('winapi');


const nw = !!global.window;
const gui = nw ? window.require('nw.gui') : null;


class AnimationRecorder extends Events.EventEmitter {

  constructor(config) {
    super();


    this.config = {
      output_path  : 'test.avi',
      capture_mode : 'html5', //or swf
      swf_version  : '2.0', //1.0 or 2.0
      duration     : 180, //max duration
      width        : 640,
      height       : 480,
      debug        : false,
      orientation  : "auto", //or 'keep'
    };

    this._screenrecorder = null;

    deepMixIn(this.config, config);

    if(this.config.debug) {
      gui.Window.get().show();
        gui.Window.get().showDevTools()
      gui.Window.get().hide();
    }

    var source_path = this.config.source_path;
    if(!source_path)
      throw new Error("Missing source path");

    this.config.source_path = path.resolve(source_path);
    this.config.source_name = path.basename(this.config.source_path)

    if(!this.config.output_path)
      throw new Error("Missing output path");

    this.config.output_path = path.resolve(this.config.output_path);

    var app = express();

    app.use(express.static(path.dirname(source_path)));

    var self = this;
    var template = fs.readFileSync(path.join(__dirname, '_flash_bootstrap.html'), "utf-8");
      template = template.replace("{MOVIE_NAME}", self.config.source_name);
    app.use('/_flash_bootstrap.html', function(req, res){ res.end(template); });

    this.server = http.createServer(app);


    console.log("Path is ", this.config.source_path);

    if(!fs.existsSync(source_path)) 
      throw "Invalid configuration source path";
  }

  * run() {
    var self = this;

    if(self.config.capture_mode == "swf") {
      var props = yield new Promise(function(resolve, reject) {
        SWFReader(self.config.source_path, function(err, props) {
          if ( err )
            return reject(err);
          resolve(props);
        });
      });

      if(self.config.swf_version == "1.0")
        this.config.duration = props.frameRate != 0 ? props.frameCount / props.frameRate : 0;

      this.config.width  = props.frameSize.width;
      this.config.height = props.frameSize.height;
    }

    var size = pick(this.config, 'width', 'height');
    var isValidSize = function(size, screen) {
      return size.width <= screen.width && size.height <= screen.height;
    }

    var screenInfos = yield promisify(winapi.GetDisplaySettings, winapi)();
    var screen = {
      width  : screenInfos.Size.Width,
      height : screenInfos.Size.Height,
      orientation : screenInfos.Orientation,
    };

    console.log({content:  size, screen: screen});

    if(this.config.orientation == "auto") {

      if(!isValidSize(size, screen)) {
        var rotated = {width : screen.height, height: screen.width };
        var enoughRotate = isValidSize(size, rotated);
        if(!enoughRotate)
          throw "Cannot find matching rotation";

        console.log("Request screen flip");
        if(screen.orientation == 0 || screen.orientation == 2)
          yield promisify(winapi.ReOrientDisplay, winapi)(1);
        else
          yield promisify(winapi.ReOrientDisplay, winapi)(0);
      }
    }


    var fps = self.config.swf_version == "1.0" ? 20 : 25;


    this._screenrecorder = new SR({x:0,y:0,w:this.config.width,h:this.config.height}, {
      'vcodec' : 'mp2v',
      'vb'     : 4096,
      'fps'    : fps,
    });
{'fraction_non_alphanumeric': 0.14585131303168536, 'fraction_numerical': 0.008876833929231907, 'mean_word_length': 2.8048780487804876, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5669349', 'n_tokens_mistral': 2613, 'n_tokens_neox': 2488, 'n_words': 517}