Skip to content

Commit

Permalink
autoplay: removed redundant config key
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill89 committed Nov 10, 2016
1 parent 5fe975a commit ea7b309
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 43 deletions.
9 changes: 5 additions & 4 deletions config/generic.yml
@@ -1,7 +1,8 @@
# This list contains domains that use default rules.
# Custom domains from 'lib/domains' included automatically.

-
id: rutube.ru
config:
autoplay: autoStart=true
#-
# id: example.com
# config:
# og:
# video: [ ssl ]
29 changes: 29 additions & 0 deletions lib/domains/rutube.ru.js
@@ -0,0 +1,29 @@
/////////////////////////////////////////////////////////////////////////////
// Rutube
//
'use strict';


module.exports = {
match: [
/^https?:\/\/(?:www\.)?rutube\.ru.*/i
],

mixinsAfter: [
'*',
function (env, callback) {
env.result.snippets.forEach(snippet => {
if (snippet.type !== 'text/html' ||
snippet.tags.indexOf('player') === -1 ||
snippet.tags.indexOf('autoplay') === -1) {

return; // continue
}

snippet.media.autoplay = 'autoStart=true';
});

callback();
}
]
};
6 changes: 1 addition & 5 deletions lib/domains/vimeo.com.js
Expand Up @@ -87,9 +87,5 @@ module.exports = {
env.result.snippets.push(resizedThumbnail);
callback();
}
],

config: {
autoplay: 'autoplay=1'
}
]
};
6 changes: 1 addition & 5 deletions lib/domains/youtube.com.js
Expand Up @@ -100,9 +100,5 @@ module.exports = {
'meta',
'oembed-player',
'oembed-thumbnail'
],

config: {
autoplay: 'autoplay=1'
}
]
};
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -31,7 +31,7 @@ let domains = _.reduce(requireAll(path.join(__dirname, 'domains')), (acc, config
}, []);

// Load generic domains
domains = domains.concat(yaml.safeLoad(fs.readFileSync(path.join(__dirname, '..', 'config', 'generic.yml'))));
domains = domains.concat(yaml.safeLoad(fs.readFileSync(path.join(__dirname, '..', 'config', 'generic.yml'))) || []);


// Create Embedza
Expand Down
28 changes: 24 additions & 4 deletions lib/mixins.js
Expand Up @@ -137,6 +137,10 @@ mixins.push({
snippet.type = 'text/html';
}

if (utils.wlCheck(env.wl, 'twitter.player', 'autoplay')) {
snippet.tags.push('autoplay');
}

env.result.snippets.push(snippet);

debug('twitter-player: done');
Expand Down Expand Up @@ -175,7 +179,7 @@ mixins.push({
return; // continue
}

env.result.snippets.push({
let snippet = {
href: href,
tags: [ 'player', 'og', 'responsive' ],
type: utils.findMeta(playerMeta, 'og:video:type'),
Expand All @@ -184,7 +188,13 @@ mixins.push({
height: utils.findMeta(playerMeta, 'og:video:height'),
duration: utils.findMeta(playerMeta, 'og:video:duration')
}, _.isUndefined)
});
};

if (utils.wlCheck(env.wl, 'oembed.video', 'autoplay')) {
snippet.tags.push('autoplay');
}

env.result.snippets.push(snippet);
});

debug('og-player: done');
Expand Down Expand Up @@ -255,7 +265,7 @@ mixins.push({
}

if (href) {
env.result.snippets.push({
let snippet = {
type: 'text/html',
href: href,
tags: [ 'player', 'oembed', 'responsive', 'html5' ],
Expand All @@ -264,7 +274,13 @@ mixins.push({
height: env.data.oembed.height,
duration: env.data.oembed.duration
}, _.isUndefined)
});
};

if (utils.wlCheck(env.wl, 'oembed.video', 'autoplay')) {
snippet.tags.push('autoplay');
}

env.result.snippets.push(snippet);
}

debug('oembed-player: done');
Expand Down Expand Up @@ -388,6 +404,10 @@ mixins.push({
}, _.isUndefined)
};

if (utils.wlCheck(env.wl, 'oembed.rich', 'autoplay')) {
snippet.tags.push('autoplay');
}

if (utils.wlCheck(env.wl, 'oembed.rich', 'reader')) {
snippet.tags.push('reader');
}
Expand Down
4 changes: 1 addition & 3 deletions lib/mixins_after.js
Expand Up @@ -292,9 +292,7 @@ mixinsAfter.push({
return; // continue
}

if (env.config.autoplay) {
snippet.media.autoplay = env.config.autoplay;
}
snippet.media.autoplay = 'autoplay=1';
});

debug('set-autoplay: done');
Expand Down
3 changes: 3 additions & 0 deletions test/domains/rutube.ru.js
Expand Up @@ -12,6 +12,9 @@ describe('rutube.ru', function () {
return embedza.info('https://rutube.ru/video/8623c112d77065f9b8167da7b7d8214f/')
.then(res => {
assert.strictEqual(res.meta.title, 'Физрук: Жил-был пёс');
res.snippets.forEach(s => {
if (s.tags.indexOf('player') !== -1) assert.strictEqual(s.media.autoplay, 'autoplay=1');
});
});
});
});
24 changes: 3 additions & 21 deletions test/mixins_after.js
Expand Up @@ -82,41 +82,23 @@ describe('mixins after', function () {
it('set-autoplay', function (done) {
let mixin = mixinsAfter.find(m => m.id === 'set-autoplay');
let env = {
config: { autoplay: true },
config: {},
result: {
snippets: [
{ href: 'http://example.com/1', tags: [ 'player' ], media: {}, type: 'text/html' },
{ href: 'http://example.com/1', tags: [ 'player', 'autoplay' ], media: {}, type: 'text/html' },
{ href: 'http://example.com/1', tags: [ 'player' ], media: {}, type: 'non/html' }
]
}
};

mixin.fn(env, err => {
assert.strictEqual(env.result.snippets[0].media.autoplay, true);
assert.strictEqual(env.result.snippets[0].media.autoplay, 'autoplay=1');
assert.deepStrictEqual(env.result.snippets[1].media, {});
done(err);
});
});


it('set-autoplay no config', function (done) {
let mixin = mixinsAfter.find(m => m.id === 'set-autoplay');
let env = {
config: {},
result: {
snippets: [
{ href: 'http://example.com/1', tags: [ 'player' ], media: {}, type: 'text/html' }
]
}
};

mixin.fn(env, err => {
assert.deepStrictEqual(env.result.snippets[0].media, {});
done(err);
});
});


it('convert-str-int', function (done) {
let mixin = mixinsAfter.find(m => m.id === 'convert-str-int');
let env = {
Expand Down

0 comments on commit ea7b309

Please sign in to comment.