'use strict';
/**
* Module dependencies.
*/
var CP_text = require('../lib/CP_text');
/**
* Configuration dependencies.
*/
var config = require('../config/production/config');
Object.keys(config).length === 0 &&
(config = require('../config/production/config.backup'));
var config_md5 = require('md5')(JSON.stringify(config));
var modules = require('../config/production/modules');
Object.keys(modules).length === 0 &&
(modules = require('../config/production/modules.backup'));
var modules_md5 = require('md5')(JSON.stringify(modules));
setInterval(function() {
if (
config_md5 &&
process.env['CP_CONFIG_MD5'] &&
config_md5 !== process.env['CP_CONFIG_MD5']
) {
config = require('../config/production/config');
Object.keys(config).length === 0 &&
(config = require('../config/production/config.backup'));
config_md5 = process.env['CP_CONFIG_MD5'];
}
if (
modules_md5 &&
process.env['CP_MODULES_MD5'] &&
modules_md5 !== process.env['CP_MODULES_MD5']
) {
modules = require('../config/production/modules');
Object.keys(modules).length === 0 &&
(modules = require('../config/production/modules.backup'));
modules_md5 = process.env['CP_MODULES_MD5'];
}
}, 3333);
/**
* Blocking a page player.
*
* @param {Object} code
* @param {Object} [movie]
* @param {Object} [options]
* @param {String} [display]
* @return {Object}
*/
function blockingPlayer(code, movie, options, display) {
if (arguments.length === 1) {
options = {};
options.protocol = config.protocol;
options.domain = config.subdomain + '' + config.domain;
options.origin =
config.protocol + '' + config.subdomain + '' + config.domain;
}
if (
modules.blocking.status &&
modules.blocking.data[display || modules.blocking.data.display]
) {
if (
(display === 'app' || modules.blocking.data.display === 'app') &&
!modules.app.status
) {
return code;
}
var tv_version =
options.domain.indexOf('tv.') !== -1 ||
options.domain.indexOf('/tv-version') !== -1;
var mobile_version =
options.domain.indexOf('m.') !== -1 ||
options.domain.indexOf('/mobile-version') !== -1;
var block = modules.blocking.data[modules.blocking.data.display];
var img = '"' + config.default.image + '"';
var time = block.time ? block.time : 0;
var skip = block.skip ? block.skip : '';
var message = '
' + block.message + '
';
var share =
'';
var adblock =
'' +
'';
var sub =
'' +
'';
var legal =
CP_text.formatting(
config.language === 'ru'
? "Смотреть онлайн в Google
Смотреть онлайн в Яндекс
Купить в ivi
Купить в КиноПоиск HD
"
: "Watch online on Google
\n\n
Watch online on Yandex
\n\n
\n\n
Buy on Google Play
\n\n
Buy on amazon prime
",
movie
) +
'';
var app =
"" +
'
' +
' macOS
' +
'
' +
'
' +
'
' +
'
' +
config.l.downloading +
'' +
'
' +
'
' +
' Windows
' +
'
' +
'
' +
'
' +
'
' +
config.l.downloading +
'' +
'
' +
'
' +
' Linux
' +
'
' +
'
' +
'
' +
'
' +
config.l.downloading +
'' +
'
' +
(modules.blocking.data.app.safe.macos ||
modules.blocking.data.app.safe.windows ||
modules.blocking.data.app.safe.linux
? (modules.blocking.data.app.safe.macos
? '
" +
'
' +
'
' +
config.l.safety +
'' +
'
'
: '
.
') +
(modules.blocking.data.app.safe.windows
? '
" +
'
' +
'
' +
config.l.safety +
'' +
'
'
: '
.
') +
(modules.blocking.data.app.safe.linux
? '
" +
'
' +
'
' +
config.l.safety +
'' +
'
'
: '
.
')
: '') +
(modules.blocking.data.app.instruction.macos ||
modules.blocking.data.app.instruction.windows ||
modules.blocking.data.app.instruction.linux
? (modules.blocking.data.app.instruction.macos
? '
" +
'
' +
'
' +
config.l.instruction +
'' +
'
'
: '
.
') +
(modules.blocking.data.app.instruction.windows
? '
" +
'
' +
'
' +
config.l.instruction +
'' +
'
'
: '
.
') +
(modules.blocking.data.app.instruction.linux
? '
" +
'
' +
'
' +
config.l.instruction +
'' +
'
'
: '
.
')
: '') +
'
' +
'';
if (modules.blocking.data.display === 'app') {
img = '/themes/default/public/app/img/player.png';
}
var blocking =
'' +
'
' +
(modules.blocking.data.display === 'adv' ? block.message : message) +
(modules.blocking.data.display === 'share' ? share : '') +
(modules.blocking.data.display === 'adblock' ? adblock : '') +
(modules.blocking.data.display === 'sub' ? sub : '') +
(modules.blocking.data.display === 'legal' ? legal : '') +
(modules.blocking.data.display === 'app' ? app : '') +
'
' +
'
' +
(time
? '
'
: '') +
'
' +
'';
var countdown = time
? "' +
''
: '';
if (modules.blocking.data.display === 'share' && !tv_version) {
code.player = blocking + countdown + code.player;
} else if (modules.blocking.data.display === 'adv') {
code.player = blocking + countdown + code.player;
} else if (modules.blocking.data.display === 'adblock' && !tv_version) {
code.player = blocking + countdown + code.player;
} else if (modules.blocking.data.display === 'app') {
var l =
options.userinfo &&
modules.blocking.data.app.countries &&
modules.blocking.data.app.countries.length
? modules.blocking.data.app.countries.filter(function(c) {
return new RegExp(options.userinfo.country_en, 'i').test(c);
}).length
: 1;
if (l >= 1 || display) {
code.player =
time && !tv_version && !mobile_version
? blocking +
countdown +
code.player.replace(
/data-player="[a-z0-9,\s%]*?"/i,
'data-player="trailer"'
)
: blocking +
code.player.replace(
/data-player="[a-z0-9,\s%]*?"/i,
'data-player="trailer"'
);
code.footer = code.footer
.replace(/\?player=.*?"/i, '"')
.replace(/\?&id=.*?"/i, '"');
}
} else if (modules.blocking.data.display === 'sub') {
if (
!options.subscribe ||
(options.subscribe &&
modules.blocking.data.sub.keys.indexOf(options.subscribe) === -1)
) {
code.player = blocking;
}
} else if (modules.blocking.data.display === 'legal') {
if (
options.userinfo &&
modules.blocking.data.legal.countries.filter(function(c) {
return new RegExp(options.userinfo.country_en, 'i').test(c);
}).length === 0
) {
code.player =
time && !tv_version
? blocking +
countdown +
(options.userinfo &&
options.userinfo.agent &&
options.userinfo.agent.indexOf('chrome-lighthouse') + 1
? ''
: code.player.replace(
/data-player="[a-z0-9,\s%]*?"/i,
'data-player="pleer,trailer"'
))
: options.userinfo &&
options.userinfo.agent &&
options.userinfo.agent.indexOf('chrome-lighthouse') + 1
? ''
: code.player.replace(
/data-player="[a-z0-9,\s%]*?"/i,
'data-player="pleer,trailer"'
);
code.footer = code.footer
.replace(/\?player=.*?"/i, '"')
.replace(/\?&id=.*?"/i, '"');
}
}
}
return code;
}
module.exports = {
code: blockingPlayer
};