Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
renderSlideContent(data) {
const { id, service } = getVideoId(data)
/* eslint-disable-next-line no-console */
if (!id || service !== 'youtube') console.error('Failed to parse Youtube URL')
return (
<div>
</div>
const insertVideo = (change, url) => {
const videoId = getVideoId(url).id
let src
if (url.match(/youtube\.com/)) {
src = `https://www.youtube.com/embed/${videoId}`
} else if (url.match(/vimeo\.com/)) {
src = `https://player.vimeo.com/video/${videoId}`
} else {
alert('Only accept Youtube or Vimeo url'); /* eslint-disable-line */
return
}
change.insertBlock({
type: BLOCKS.VIDEO,
isVoid: true,
data: { src, url }
})
}
store.get().then(r => {
const getUrlFn = opts.getUrlFn;
const action = opts.action;
delete opts.getUrlFn;
delete opts.action;
if (action === 'play') opts.playing = true;
send(opts = Object.assign({
id: uuid(),
width: r.width,
height: r.height,
videoId: getVideoId(opts.url) ? getVideoId(opts.url).id : '',
strings: getLocaleStrings(opts.domain, isAudio(opts.url)),
// tabId: browser.tabs.TAB.id,
launchUrl: opts.url,
currentTime: 0,
confirm: false,
confirmContent: '{}'
}, opts));
// YouTube playlist handling
if (opts.domain === 'youtube.com' && !!~opts.url.indexOf('list')) {
if (!!~opts.url.indexOf('watch?v')) {
const parsed = parse(opts.url.substr(opts.url.indexOf('?') + 1));
youtubeHelpers.getPlaylistMeta({
videoId: parsed.v,
playlistId: parsed.list
}, (meta) => {
handleSourceChange = event => {
const {type} = this.props
const inputValue = event.target.value
this.setState({errorMessage: null})
if (inputValue.length < 3) {
return
}
const result = getVideoId(inputValue)
if (!result) {
this.setState({
result: null,
errorMessage: ERROR_UNKNOWN_VIDEO_SERVICE
})
return
}
if (!result.id) {
this.setState({
result: null,
errorMessage: ERROR_UNKNOWN_VIDEO_ID
})
return
}
export const requestThumbnail = embedUrl => dispatch => {
const { id, service } = getEmbedMetadata( embedUrl ) || {};
switch ( service ) {
case 'youtube': {
const thumbnailUrl = `https://img.youtube.com/vi/${ id }/mqdefault.jpg`;
dispatch( receiveThumbnail( embedUrl, thumbnailUrl ) );
return Promise.resolve();
}
case 'videopress': {
const thumbnailUrl = `https://thumbs.videopress.com/${ id }?c=1`;
dispatch( receiveThumbnail( embedUrl, thumbnailUrl ) );
return Promise.resolve();
}
case 'vimeo': {
debug( `Requesting thumbnail for embed ${ embedUrl }` );
dispatch( {
type: READER_THUMBNAIL_REQUEST,
embedUrl,
function getEmbedCode(value) {
if (!value || !value.url) {
return <span>[Video]</span>
}
const videoId = (value && value.url) ? getVideoId(value.url) : ''
if (!videoId) {
return <span>Unrecognized video service. Supported services: {Object.keys(SERVICES).join(', ')}</span>
}
if (!(videoId.service in SERVICES)) {
return <span>Unsupported video service: {videoId.service}</span>
}
return SERVICES[videoId.service](videoId.id)
}
export default class YoutubeVideo extends React.Component {
public parseVideoUrl(url: string): VideoReturnType {
const { id, service } = getVideoId(url);
if (!id) throw new InternalServerErrorException('Invalid url');
if (service !== 'youtube') throw new NotAcceptableException(`Service ${service} is not supported yet`);
return { id, service };
}
const getAutoplayIframe = iframe => {
const KNOWN_SERVICES = [ 'youtube', 'vimeo', 'videopress' ];
const metadata = getEmbedMetadata( iframe.src );
if ( metadata && includes( KNOWN_SERVICES, metadata.service ) ) {
const autoplayIframe = iframe.cloneNode();
if ( autoplayIframe.src.indexOf( '?' ) === -1 ) {
autoplayIframe.src += '?autoplay=1';
} else {
autoplayIframe.src += '&autoplay=1';
}
return autoplayIframe.outerHTML;
}
return null;
};