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

93 lines
1.8 KiB
Vue
Raw Normal View History

2016-07-30 15:32:17 +00:00
<template>
2016-11-15 07:54:41 +00:00
<div id="youtube-extra-wrapper">
2016-07-30 15:32:17 +00:00
<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>
2016-11-26 03:25:35 +00:00
import { youtube as youtubeService } from '../../../services'
2016-07-30 15:32:17 +00:00
export default {
name: 'main-wrapper--extra--youtube',
props: ['song'],
2016-11-26 03:25:35 +00:00
data () {
2016-07-30 15:32:17 +00:00
return {
loading: false,
2016-11-26 03:25:35 +00:00
videos: []
}
2016-07-30 15:32:17 +00:00
},
watch: {
2016-11-26 03:25:35 +00:00
song (val) {
this.videos = val.youtube ? val.youtube.items : []
}
2016-07-30 15:32:17 +00:00
},
methods: {
2016-11-26 03:25:35 +00:00
playYouTube (id) {
youtubeService.play(id)
2016-07-30 15:32:17 +00:00
},
/**
* Load more videos.
*/
2016-11-26 03:25:35 +00:00
loadMore () {
this.loading = true
2016-07-30 15:32:17 +00:00
youtubeService.searchVideosRelatedToSong(this.song, () => {
2016-11-26 03:25:35 +00:00
this.videos = this.song.youtube.items
this.loading = false
})
}
}
}
2016-07-30 15:32:17 +00:00
</script>
<style lang="sass" scoped>
2016-11-15 07:54:41 +00:00
#youtube-extra-wrapper {
2016-07-30 15:32:17 +00:00
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>