2020-02-16 18:30:00 +00:00
|
|
|
import Vue from 'vue'
|
2020-06-11 00:21:31 +00:00
|
|
|
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
|
2020-02-16 18:30:00 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: 'FtListVideo',
|
2020-06-11 00:21:31 +00:00
|
|
|
components: {
|
|
|
|
'ft-icon-button': FtIconButton
|
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
props: {
|
|
|
|
data: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
},
|
2020-05-17 20:12:58 +00:00
|
|
|
playlistId: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
forceListType: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2020-06-23 15:47:19 +00:00
|
|
|
},
|
|
|
|
appearance: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
id: '',
|
|
|
|
title: '',
|
|
|
|
channelName: '',
|
|
|
|
channelId: '',
|
|
|
|
viewCount: 0,
|
2020-08-12 03:26:49 +00:00
|
|
|
parsedViewCount: '',
|
2020-02-16 18:30:00 +00:00
|
|
|
uploadedTime: '',
|
|
|
|
duration: '',
|
|
|
|
description: '',
|
|
|
|
watched: false,
|
|
|
|
progressPercentage: 0,
|
|
|
|
isLive: false,
|
|
|
|
isFavorited: false,
|
2020-06-11 00:21:31 +00:00
|
|
|
hideViews: false,
|
|
|
|
optionsValues: [
|
|
|
|
'openYoutube',
|
|
|
|
'copyYoutube',
|
|
|
|
'openYoutubeEmbed',
|
|
|
|
'copyYoutubeEmbed',
|
|
|
|
'openInvidious',
|
|
|
|
'copyInvidious'
|
|
|
|
]
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2020-06-11 00:21:31 +00:00
|
|
|
usingElectron: function () {
|
|
|
|
return this.$store.getters.getUsingElectron
|
|
|
|
},
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
listType: function () {
|
|
|
|
return this.$store.getters.getListType
|
|
|
|
},
|
|
|
|
|
2020-02-27 03:10:56 +00:00
|
|
|
thumbnailPreference: function () {
|
|
|
|
return this.$store.getters.getThumbnailPreference
|
2020-05-17 20:12:58 +00:00
|
|
|
},
|
|
|
|
|
2020-06-03 02:27:55 +00:00
|
|
|
backendPreference: function () {
|
|
|
|
return this.$store.getters.getBackendPreference
|
|
|
|
},
|
|
|
|
|
|
|
|
invidiousInstance: function () {
|
|
|
|
return this.$store.getters.getInvidiousInstance
|
|
|
|
},
|
|
|
|
|
2020-06-11 00:21:31 +00:00
|
|
|
invidiousUrl: function () {
|
|
|
|
return `${this.invidiousInstance}/watch?v=${this.id}`
|
|
|
|
},
|
|
|
|
|
|
|
|
youtubeUrl: function () {
|
|
|
|
return `https://www.youtube.com/watch?v=${this.id}`
|
|
|
|
},
|
|
|
|
|
|
|
|
youtubeEmbedUrl: function () {
|
|
|
|
return `https://www.youtube-nocookie.com/embed/${this.id}`
|
|
|
|
},
|
|
|
|
|
2020-08-12 03:26:49 +00:00
|
|
|
optionsNames: function () {
|
|
|
|
return [
|
|
|
|
this.$t('Video.Open in YouTube'),
|
|
|
|
this.$t('Video.Copy YouTube Link'),
|
|
|
|
this.$t('Video.Open YouTube Embedded Player'),
|
|
|
|
this.$t('Video.Copy YouTube Embedded Player Link'),
|
|
|
|
this.$t('Video.Open in Invidious'),
|
|
|
|
this.$t('Video.Copy Invidious Link')
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
2020-05-17 20:12:58 +00:00
|
|
|
thumbnail: function () {
|
2020-06-03 02:27:55 +00:00
|
|
|
let baseUrl
|
|
|
|
if (this.backendPreference === 'invidious') {
|
|
|
|
baseUrl = this.invidiousInstance
|
|
|
|
} else {
|
|
|
|
baseUrl = 'https://i.ytimg.com'
|
|
|
|
}
|
|
|
|
|
2020-05-17 20:12:58 +00:00
|
|
|
switch (this.thumbnailPreference) {
|
|
|
|
case 'start':
|
2020-06-03 02:27:55 +00:00
|
|
|
return `${baseUrl}/vi/${this.id}/mq1.jpg`
|
2020-05-17 20:12:58 +00:00
|
|
|
case 'middle':
|
2020-06-03 02:27:55 +00:00
|
|
|
return `${baseUrl}/vi/${this.id}/mq2.jpg`
|
2020-05-17 20:12:58 +00:00
|
|
|
case 'end':
|
2020-06-03 02:27:55 +00:00
|
|
|
return `${baseUrl}/vi/${this.id}/mq3.jpg`
|
2020-05-17 20:12:58 +00:00
|
|
|
default:
|
2020-06-03 02:27:55 +00:00
|
|
|
return `${baseUrl}/vi/${this.id}/mqdefault.jpg`
|
2020-05-17 20:12:58 +00:00
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted: function () {
|
|
|
|
// Check if data came from Invidious or from local backend
|
|
|
|
|
|
|
|
if (typeof (this.data.descriptionHtml) !== 'undefined' ||
|
|
|
|
typeof (this.data.index) !== 'undefined' ||
|
2020-06-25 01:41:46 +00:00
|
|
|
typeof (this.data.authorId) !== 'undefined' ||
|
2020-02-16 18:30:00 +00:00
|
|
|
typeof (this.data.publishedText) !== 'undefined' ||
|
|
|
|
typeof (this.data.authorThumbnails) === 'object'
|
|
|
|
) {
|
|
|
|
this.parseInvidiousData()
|
|
|
|
} else {
|
|
|
|
this.parseLocalData()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggleSave: function () {
|
|
|
|
console.log('TODO: ft-list-video method toggleSave')
|
|
|
|
},
|
|
|
|
|
2020-06-11 00:21:31 +00:00
|
|
|
handleOptionsClick: function (option) {
|
|
|
|
console.log('Handling share')
|
|
|
|
console.log(option)
|
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case 'copyYoutube':
|
|
|
|
navigator.clipboard.writeText(this.youtubeUrl)
|
|
|
|
break
|
|
|
|
case 'openYoutube':
|
|
|
|
if (this.usingElectron) {
|
|
|
|
const shell = require('electron').shell
|
|
|
|
shell.openExternal(this.youtubeUrl)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case 'copyYoutubeEmbed':
|
|
|
|
navigator.clipboard.writeText(this.youtubeEmbedUrl)
|
|
|
|
break
|
|
|
|
case 'openYoutubeEmbed':
|
|
|
|
if (this.usingElectron) {
|
|
|
|
const shell = require('electron').shell
|
|
|
|
shell.openExternal(this.youtubeEmbedUrl)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case 'copyInvidious':
|
|
|
|
navigator.clipboard.writeText(this.invidiousUrl)
|
|
|
|
break
|
|
|
|
case 'openInvidious':
|
|
|
|
if (this.usingElectron) {
|
|
|
|
console.log('using electron')
|
|
|
|
const shell = require('electron').shell
|
|
|
|
shell.openExternal(this.invidiousUrl)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
// For Invidious data, as duration is sent in seconds
|
|
|
|
calculateVideoDuration: function (lengthSeconds) {
|
|
|
|
let durationText = ''
|
|
|
|
let time = lengthSeconds
|
|
|
|
let hours = 0
|
|
|
|
|
|
|
|
if (time >= 3600) {
|
|
|
|
hours = Math.floor(time / 3600)
|
|
|
|
time = time - hours * 3600
|
|
|
|
}
|
|
|
|
|
|
|
|
let minutes = Math.floor(time / 60)
|
|
|
|
let seconds = time - minutes * 60
|
|
|
|
|
|
|
|
if (seconds < 10) {
|
|
|
|
seconds = '0' + seconds
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minutes < 10 && hours > 0) {
|
|
|
|
minutes = '0' + minutes
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hours > 0) {
|
|
|
|
durationText = hours + ':' + minutes + ':' + seconds
|
|
|
|
} else {
|
|
|
|
durationText = minutes + ':' + seconds
|
|
|
|
}
|
|
|
|
|
|
|
|
return durationText
|
|
|
|
},
|
|
|
|
|
|
|
|
parseInvidiousData: function () {
|
|
|
|
this.id = this.data.videoId
|
|
|
|
this.title = this.data.title
|
|
|
|
// this.thumbnail = this.data.videoThumbnails[4].url
|
2020-05-17 20:12:58 +00:00
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
this.channelName = this.data.author
|
|
|
|
this.channelId = this.data.authorId
|
|
|
|
this.duration = this.calculateVideoDuration(this.data.lengthSeconds)
|
|
|
|
this.description = this.data.description
|
|
|
|
this.isLive = this.data.liveNow
|
2020-08-12 03:26:49 +00:00
|
|
|
this.viewCount = this.data.viewCount
|
2020-02-16 18:30:00 +00:00
|
|
|
|
|
|
|
if (typeof (this.data.publishedText) !== 'undefined') {
|
|
|
|
this.uploadedTime = this.data.publishedText
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof (this.data.viewCount) !== 'undefined' && this.data.viewCount !== null) {
|
2020-08-12 03:26:49 +00:00
|
|
|
this.parsedViewCount = this.data.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
2020-02-16 18:30:00 +00:00
|
|
|
} else if (typeof (this.data.viewCountText) !== 'undefined') {
|
2020-08-12 03:26:49 +00:00
|
|
|
this.parsedViewCount = this.data.viewCountText.replace(' views', '')
|
2020-02-16 18:30:00 +00:00
|
|
|
} else {
|
|
|
|
this.hideViews = true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
parseLocalData: function () {
|
|
|
|
if (typeof (this.data.id) !== 'undefined') {
|
|
|
|
this.id = this.data.id
|
|
|
|
} else {
|
|
|
|
this.id = this.data.link.replace('https://www.youtube.com/watch?v=', '')
|
|
|
|
}
|
|
|
|
|
|
|
|
this.title = this.data.title
|
|
|
|
|
|
|
|
if (typeof (this.data.author) === 'string') {
|
|
|
|
this.channelName = this.data.author
|
|
|
|
this.channelId = this.data.ucid
|
2020-08-12 03:26:49 +00:00
|
|
|
this.viewCount = this.data.views
|
2020-02-16 18:30:00 +00:00
|
|
|
|
|
|
|
// Data is returned as a literal string names 'undefined'
|
|
|
|
if (this.data.length_seconds !== 'undefined') {
|
|
|
|
this.duration = this.calculateVideoDuration(parseInt(this.data.length_seconds))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.channelName = this.data.author.name
|
|
|
|
this.duration = this.data.duration
|
|
|
|
this.description = this.data.description
|
|
|
|
this.channelId = this.data.author.ref.replace('https://www.youtube.com/user/', '')
|
|
|
|
this.channelId = this.channelId.replace('https://www.youtube.com/channel/', '')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof (this.data.uploaded_at) !== 'undefined') {
|
|
|
|
this.uploadedTime = this.data.uploaded_at
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.data.views !== null && typeof (this.data.views) !== 'undefined') {
|
2020-08-12 03:26:49 +00:00
|
|
|
this.parsedViewCount = this.data.views.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
2020-02-16 18:30:00 +00:00
|
|
|
} else if (typeof (this.data.view_count) !== 'undefined') {
|
|
|
|
const viewCount = this.data.view_count.replace(',', '')
|
2020-08-12 03:26:49 +00:00
|
|
|
this.parsedViewCount = viewCount.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
2020-02-16 18:30:00 +00:00
|
|
|
} else {
|
|
|
|
this.hideViews = true
|
|
|
|
}
|
|
|
|
|
2020-05-23 21:29:42 +00:00
|
|
|
this.isLive = this.data.live
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|