whatsthis
Version:
Discover embedable content from URL's
46 lines (36 loc) • 1.08 kB
JavaScript
;
var embedframe = require('../embedframe');
/**
* Detect if the given URL is an youtube URL.
*
* @param {Result} result Result of message parsing.
* @param {Function} next Continuation callback.
* @private
*/
module.exports = function youtube(result, next) {
if ('xboxdvr.com' !== result.url.hostname) {
return next();
}
var code = result.url.pathname.split('/').pop();
result.url.set('protocol', 'https:');
result.url.set('query', { color: '428bca' });
//
// The xboxdvr service can share 2 different types of content:
//
// 1. Images (screenshots)
// 2. Gameplay (videos)
//
// We need to embed them both differently.
//
if (~result.url.pathname.indexOf('screenshot')) {
result.url.set('pathname', '/gamer/*/screenshot/'+ code +'/embed');
result.type = 'image';
result.service = 'xboxdvr';
} else {
result.url.set('pathname', '/gamer/*/video/'+ code +'/embed');
result.type = 'video';
result.service = 'xboxdvr';
}
result.html = embedframe(result.url.href);
return next(undefined, true);
};