FreeTube/src/renderer/components/playlist-info/playlist-info.js

128 lines
3.6 KiB
JavaScript
Raw Normal View History

import { defineComponent } from 'vue'
import FtShareButton from '../ft-share-button/ft-share-button.vue'
import { copyToClipboard, formatNumber, openExternalLink } from '../../helpers/utils'
2020-02-16 19:30:00 +01:00
export default defineComponent({
name: 'PlaylistInfo',
2020-02-16 19:30:00 +01:00
components: {
'ft-share-button': FtShareButton
2020-02-16 19:30:00 +01:00
},
props: {
data: {
type: Object,
required: true
}
},
data: function () {
return {
id: '',
firstVideoId: '',
playlistThumbnail: '',
2020-02-16 19:30:00 +01:00
title: '',
channelThumbnail: '',
channelName: '',
channelId: null,
2020-02-16 19:30:00 +01:00
videoCount: 0,
viewCount: 0,
lastUpdated: '',
description: '',
infoSource: ''
2020-02-16 19:30:00 +01:00
}
},
computed: {
hideSharingActions: function() {
return this.$store.getters.getHideSharingActions
},
currentInvidiousInstance: function () {
return this.$store.getters.getCurrentInvidiousInstance
},
2020-06-19 22:20:06 +02:00
thumbnailPreference: function () {
return this.$store.getters.getThumbnailPreference
},
blurThumbnails: function () {
return this.$store.getters.getBlurThumbnails
},
blurThumbnailsStyle: function () {
return this.blurThumbnails ? 'blur(20px)' : null
},
backendPreference: function () {
return this.$store.getters.getBackendPreference
},
hideViews: function () {
return this.$store.getters.getHideVideoViews
},
thumbnail: function () {
if (this.thumbnailPreference === 'hidden') {
return require('../../assets/img/thumbnail_placeholder.svg')
}
let baseUrl
if (this.backendPreference === 'invidious') {
baseUrl = this.currentInvidiousInstance
} else {
return this.data.playlistThumbnail
}
switch (this.thumbnailPreference) {
case 'start':
return `${baseUrl}/vi/${this.firstVideoId}/mq1.jpg`
case 'middle':
return `${baseUrl}/vi/${this.firstVideoId}/mq2.jpg`
case 'end':
return `${baseUrl}/vi/${this.firstVideoId}/mq3.jpg`
default:
return `${baseUrl}/vi/${this.firstVideoId}/mqdefault.jpg`
}
2020-02-16 19:30:00 +01:00
}
},
mounted: function () {
this.id = this.data.id
this.firstVideoId = this.data.firstVideoId
2020-02-16 19:30:00 +01:00
this.title = this.data.title
this.channelName = this.data.channelName
this.channelThumbnail = this.data.channelThumbnail
this.channelId = this.data.channelId
2020-02-16 19:30:00 +01:00
this.uploadedTime = this.data.uploaded_at
this.description = this.data.description
this.infoSource = this.data.infoSource
2020-02-16 19:30:00 +01:00
// Causes errors if not put inside of a check
if (typeof (this.data.viewCount) !== 'undefined' && !isNaN(this.data.viewCount)) {
this.viewCount = this.hideViews ? null : formatNumber(this.data.viewCount)
2020-02-16 19:30:00 +01:00
}
if (typeof (this.data.videoCount) !== 'undefined' && !isNaN(this.data.videoCount)) {
this.videoCount = formatNumber(this.data.videoCount)
2020-02-16 19:30:00 +01:00
}
this.lastUpdated = this.data.lastUpdated
},
methods: {
sharePlaylist: function (method) {
const youtubeUrl = `https://youtube.com/playlist?list=${this.id}`
const invidiousUrl = `${this.currentInvidiousInstance}/playlist?list=${this.id}`
2020-02-16 19:30:00 +01:00
switch (method) {
case 'copyYoutube':
copyToClipboard(youtubeUrl, { messageOnSuccess: this.$t('Share.YouTube URL copied to clipboard') })
2020-02-16 19:30:00 +01:00
break
case 'openYoutube':
openExternalLink(youtubeUrl)
2020-02-16 19:30:00 +01:00
break
case 'copyInvidious':
copyToClipboard(invidiousUrl, { messageOnSuccess: this.$t('Share.Invidious URL copied to clipboard') })
2020-02-16 19:30:00 +01:00
break
case 'openInvidious':
openExternalLink(invidiousUrl)
2020-02-16 19:30:00 +01:00
break
}
}
2020-02-16 19:30:00 +01:00
}
})