Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vimeo): load thumbnail using Vimeo API #19

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/components/LazyVimeo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ import VideoWrapper from "./common/Wrapper";
export default {
name: "LazyVimeo",
mixins: [commonMixin, vimeoMixin],
data() {
return {
videoID: null
}
},
props: {
src: {
type: String,
Expand Down Expand Up @@ -133,6 +128,9 @@ name: "LazyVimeo",

},
computed: {
videoID: function () {
return this.getVimeoID(this.src)
},
aspectRatioValue: function () {
return this.calcAspect(this.aspectRatio)
},
Expand All @@ -159,4 +157,4 @@ name: "LazyVimeo",

<style scoped>

</style>
</style>
12 changes: 8 additions & 4 deletions src/mixins/commonMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,26 @@ export default {
const self = this
let url = ''

url = type === 'youtube' ? `https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${this.videoID}&format=json` : `https://vimeo.com/api/oembed.json?url=${this.src}`
url = type === 'youtube' ? `https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=${this.videoID}&format=json` : `https://vimeo.com/api/v2/video/${this.videoID}.json`
axios.get(url)
.then(function (response) {
// handle success
self.videoInfo = response.data
if(type === 'youtube') {
self.videoInfo = response.data
}

if (type === 'vimeo') {
self.videoID = response.data.video_id
self.videoInfo = response.data[0]
}

self.isVideoFound = true
})
.catch(function () {
// handle error
self.videoInfo = null
self.isVideoFound = false
})
.then(function () {
.finally(function () {
// always executed
self.fetchingInfo = false

Expand Down
40 changes: 10 additions & 30 deletions src/mixins/vimeoMixin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// const axios = require('axios').default

export default {
methods: {
getVimeoID (url) {
return new URL(url).pathname.split('/').pop();
},
playVideo() {
if(!this.isPostMessageSupported) {
return
Expand Down Expand Up @@ -31,35 +36,10 @@ export default {
},

getVimeoThumbnail(video_id, quality){
let thumbnail;

if(video_id){
if(typeof quality == "undefined"){
quality = 'high';
}

let quality_key = '960x540';
if(quality === 'default'){
quality_key = '200x150';
}
else if(quality === 'medium'){
quality_key = '295x166';
}
else if(quality === 'high'){
quality_key = '640x360';
}
else if (quality === 'standard') {
quality_key = '960x540';
}
else if (quality === 'maxres') {
quality_key = '1280x720';
}

thumbnail = "https://i.vimeocdn.com/video/"+video_id+"_"+quality_key+".jpg";
return thumbnail;
}

return false;
if(!video_id) return false;

const _quality = ['small', 'medium', 'large'].includes(quality) ? quality: 'medium';
return this.videoInfo[`thumbnail_${_quality}`];
}
}
};
};
5 changes: 1 addition & 4 deletions src/mixins/youtubeMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export default {
}
},
getYoutubeThumbnail (video_id, quality) {
let thumbnail

if (video_id) {
if (typeof quality === 'undefined') {
quality = 'high'
Expand All @@ -56,8 +54,7 @@ export default {
quality_key = 'maxresdefault'
}

thumbnail = 'http://img.youtube.com/vi/' + video_id + '/' + quality_key + '.jpg'
return thumbnail
return `https://img.youtube.com/vi/${video_id}/${quality_key}.jpg`;
}

return false
Expand Down