From ea7b309e3e9a6c1e34923572774871850e51642f Mon Sep 17 00:00:00 2001 From: Kirill Efimov Date: Thu, 10 Nov 2016 17:53:34 +0200 Subject: [PATCH] autoplay: removed redundant config key --- config/generic.yml | 9 +++++---- lib/domains/rutube.ru.js | 29 +++++++++++++++++++++++++++++ lib/domains/vimeo.com.js | 6 +----- lib/domains/youtube.com.js | 6 +----- lib/index.js | 2 +- lib/mixins.js | 28 ++++++++++++++++++++++++---- lib/mixins_after.js | 4 +--- test/domains/rutube.ru.js | 3 +++ test/mixins_after.js | 24 +++--------------------- 9 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 lib/domains/rutube.ru.js diff --git a/config/generic.yml b/config/generic.yml index 9ff9661..fe77926 100644 --- a/config/generic.yml +++ b/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 ] diff --git a/lib/domains/rutube.ru.js b/lib/domains/rutube.ru.js new file mode 100644 index 0000000..875942f --- /dev/null +++ b/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(); + } + ] +}; diff --git a/lib/domains/vimeo.com.js b/lib/domains/vimeo.com.js index bbb4d93..2806735 100644 --- a/lib/domains/vimeo.com.js +++ b/lib/domains/vimeo.com.js @@ -87,9 +87,5 @@ module.exports = { env.result.snippets.push(resizedThumbnail); callback(); } - ], - - config: { - autoplay: 'autoplay=1' - } + ] }; diff --git a/lib/domains/youtube.com.js b/lib/domains/youtube.com.js index 54f2150..c2ea30d 100644 --- a/lib/domains/youtube.com.js +++ b/lib/domains/youtube.com.js @@ -100,9 +100,5 @@ module.exports = { 'meta', 'oembed-player', 'oembed-thumbnail' - ], - - config: { - autoplay: 'autoplay=1' - } + ] }; diff --git a/lib/index.js b/lib/index.js index b099627..a3bf51c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 diff --git a/lib/mixins.js b/lib/mixins.js index fbb48a3..887b73f 100644 --- a/lib/mixins.js +++ b/lib/mixins.js @@ -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'); @@ -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'), @@ -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'); @@ -255,7 +265,7 @@ mixins.push({ } if (href) { - env.result.snippets.push({ + let snippet = { type: 'text/html', href: href, tags: [ 'player', 'oembed', 'responsive', 'html5' ], @@ -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'); @@ -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'); } diff --git a/lib/mixins_after.js b/lib/mixins_after.js index 12d114e..a6d3e0b 100644 --- a/lib/mixins_after.js +++ b/lib/mixins_after.js @@ -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'); diff --git a/test/domains/rutube.ru.js b/test/domains/rutube.ru.js index f657345..2925b50 100644 --- a/test/domains/rutube.ru.js +++ b/test/domains/rutube.ru.js @@ -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'); + }); }); }); }); diff --git a/test/mixins_after.js b/test/mixins_after.js index fff0ffa..0d33229 100644 --- a/test/mixins_after.js +++ b/test/mixins_after.js @@ -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 = {