<|start_filename|>examples/serverdownloadmp3.js<|end_filename|>
'use strict';

var horizon = require('../lib/index');
var http = require('http');
var url  = require('url') ;
var log = require('console-log-level')({ level: 'info' });

var server = http.createServer(function(request, response) {

  var paramsUrl = url.parse(request.url, true).query;
  log.info('URL Video: ' + paramsUrl.youtubeURL);

  //var cropParams = {start:'02:15', end:'02:20'}; //Optional
  var cropParams = null;

  horizon.download(paramsUrl.youtubeURL, response, null, cropParams, null, true, function(err, e){

    if(err) {
      return log.info(err);
    }

    if(e === horizon.successType.CONVERSION_FILE_COMPLETE){
      log.info(e);
    }
  });
});

server.listen(3000);
log.info('Server running!');
log.info('Put on browser: http://localhost:3000/?youtubeURL=http://youtube.com/watch?v=NEA0BLnpOtg');

<|start_filename|>examples/downloadmp3.js<|end_filename|>
'use strict';

var horizon = require('../lib/index'); //use 'horizon-youtube-mp3'
var path = require('path');

var downloadPath = path.join(__dirname);

horizon.downloadToLocal(
  'http://youtube.com/watch?v=NEA0BLnpOtg',
  downloadPath,
  null,
  null,
  null,
  onConvertVideoComplete,
  onConvertVideoProgress
);

function onConvertVideoComplete(err, result) {
  console.log(err, result);
  // Will return...
  //null, conversionFileComplete
}

function onConvertVideoProgress(percent, timemark, targetSize) {
  console.log('Progress:', percent, 'Timemark:', timemark, 'Target Size:', targetSize);
  // Will return...
  // Progress: 90.45518257038955 Timemark: 00:02:20.04 Target Size: 2189
  // Progress: 93.73001672942894 Timemark: 00:02:25.11 Target Size: 2268
  // Progress: 100.0083970106642 Timemark: 00:02:34.83 Target Size: 2420
}

<|start_filename|>examples/videoinfo.js<|end_filename|>
'use strict';

var horizon = require('../lib/index');
var log = require('console-log-level')({ level: 'info' });

horizon.getInfo('http://youtube.com/watch?v=NEA0BLnpOtg', function(err, e){

  log.info(e);

  /**
     * It'll return:
     *
     * { isValid: true,
     *   videoName: 'OZIELZINHO - TOP GEAR 2.0',
     *   videoThumb: 'https://i.ytimg.com/vi/NEA0BLnpOtg/hqdefault.jpg?custom=true&w=320&h=180&stc=true&jpg444=true&jpgq=90&sp=68&sigh=FoGsoudXCGPU-Fb6epRh1eIzVDs',
     *   videoThumbList: [{url, width, height}, {...}...]
     *   videoTime: '2:35',
      *  videoFile: 'https://....'}
     */
});

<|start_filename|>lib/toHHMMSS.js<|end_filename|>
/**
 * Created by wendersonpires on 27/11/16.
 */

'use strict';

/**
 * Return HH:MM:SS String from seconds
 * @param sec_num   Seconds
 * @returns {string}    HH:MM:SS String
 */
function secondsToHHMMSS(sec_num) {
  var d = Number(sec_num);
  var h = Math.floor(d / 3600);
  var m = Math.floor(d % 3600 / 60);
  var s = Math.floor(d % 3600 % 60);
  return ((h > 0 ? h + ':' + (m < 10 ? '0' : '') : '') + m + ':' + (s < 10 ? '0' : '') + s);
}

module.exports = secondsToHHMMSS;

<|start_filename|>lib/itags.js<|end_filename|>
/**
 * Created by wendersonpires on 27/11/16.
 */

'use strict';

// Itags Video info
const itags = {
  ITAG_43  : '43',
  ITAG_251 : '251',
  ITAG_140 : '140'
};

module.exports = itags;