2020-02-16 18:30:00 +00:00
|
|
|
import Vue from 'vue'
|
2020-02-28 03:29:30 +00:00
|
|
|
import xml2vtt from 'yt-xml2vtt'
|
|
|
|
import $ from 'jquery'
|
2020-02-16 18:30:00 +00:00
|
|
|
import FtLoader from '../../components/ft-loader/ft-loader.vue'
|
|
|
|
import FtCard from '../../components/ft-card/ft-card.vue'
|
|
|
|
import FtElementList from '../../components/ft-element-list/ft-element-list.vue'
|
|
|
|
import FtVideoPlayer from '../../components/ft-video-player/ft-video-player.vue'
|
|
|
|
import WatchVideoInfo from '../../components/watch-video-info/watch-video-info.vue'
|
|
|
|
import WatchVideoDescription from '../../components/watch-video-description/watch-video-description.vue'
|
|
|
|
import WatchVideoComments from '../../components/watch-video-comments/watch-video-comments.vue'
|
2020-05-17 20:12:58 +00:00
|
|
|
import WatchVideoPlaylist from '../../components/watch-video-playlist/watch-video-playlist.vue'
|
2020-02-16 18:30:00 +00:00
|
|
|
import WatchVideoRecommendations from '../../components/watch-video-recommendations/watch-video-recommendations.vue'
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: 'Watch',
|
|
|
|
components: {
|
|
|
|
'ft-loader': FtLoader,
|
|
|
|
'ft-card': FtCard,
|
|
|
|
'ft-element-list': FtElementList,
|
|
|
|
'ft-video-player': FtVideoPlayer,
|
|
|
|
'watch-video-info': WatchVideoInfo,
|
|
|
|
'watch-video-description': WatchVideoDescription,
|
|
|
|
'watch-video-comments': WatchVideoComments,
|
2020-05-17 20:12:58 +00:00
|
|
|
'watch-video-playlist': WatchVideoPlaylist,
|
2020-02-28 03:29:30 +00:00
|
|
|
'watch-video-recommendations': WatchVideoRecommendations,
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
2020-02-28 03:29:30 +00:00
|
|
|
data: function() {
|
2020-02-16 18:30:00 +00:00
|
|
|
return {
|
|
|
|
isLoading: false,
|
|
|
|
firstLoad: true,
|
2020-04-22 02:59:09 +00:00
|
|
|
useTheatreMode: false,
|
2020-02-16 18:30:00 +00:00
|
|
|
showDashPlayer: true,
|
|
|
|
showLegacyPlayer: false,
|
|
|
|
showYouTubeNoCookieEmbed: false,
|
2020-02-19 03:31:10 +00:00
|
|
|
hidePlayer: false,
|
2020-05-17 20:12:58 +00:00
|
|
|
isLive: false,
|
2020-02-19 03:31:10 +00:00
|
|
|
activeFormat: 'legacy',
|
2020-02-16 18:30:00 +00:00
|
|
|
videoId: '',
|
|
|
|
videoTitle: '',
|
|
|
|
videoDescription: '',
|
|
|
|
videoDescriptionHtml: '',
|
|
|
|
videoViewCount: 0,
|
|
|
|
videoLikeCount: 0,
|
|
|
|
videoDislikeCount: 0,
|
|
|
|
channelName: '',
|
|
|
|
channelThumbnail: '',
|
|
|
|
channelId: '',
|
|
|
|
channelSubscriptionCountText: '',
|
|
|
|
videoPublished: 0,
|
2020-02-18 20:59:01 +00:00
|
|
|
videoStoryboardSrc: '',
|
2020-02-16 18:30:00 +00:00
|
|
|
audioUrl: '',
|
2020-02-18 20:59:01 +00:00
|
|
|
videoSourceList: [],
|
|
|
|
captionSourceList: [],
|
2020-02-28 03:29:30 +00:00
|
|
|
recommendedVideos: [],
|
2020-05-17 20:12:58 +00:00
|
|
|
watchingPlaylist: false,
|
|
|
|
playlistId: '',
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2020-04-18 03:17:45 +00:00
|
|
|
usingElectron: function () {
|
|
|
|
return this.$store.getters.getUsingElectron
|
|
|
|
},
|
|
|
|
|
2020-03-01 03:37:02 +00:00
|
|
|
backendPreference: function () {
|
2020-02-16 18:30:00 +00:00
|
|
|
return this.$store.getters.getBackendPreference
|
|
|
|
},
|
|
|
|
|
2020-03-01 03:37:02 +00:00
|
|
|
backendFallback: function () {
|
2020-02-16 18:30:00 +00:00
|
|
|
return this.$store.getters.getBackendFallback
|
|
|
|
},
|
|
|
|
|
2020-03-01 03:37:02 +00:00
|
|
|
invidiousInstance: function () {
|
2020-02-16 18:30:00 +00:00
|
|
|
return this.$store.getters.getInvidiousInstance
|
|
|
|
},
|
|
|
|
|
2020-04-14 02:59:25 +00:00
|
|
|
proxyVideos: function () {
|
|
|
|
return this.$store.getters.getProxyVideos
|
|
|
|
},
|
|
|
|
|
2020-04-22 02:59:09 +00:00
|
|
|
defaultTheatreMode: function () {
|
|
|
|
return this.$store.getters.getDefaultTheatreMode
|
|
|
|
},
|
|
|
|
|
2020-03-01 03:37:02 +00:00
|
|
|
defaultVideoFormat: function () {
|
|
|
|
return this.$store.getters.getDefaultVideoFormat
|
2020-02-19 03:31:10 +00:00
|
|
|
},
|
|
|
|
|
2020-03-01 03:37:02 +00:00
|
|
|
forceLocalBackendForLegacy: function () {
|
|
|
|
return this.$store.getters.getForceLocalBackendForLegacy
|
|
|
|
},
|
|
|
|
|
|
|
|
youtubeNoCookieEmbeddedFrame: function () {
|
2020-02-16 18:30:00 +00:00
|
|
|
return `<iframe width='560' height='315' src='https://www.youtube-nocookie.com/embed/${this.videoId}?rel=0' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>`
|
2020-02-18 20:59:01 +00:00
|
|
|
},
|
|
|
|
|
2020-03-01 03:37:02 +00:00
|
|
|
dashSrc: function () {
|
2020-04-18 03:17:45 +00:00
|
|
|
let url = `${this.invidiousInstance}/api/manifest/dash/id/${this.videoId}.mpd`
|
2020-04-14 02:59:25 +00:00
|
|
|
|
2020-04-18 03:17:45 +00:00
|
|
|
if (this.proxyVideos || !this.usingElectron) {
|
2020-04-14 02:59:25 +00:00
|
|
|
url = url + '?local=true'
|
|
|
|
}
|
|
|
|
|
2020-02-28 03:29:30 +00:00
|
|
|
return [
|
|
|
|
{
|
2020-04-14 02:59:25 +00:00
|
|
|
url: url,
|
2020-02-28 03:29:30 +00:00
|
|
|
type: 'application/dash+xml',
|
|
|
|
label: 'Dash',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
watch: {
|
2020-02-28 03:29:30 +00:00
|
|
|
$route() {
|
2020-02-16 18:30:00 +00:00
|
|
|
// react to route changes...
|
|
|
|
this.videoId = this.$route.params.id
|
|
|
|
|
|
|
|
this.firstLoad = true
|
|
|
|
|
2020-05-17 20:12:58 +00:00
|
|
|
this.checkIfPlaylist()
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
switch (this.backendPreference) {
|
|
|
|
case 'local':
|
|
|
|
this.getVideoInformationLocal(this.videoId)
|
|
|
|
break
|
|
|
|
case 'invidious':
|
|
|
|
this.getVideoInformationInvidious(this.videoId)
|
2020-03-01 03:37:02 +00:00
|
|
|
|
|
|
|
if (this.forceLocalBackendForLegacy) {
|
|
|
|
this.getVideoInformationLocal(this.videoId)
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
break
|
|
|
|
}
|
2020-02-28 03:29:30 +00:00
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
2020-05-17 20:12:58 +00:00
|
|
|
mounted: function () {
|
2020-02-16 18:30:00 +00:00
|
|
|
this.videoId = this.$route.params.id
|
2020-02-18 20:59:01 +00:00
|
|
|
this.videoStoryboardSrc = `${this.invidiousInstance}/api/v1/storyboards/${this.videoId}?height=90`
|
|
|
|
|
2020-03-01 03:37:02 +00:00
|
|
|
this.activeFormat = this.defaultVideoFormat
|
2020-04-22 02:59:09 +00:00
|
|
|
this.useTheatreMode = this.defaultTheatreMode
|
2020-02-19 03:31:10 +00:00
|
|
|
|
2020-05-17 20:12:58 +00:00
|
|
|
this.checkIfPlaylist()
|
|
|
|
|
2020-04-18 03:17:45 +00:00
|
|
|
if (!this.usingElectron) {
|
|
|
|
this.getVideoInformationInvidious()
|
|
|
|
} else {
|
|
|
|
switch (this.backendPreference) {
|
|
|
|
case 'local':
|
|
|
|
this.getVideoInformationLocal()
|
|
|
|
break
|
|
|
|
case 'invidious':
|
|
|
|
this.getVideoInformationInvidious()
|
|
|
|
break
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2020-02-28 03:29:30 +00:00
|
|
|
toggleTheatreMode: function() {
|
2020-02-18 20:59:01 +00:00
|
|
|
this.useTheatreMode = !this.useTheatreMode
|
|
|
|
},
|
|
|
|
|
2020-02-28 03:29:30 +00:00
|
|
|
getVideoInformationLocal: function() {
|
2020-02-16 18:30:00 +00:00
|
|
|
if (this.firstLoad) {
|
|
|
|
this.isLoading = true
|
|
|
|
}
|
|
|
|
|
2020-02-28 03:29:30 +00:00
|
|
|
this.$store
|
|
|
|
.dispatch('ytGetVideoInformation', this.videoId)
|
|
|
|
.then(result => {
|
2020-05-17 20:12:58 +00:00
|
|
|
console.log(result)
|
2020-02-28 03:29:30 +00:00
|
|
|
this.videoTitle = result.title
|
|
|
|
this.videoViewCount = parseInt(
|
|
|
|
result.player_response.videoDetails.viewCount,
|
|
|
|
10
|
|
|
|
)
|
|
|
|
this.channelId = result.author.id
|
|
|
|
this.channelName = result.author.name
|
|
|
|
this.channelThumbnail = result.author.avatar
|
|
|
|
this.videoPublished = result.published
|
|
|
|
this.videoDescription =
|
|
|
|
result.player_response.videoDetails.shortDescription
|
|
|
|
this.recommendedVideos = result.related_videos
|
|
|
|
this.videoLikeCount = result.likes
|
|
|
|
this.videoDislikeCount = result.dislikes
|
2020-05-17 20:12:58 +00:00
|
|
|
this.isLive = result.player_response.videoDetails.isLive
|
|
|
|
|
|
|
|
if (this.isLive) {
|
|
|
|
this.showLegacyPlayer = false
|
|
|
|
this.showDashPlayer = true
|
|
|
|
this.videoSourceList = [
|
|
|
|
{
|
|
|
|
url: 'https://invidious.snopyta.org/api/manifest/dash/id/EEIk7gwjgIM',
|
|
|
|
type: 'application/dash+xml',
|
|
|
|
label: 'Dash',
|
|
|
|
qualityLabel: 'Auto'
|
|
|
|
},
|
|
|
|
]
|
|
|
|
} else {
|
|
|
|
this.videoSourceList = result.player_response.streamingData.formats
|
|
|
|
}
|
2020-02-28 03:29:30 +00:00
|
|
|
|
|
|
|
// The response provides a storyboard, however it returns a 403 error.
|
|
|
|
// Uncomment this line if that ever changes.
|
|
|
|
// this.videoStoryboardSrc = result.player_response.storyboards.playerStoryboardSpecRenderer.spec
|
|
|
|
|
|
|
|
this.captionSourceList =
|
|
|
|
result.player_response.captions &&
|
|
|
|
result.player_response.captions.playerCaptionsTracklistRenderer
|
|
|
|
.captionTracks
|
|
|
|
|
|
|
|
if (typeof this.captionSourceList !== 'undefined') {
|
|
|
|
this.captionSourceList = this.captionSourceList.map(caption => {
|
|
|
|
caption.type = 'text/vtt'
|
|
|
|
caption.charset = 'charset=utf-8'
|
|
|
|
caption.dataSource = 'local'
|
|
|
|
|
|
|
|
$.get(caption.baseUrl, response => {
|
|
|
|
xml2vtt
|
|
|
|
.Parse(new XMLSerializer().serializeToString(response))
|
|
|
|
.then(vtt => {
|
|
|
|
caption.baseUrl = `data:${caption.type};${caption.charset},${vtt}`
|
|
|
|
})
|
|
|
|
.catch(err =>
|
|
|
|
console.log(`Error while converting XML to VTT : ${err}`)
|
|
|
|
)
|
|
|
|
}).fail((xhr, textStatus, error) => {
|
|
|
|
console.log(xhr)
|
|
|
|
console.log(textStatus)
|
|
|
|
console.log(error)
|
|
|
|
})
|
|
|
|
|
|
|
|
return caption
|
|
|
|
})
|
|
|
|
}
|
2020-02-20 20:58:21 +00:00
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
this.isLoading = false
|
2020-02-28 03:29:30 +00:00
|
|
|
})
|
|
|
|
.catch(err => {
|
2020-04-18 03:17:45 +00:00
|
|
|
console.log('Error grabbing video data through local API')
|
2020-02-28 03:29:30 +00:00
|
|
|
console.log(err)
|
2020-04-18 03:17:45 +00:00
|
|
|
if (!this.usingElectron || (this.backendPreference === 'local' && this.backendFallback)) {
|
2020-02-28 03:29:30 +00:00
|
|
|
console.log(
|
|
|
|
'Error getting data with local backend, falling back to Invidious'
|
|
|
|
)
|
|
|
|
this.getVideoInformationInvidious()
|
|
|
|
} else {
|
|
|
|
this.isLoading = false
|
|
|
|
// TODO: Show toast with error message
|
|
|
|
}
|
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
},
|
|
|
|
|
2020-02-28 03:29:30 +00:00
|
|
|
getVideoInformationInvidious: function() {
|
2020-02-16 18:30:00 +00:00
|
|
|
if (this.firstLoad) {
|
|
|
|
this.isLoading = true
|
|
|
|
}
|
|
|
|
|
2020-02-28 03:29:30 +00:00
|
|
|
this.$store
|
|
|
|
.dispatch('invidiousGetVideoInformation', this.videoId)
|
|
|
|
.then(result => {
|
|
|
|
console.log(result)
|
|
|
|
|
|
|
|
this.videoTitle = result.title
|
|
|
|
this.videoViewCount = result.viewCount
|
|
|
|
this.videoLikeCount = result.likeCount
|
|
|
|
this.videoDislikeCount = result.dislikeCount
|
|
|
|
this.channelSubscriptionCountText = result.subCountText
|
|
|
|
this.channelId = result.authorId
|
|
|
|
this.channelName = result.author
|
|
|
|
this.channelThumbnail = result.authorThumbnails[1].url
|
|
|
|
this.videoPublished = result.published * 1000
|
|
|
|
this.videoDescriptionHtml = result.descriptionHtml
|
|
|
|
this.recommendedVideos = result.recommendedVideos
|
|
|
|
this.captionSourceList = result.captions.map(caption => {
|
|
|
|
caption.url = this.invidiousInstance + caption.url
|
|
|
|
caption.type = ''
|
|
|
|
caption.dataSource = 'invidious'
|
|
|
|
return caption
|
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2020-03-01 03:37:02 +00:00
|
|
|
if (this.forceLocalBackendForLegacy) {
|
|
|
|
this.getLegacyFormats()
|
2020-04-14 02:59:25 +00:00
|
|
|
} else {
|
|
|
|
this.videoSourceList = result.formatStreams.reverse()
|
2020-03-01 03:37:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 18:30:00 +00:00
|
|
|
this.isLoading = false
|
2020-02-28 03:29:30 +00:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
if (this.backendPreference === 'invidious' && this.backendFallback) {
|
|
|
|
console.log(
|
|
|
|
'Error getting data with Invidious, falling back to local backend'
|
|
|
|
)
|
|
|
|
this.getVideoInformationLocal()
|
|
|
|
} else {
|
|
|
|
this.isLoading = false
|
|
|
|
// TODO: Show toast with error message
|
|
|
|
}
|
|
|
|
})
|
2020-02-19 03:31:10 +00:00
|
|
|
},
|
|
|
|
|
2020-05-17 20:12:58 +00:00
|
|
|
checkIfPlaylist: function () {
|
|
|
|
if (typeof (this.$route.query) !== 'undefined') {
|
|
|
|
console.log('defined')
|
|
|
|
console.log(this.$route.query)
|
|
|
|
this.playlistId = this.$route.query.playlistId
|
|
|
|
|
|
|
|
if (typeof (this.playlistId) !== 'undefined') {
|
|
|
|
this.watchingPlaylist = true
|
|
|
|
} else {
|
|
|
|
this.watchingPlaylist = false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.watchingPlaylist = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-03-01 03:37:02 +00:00
|
|
|
getLegacyFormats: function () {
|
|
|
|
this.$store
|
|
|
|
.dispatch('ytGetVideoInformation', this.videoId)
|
|
|
|
.then(result => {
|
|
|
|
this.videoSourceList = result.player_response.streamingData.formats
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
enableDashFormat: function () {
|
2020-02-20 20:58:21 +00:00
|
|
|
if (this.activeFormat === 'dash') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-19 03:31:10 +00:00
|
|
|
this.activeFormat = 'dash'
|
|
|
|
this.hidePlayer = true
|
|
|
|
|
2020-02-28 03:29:30 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
this.hidePlayer = false
|
|
|
|
}, 100)
|
2020-02-19 03:31:10 +00:00
|
|
|
},
|
|
|
|
|
2020-05-17 20:12:58 +00:00
|
|
|
enableLegacyFormat: function () {
|
2020-02-20 20:58:21 +00:00
|
|
|
if (this.activeFormat === 'legacy') {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-19 03:31:10 +00:00
|
|
|
this.activeFormat = 'legacy'
|
|
|
|
this.hidePlayer = true
|
|
|
|
|
2020-02-20 20:58:21 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
this.hidePlayer = false
|
|
|
|
}, 100)
|
2020-02-21 18:31:32 +00:00
|
|
|
},
|
|
|
|
|
2020-05-17 20:12:58 +00:00
|
|
|
handleVideoEnded: function () {
|
|
|
|
if (this.watchingPlaylist) {
|
|
|
|
console.log('Playlist next video in 5 seconds')
|
|
|
|
setTimeout(() => {
|
|
|
|
this.$refs.watchVideoPlaylist.playNextVideo()
|
|
|
|
}, 5000)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-28 03:29:30 +00:00
|
|
|
handleVideoError: function(error) {
|
2020-02-21 18:31:32 +00:00
|
|
|
console.log(error)
|
|
|
|
if (error.code === 4) {
|
|
|
|
if (this.activeFormat === 'dash') {
|
2020-02-28 03:29:30 +00:00
|
|
|
console.log(
|
|
|
|
'Unable to play dash formats. Reverting to legacy formats...'
|
|
|
|
)
|
2020-02-21 18:31:32 +00:00
|
|
|
this.enableLegacyFormat()
|
|
|
|
} else {
|
|
|
|
this.enableDashFormat()
|
|
|
|
}
|
|
|
|
}
|
2020-02-28 03:29:30 +00:00
|
|
|
},
|
|
|
|
},
|
2020-02-16 18:30:00 +00:00
|
|
|
})
|