Created
May 25, 2022 02:11
-
-
Save srestraj/a1d2370711bc0cc9447853faf1bb72ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<label for="videourl"> | |
Vimeo or YouTube URL | |
</label> | |
<br/> | |
<input type="text" v-model="videoURL" placeholder="Enter URL" id="videourl"> | |
<div v-if="videoURL != ''"> | |
Extracted Thumbnail: <br/> | |
<img :src="extractedThumbnail" /> | |
</div> | |
</div> | |
</template> | |
<script> | |
import { ref, computed } from "vue"; | |
export default { | |
setup() { | |
const videoURL = ref(""); | |
const extractedThumbnail = computed(() => { | |
if (!videoURL.value) return ""; | |
const regex = /^(http(s)??\:\/\/)?(www\.)?((youtube\.com\/watch\?v=)|(youtu.be\/)|(vimeo\.com\/)|(youtube\.com\/shorts\/)|(dailymotion\.com\/))?/i; | |
let vimeoURL = "vimeo.com"; | |
let dailymotionURL = "dailymotion.com"; | |
let path = ""; | |
if (videoURL.value.includes(vimeoURL)) { | |
path = "https://" + videoURL.value.replace(regex, "vumbnail.com/"); | |
return path + ".jpg"; | |
} else if (videoURL.value.includes(dailymotionURL)) { | |
path = videoURL.value.replace( | |
regex, | |
"https://www.dailymotion.com/thumbnail/" | |
); | |
return path; | |
} else { | |
path = | |
"https://" + videoURL.value.replace(regex, "img.youtube.com/vi/"); | |
return path + "/hqdefault.jpg"; // for high quality videos, you can use maxresdefault.jpg | |
} | |
}); | |
return { | |
videoURL, | |
extractedThumbnail | |
}; | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment