const ytSearch = require( 'yt-search' );
on ({id: 'sonus.0.data.detected', change: 'any'}, function (obj) {
console.log('Detected words: ' + obj.state.val);
if (obj.state.val.match(/найди */i)) {
var searchtext = obj.state.val;
searchtext.replace(/найди/i, '');
console.log("searchtext="+searchtext);
var saytext = 'Ищу и включаю видео';
setState("javascript.0.Volume1",30);
setState("sayit.1.tts.text",'ru;30;'+saytext);
ytSearch( searchtext, function ( err, r ) {
if ( err ) throw err
const videos = r.videos;
const firstResult = videos[ 0 ]
var str_videoid=JSON.stringify(firstResult.videoId);
str_videoid = str_videoid.substring(1, str_videoid.length-1);
const wol = require('wol');
console.log('Turning on');
wol.wake('78:5D:C8:C9:68:03', function(err, res){
console.log(res);
});
var lgtv = require("lgtv2")({
url: 'ws://192.168.3.100:3000'
});
lgtv.on('error', function (err) {
console.log(err);
});
lgtv.on('connect', function () {
console.log('Launch youtube');
lgtv.request('ssap://system.launcher/launch', {id: 'youtube.leanback.v4', contentId:str_videoid});
});
} )
}