+ showMagnetUriModal (event: Event) {
+ event.preventDefault()
+ this.videoMagnetModal.show()
+ }
+
+ isUserLoggedIn () {
+ return this.authService.isLoggedIn()
+ }
+
+ canUserUpdateVideo () {
+ return this.video.isUpdatableBy(this.authService.getUser())
+ }
+
+ isVideoRemovable () {
+ return this.video.isRemovableBy(this.authService.getUser())
+ }
+
+ isVideoBlacklistable () {
+ return this.video.isBlackistableBy(this.authService.getUser())
+ }
+
+ 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.text)
+ )
+ }
+
+ 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.setOpenGraphTags()
+ this.loadVideo()
+ 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 loadTooLong () {
+ this.error = true
+ console.error('The video load seems to be abnormally long.')
+ }
+
+ 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.thumbnailPath)
+
+ 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)