JSFiddle - React, Tailwind, and code Playground
by Chris Ball
JavaScript
class VideoThumbnailService {
constructor( videoURL ) {
this.getVideoType( videoURL )
}
getVideoType( videoURL ) {
let urlObject = new URL( videoURL )
let domain = urlObject.hostname
if (domain.includes('vimeo'))
this.vimeo( videoURL )
else if (domain.includes('youtu'))
this.youtube( videoURL )
}
youtube( videoID ) {
this.type = 'youtube'
return 'blah'
// return `https://img.youtube.com/vi/${videoID}/maxresdefault.jpg`
}
vimeo( videoURL ) {
this.type = 'vimeo'
const videoData = `http://vimeo.com/api/oembed.json?url=${videoURL}`
const thumbnail = videoData.thumbnail_url
const thumbnailLarge = videoData.thumbnail_url.replace(/(._640$)/, '')
}
}
let thing = (new VideoThumbnailService('https://www.youtube.com/watch?v=jUuqBZwwkQw'))
console.log(thing.type)