+ private checkUserRating () {
+ // Unlogged users do not have ratings
+ if (this.isUserLoggedIn() === false) return
+
+ this.videoService.getUserVideoRating(this.video.id)
+ .subscribe(
+ ratingObject => {
+ if (ratingObject) {
+ this.userRating = ratingObject.rating
+ }
+ },
+
+ err => this.notificationsService.error('Error', err.message)
+ )
+ }
+
+ private onVideoFetched (video: Video) {
+ this.video = video
+
+ let observable
+ if (this.video.isVideoNSFWForUser(this.authService.getUser())) {
+ observable = this.confirmService.confirm('This video is not safe for work. Are you sure you want to watch it?', 'NSFW')
+ } else {
+ observable = Observable.of(true)
+ }
+
+ observable.subscribe(
+ res => {
+ if (res === false) {
+ return this.router.navigate([ '/videos/list' ])
+ }
+
+ this.playerElement = this.elementRef.nativeElement.querySelector('#video-container')
+
+ const videojsOptions = {
+ controls: true,
+ autoplay: true,
+ plugins: {
+ peertube: {
+ videoFiles: this.video.files,
+ playerElement: this.playerElement,
+ autoplay: true,
+ peerTubeLink: false
+ }
+ }
+ }
+
+ const self = this
+ videojs(this.playerElement, videojsOptions, function () {
+ self.player = this
+ this.on('customError', (event, data) => {
+ self.handleError(data.err)
+ })
+
+ this.on('torrentInfo', (event, data) => {
+ self.downloadSpeed = data.downloadSpeed
+ self.numPeers = data.numPeers
+ self.uploadSpeed = data.uploadSpeed
+ })
+ })
+
+ this.setOpenGraphTags()
+ this.checkUserRating()
+ }
+ )
+ }
+
+ private updateVideoRating (oldRating: UserVideoRateType, newRating: VideoRateType) {
+ let likesToIncrement = 0
+ let dislikesToIncrement = 0
+
+ if (oldRating) {
+ if (oldRating === 'like') likesToIncrement--
+ if (oldRating === 'dislike') dislikesToIncrement--
+ }
+
+ if (newRating === 'like') likesToIncrement++
+ if (newRating === 'dislike') dislikesToIncrement++
+
+ this.video.likes += likesToIncrement
+ this.video.dislikes += dislikesToIncrement
+ }
+
+ private setOpenGraphTags () {
+ this.metaService.setTitle(this.video.name)
+
+ this.metaService.setTag('og:type', 'video')
+
+ this.metaService.setTag('og:title', this.video.name)
+ this.metaService.setTag('name', this.video.name)
+
+ this.metaService.setTag('og:description', this.video.description)
+ this.metaService.setTag('description', this.video.description)
+
+ this.metaService.setTag('og:image', this.video.previewPath)
+
+ this.metaService.setTag('og:duration', this.video.duration.toString())
+
+ this.metaService.setTag('og:site_name', 'PeerTube')
+
+ this.metaService.setTag('og:url', window.location.href)
+ this.metaService.setTag('url', window.location.href)