koel/resources/assets/js/components/main-wrapper/extra/youtube.vue

94 lines
1.8 KiB
Vue
Raw Normal View History

2016-07-30 15:32:17 +00:00
<template>
<div id="youtube-wrapper">
<template v-if="videos && videos.length">
2016-10-31 04:28:12 +00:00
<a class="video" v-for="video in videos" href @click.prevent="playYouTube(video.id.videoId)">
2016-07-30 15:32:17 +00:00
<div class="thumb">
<img :src="video.snippet.thumbnails.default.url" width="90">
</div>
<div class="meta">
<h3 class="title">{{ video.snippet.title }}</h3>
<p class="desc">{{ video.snippet.description }}</p>
</div>
</a>
<button @click="loadMore" v-if="!loading" class="more btn-blue">Load More</button>
</template>
2016-10-31 03:41:30 +00:00
<p class="nope" v-else>Play a song to retrieve related YouTube videos.</p>
2016-07-30 15:32:17 +00:00
<p class="nope" v-show="loading">Loading</p>
</div>
</template>
<script>
import { event } from '../../../utils';
import { youtube as youtubeService } from '../../../services';
export default {
name: 'main-wrapper--extra--youtube',
props: ['song'],
data() {
return {
loading: false,
videos: [],
};
},
watch: {
song(val) {
this.videos = val.youtube ? val.youtube.items : [];
},
},
methods: {
playYouTube(id) {
youtubeService.play(id);
},
/**
* Load more videos.
*/
loadMore() {
this.loading = true;
youtubeService.searchVideosRelatedToSong(this.song, () => {
this.videos = this.song.youtube.items;
this.loading = false;
});
},
},
};
</script>
<style lang="sass" scoped>
#youtube-wrapper {
overflow-x: hidden;
.video {
display: flex;
padding: 12px 0;
border-bottom: 1px solid #333;
.thumb {
margin-right: 10px;
}
.title {
font-size: 1.1rem;
margin-bottom: .4rem;
}
.desc {
font-size: .9rem;
}
&:hover {
.title {
color: #fff;
}
}
&:last-of-type {
margin-bottom: 16px;
}
}
}
</style>