]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-watch/video-watch.component.ts
Improve 4k resolution bitrate
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / video-watch.component.ts
CommitLineData
e972e046 1import { catchError } from 'rxjs/operators'
3b492bff 2import { ChangeDetectorRef, Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core'
df98563e 3import { ActivatedRoute, Router } from '@angular/router'
901637bb 4import { RedirectService } from '@app/core/routing/redirect.service'
0bd78bf3 5import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
07fa4c97 6import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component'
1f3e9fec 7import { MetaService } from '@ngx-meta/core'
f8b2c1b4 8import { Notifier, ServerService } from '@app/core'
4c72c1cd 9import { forkJoin, Observable, Subscription } from 'rxjs'
20d21199 10import { Hotkey, HotkeysService } from 'angular2-hotkeys'
72675ebe 11import { UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '../../../../../shared'
df98563e 12import { AuthService, ConfirmService } from '../../core'
a51bad1a 13import { RestExtractor, VideoBlacklistService } from '../../shared'
ff249f49 14import { VideoDetails } from '../../shared/video/video-details.model'
63c4db6d 15import { VideoService } from '../../shared/video/video.service'
4635f59d 16import { VideoShareComponent } from './modal/video-share.component'
20d21199 17import { SubscribeButtonComponent } from '@app/shared/user-subscription/subscribe-button.component'
989e526a 18import { I18n } from '@ngx-translate/i18n-polyfill'
e945b184 19import { environment } from '../../../environments/environment'
16f7022b 20import { VideoCaptionService } from '@app/shared/video-caption'
1506307f 21import { MarkdownService } from '@app/shared/renderer'
6ec0b75b 22import {
5f85f8aa 23 videojs,
5efab546 24 CustomizationOptions,
6ec0b75b
C
25 P2PMediaLoaderOptions,
26 PeertubePlayerManager,
27 PeertubePlayerManagerOptions,
597a9266 28 PlayerMode
6ec0b75b 29} from '../../../assets/player/peertube-player-manager'
e2f01c47
C
30import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
31import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
e2f01c47 32import { Video } from '@app/shared/video/video.model'
5efab546 33import { isWebRTCDisabled, timeToInt } from '../../../assets/player/utils'
72675ebe 34import { VideoWatchPlaylistComponent } from '@app/videos/+video-watch/video-watch-playlist.component'
011e1e6b 35import { getStoredTheater } from '../../../assets/player/peertube-player-local-storage'
18a6f04c 36import { PluginService } from '@app/core/plugins/plugin.service'
93cae479 37import { HooksService } from '@app/core/plugins/hooks.service'
60c2bc80 38import { PlatformLocation } from '@angular/common'
6aa54148 39import { randomInt } from '@shared/core-utils/miscs/miscs'
dc8bc31b 40
dc8bc31b
C
41@Component({
42 selector: 'my-video-watch',
ec8d8440
C
43 templateUrl: './video-watch.component.html',
44 styleUrls: [ './video-watch.component.scss' ]
dc8bc31b 45})
0629423c 46export class VideoWatchComponent implements OnInit, OnDestroy {
22b59e80
C
47 private static LOCAL_STORAGE_PRIVACY_CONCERN_KEY = 'video-watch-privacy-concern'
48
f36da21e
C
49 @ViewChild('videoWatchPlaylist', { static: true }) videoWatchPlaylist: VideoWatchPlaylistComponent
50 @ViewChild('videoShareModal', { static: false }) videoShareModal: VideoShareComponent
51 @ViewChild('videoSupportModal', { static: false }) videoSupportModal: VideoSupportComponent
52 @ViewChild('subscribeButton', { static: false }) subscribeButton: SubscribeButtonComponent
df98563e 53
2adfc7ea 54 player: any
0826c92d 55 playerElement: HTMLVideoElement
9a18a625 56 theaterEnabled = false
154898b0 57 userRating: UserVideoRateType = null
80958c78 58 descriptionLoading = false
2de96f4d 59
2f4c784a
C
60 video: VideoDetails = null
61 videoCaptions: VideoCaption[] = []
62
e2f01c47 63 playlist: VideoPlaylist = null
e2f01c47 64
2de96f4d
C
65 completeDescriptionShown = false
66 completeVideoDescription: string
67 shortVideoDescription: string
9d9597df 68 videoHTMLDescription = ''
e9189001 69 likesBarTooltipText = ''
73e09f27 70 hasAlreadyAcceptedPrivacyConcern = false
6d88de72 71 remoteServerDown = false
20d21199 72 hotkeys: Hotkey[]
df98563e 73
6aa54148 74 private nextVideoUuid = ''
f0a39880 75 private currentTime: number
df98563e 76 private paramsSub: Subscription
e2f01c47 77 private queryParamsSub: Subscription
31b6ddf8 78 private configSub: Subscription
df98563e
C
79
80 constructor (
4fd8aa32 81 private elementRef: ElementRef,
3b492bff 82 private changeDetector: ChangeDetectorRef,
0629423c 83 private route: ActivatedRoute,
92fb909c 84 private router: Router,
d3ef341a 85 private videoService: VideoService,
e2f01c47 86 private playlistService: VideoPlaylistService,
35bf0c83 87 private videoBlacklistService: VideoBlacklistService,
92fb909c 88 private confirmService: ConfirmService,
3ec343a4 89 private metaService: MetaService,
7ddd02c9 90 private authService: AuthService,
0883b324 91 private serverService: ServerService,
a51bad1a 92 private restExtractor: RestExtractor,
f8b2c1b4 93 private notifier: Notifier,
18a6f04c 94 private pluginService: PluginService,
7ae71355 95 private markdownService: MarkdownService,
901637bb 96 private zone: NgZone,
989e526a 97 private redirectService: RedirectService,
16f7022b 98 private videoCaptionService: VideoCaptionService,
e945b184 99 private i18n: I18n,
20d21199 100 private hotkeysService: HotkeysService,
93cae479 101 private hooks: HooksService,
60c2bc80 102 private location: PlatformLocation,
e945b184 103 @Inject(LOCALE_ID) private localeId: string
d3ef341a 104 ) {}
dc8bc31b 105
b2731bff
C
106 get user () {
107 return this.authService.getUser()
108 }
109
18a6f04c 110 async ngOnInit () {
31b6ddf8
C
111 this.configSub = this.serverService.configLoaded
112 .subscribe(() => {
113 if (
114 isWebRTCDisabled() ||
115 this.serverService.getConfig().tracker.enabled === false ||
116 peertubeLocalStorage.getItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY) === 'true'
117 ) {
118 this.hasAlreadyAcceptedPrivacyConcern = true
119 }
120 })
2b3b76ab 121
13fc89f4 122 this.paramsSub = this.route.params.subscribe(routeParams => {
e2f01c47
C
123 const videoId = routeParams[ 'videoId' ]
124 if (videoId) this.loadVideo(videoId)
a51bad1a 125
e2f01c47
C
126 const playlistId = routeParams[ 'playlistId' ]
127 if (playlistId) this.loadPlaylist(playlistId)
128 })
bf079b7b 129
e2f01c47
C
130 this.queryParamsSub = this.route.queryParams.subscribe(queryParams => {
131 const videoId = queryParams[ 'videoId' ]
132 if (videoId) this.loadVideo(videoId)
df98563e 133 })
20d21199 134
1c8ddbfa 135 this.initHotkeys()
011e1e6b
C
136
137 this.theaterEnabled = getStoredTheater()
18a6f04c 138
c9e3eeed 139 this.hooks.runAction('action:video-watch.init', 'video-watch')
d1992b93
C
140 }
141
df98563e 142 ngOnDestroy () {
09edde40 143 this.flushPlayer()
067e3f84 144
13fc89f4 145 // Unsubscribe subscriptions
e2f01c47
C
146 if (this.paramsSub) this.paramsSub.unsubscribe()
147 if (this.queryParamsSub) this.queryParamsSub.unsubscribe()
20d21199
RK
148
149 // Unbind hotkeys
150 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
dc8bc31b 151 }
98b01bac 152
df98563e
C
153 setLike () {
154 if (this.isUserLoggedIn() === false) return
4c72c1cd
C
155
156 // Already liked this video
157 if (this.userRating === 'like') this.setRating('none')
158 else this.setRating('like')
d38b8281
C
159 }
160
df98563e
C
161 setDislike () {
162 if (this.isUserLoggedIn() === false) return
4c72c1cd
C
163
164 // Already disliked this video
165 if (this.userRating === 'dislike') this.setRating('none')
166 else this.setRating('dislike')
d38b8281
C
167 }
168
2de96f4d 169 showMoreDescription () {
2de96f4d
C
170 if (this.completeVideoDescription === undefined) {
171 return this.loadCompleteDescription()
172 }
173
174 this.updateVideoDescription(this.completeVideoDescription)
80958c78 175 this.completeDescriptionShown = true
2de96f4d
C
176 }
177
178 showLessDescription () {
2de96f4d 179 this.updateVideoDescription(this.shortVideoDescription)
80958c78 180 this.completeDescriptionShown = false
2de96f4d
C
181 }
182
183 loadCompleteDescription () {
80958c78
C
184 this.descriptionLoading = true
185
2de96f4d 186 this.videoService.loadCompleteDescription(this.video.descriptionPath)
2186386c
C
187 .subscribe(
188 description => {
189 this.completeDescriptionShown = true
190 this.descriptionLoading = false
191
192 this.shortVideoDescription = this.video.description
193 this.completeVideoDescription = description
194
195 this.updateVideoDescription(this.completeVideoDescription)
196 },
197
198 error => {
199 this.descriptionLoading = false
f8b2c1b4 200 this.notifier.error(error.message)
2186386c
C
201 }
202 )
2de96f4d
C
203 }
204
07fa4c97 205 showSupportModal () {
689a4f69
C
206 this.pausePlayer()
207
07fa4c97
C
208 this.videoSupportModal.show()
209 }
210
df98563e 211 showShareModal () {
689a4f69
C
212 this.pausePlayer()
213
f0a39880 214 this.videoShareModal.show(this.currentTime)
99cc4f49
C
215 }
216
df98563e
C
217 isUserLoggedIn () {
218 return this.authService.isLoggedIn()
4f8c0eb0
C
219 }
220
b1fa3eba
C
221 getVideoTags () {
222 if (!this.video || Array.isArray(this.video.tags) === false) return []
223
4278710d 224 return this.video.tags
b1fa3eba
C
225 }
226
6aa54148
L
227 onRecommendations (videos: Video[]) {
228 if (videos.length > 0) {
229 // Pick a random video until the recommendations are improved
230 this.nextVideoUuid = videos[randomInt(0,videos.length - 1)].uuid
231 }
232 }
233
689a4f69
C
234 onModalOpened () {
235 this.pausePlayer()
236 }
237
3a0fb65c
C
238 onVideoRemoved () {
239 this.redirectService.redirectToHomepage()
6725d05c
C
240 }
241
73e09f27 242 acceptedPrivacyConcern () {
0bd78bf3 243 peertubeLocalStorage.setItem(VideoWatchComponent.LOCAL_STORAGE_PRIVACY_CONCERN_KEY, 'true')
73e09f27
C
244 this.hasAlreadyAcceptedPrivacyConcern = true
245 }
246
2186386c
C
247 isVideoToTranscode () {
248 return this.video && this.video.state.id === VideoState.TO_TRANSCODE
249 }
250
516df59b
C
251 isVideoToImport () {
252 return this.video && this.video.state.id === VideoState.TO_IMPORT
253 }
254
bbe0f064
C
255 hasVideoScheduledPublication () {
256 return this.video && this.video.scheduledUpdate !== undefined
257 }
258
e2f01c47
C
259 isVideoBlur (video: Video) {
260 return video.isVideoNSFWForUser(this.user, this.serverService.getConfig())
261 }
262
e2f01c47
C
263 private loadVideo (videoId: string) {
264 // Video did not change
265 if (this.video && this.video.uuid === videoId) return
266
267 if (this.player) this.player.pause()
268
93cae479
C
269 const videoObs = this.hooks.wrapObsFun(
270 this.videoService.getVideo.bind(this.videoService),
271 { videoId },
272 'video-watch',
273 'filter:api.video-watch.video.get.params',
274 'filter:api.video-watch.video.get.result'
275 )
276
e2f01c47 277 // Video did change
c8861d5d 278 forkJoin([
93cae479 279 videoObs,
e2f01c47 280 this.videoCaptionService.listCaptions(videoId)
c8861d5d 281 ])
e2f01c47
C
282 .pipe(
283 // If 401, the video is private or blacklisted so redirect to 404
284 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]))
285 )
286 .subscribe(([ video, captionsResult ]) => {
287 const queryParams = this.route.snapshot.queryParams
e2f01c47 288
4c72c1cd
C
289 const urlOptions = {
290 startTime: queryParams.start,
291 stopTime: queryParams.stop,
5efab546
C
292
293 muted: queryParams.muted,
294 loop: queryParams.loop,
4c72c1cd 295 subtitle: queryParams.subtitle,
5efab546
C
296
297 playerMode: queryParams.mode,
298 peertubeLink: false
4c72c1cd
C
299 }
300
301 this.onVideoFetched(video, captionsResult.data, urlOptions)
e2f01c47
C
302 .catch(err => this.handleError(err))
303 })
304 }
305
306 private loadPlaylist (playlistId: string) {
307 // Playlist did not change
308 if (this.playlist && this.playlist.uuid === playlistId) return
309
310 this.playlistService.getVideoPlaylist(playlistId)
311 .pipe(
312 // If 401, the video is private or blacklisted so redirect to 404
313 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 401, 403, 404 ]))
314 )
315 .subscribe(playlist => {
316 this.playlist = playlist
317
318 const videoId = this.route.snapshot.queryParams['videoId']
72675ebe 319 this.videoWatchPlaylist.loadPlaylistElements(playlist, !videoId)
e2f01c47
C
320 })
321 }
322
2de96f4d
C
323 private updateVideoDescription (description: string) {
324 this.video.description = description
325 this.setVideoDescriptionHTML()
4c72c1cd 326 .catch(err => console.error(err))
2de96f4d
C
327 }
328
41d71344
C
329 private async setVideoDescriptionHTML () {
330 this.videoHTMLDescription = await this.markdownService.textMarkdownToHTML(this.video.description)
2de96f4d
C
331 }
332
e9189001 333 private setVideoLikesBarTooltipText () {
2186386c
C
334 this.likesBarTooltipText = this.i18n('{{likesNumber}} likes / {{dislikesNumber}} dislikes', {
335 likesNumber: this.video.likes,
336 dislikesNumber: this.video.dislikes
337 })
e9189001
C
338 }
339
0c31c33d
C
340 private handleError (err: any) {
341 const errorMessage: string = typeof err === 'string' ? err : err.message
bf5685f0
C
342 if (!errorMessage) return
343
6d88de72 344 // Display a message in the video player instead of a notification
0f7fedc3 345 if (errorMessage.indexOf('from xs param') !== -1) {
6d88de72
C
346 this.flushPlayer()
347 this.remoteServerDown = true
3b492bff
C
348 this.changeDetector.detectChanges()
349
6d88de72 350 return
0c31c33d
C
351 }
352
f8b2c1b4 353 this.notifier.error(errorMessage)
0c31c33d
C
354 }
355
df98563e 356 private checkUserRating () {
d38b8281 357 // Unlogged users do not have ratings
df98563e 358 if (this.isUserLoggedIn() === false) return
d38b8281
C
359
360 this.videoService.getUserVideoRating(this.video.id)
2186386c
C
361 .subscribe(
362 ratingObject => {
363 if (ratingObject) {
364 this.userRating = ratingObject.rating
365 }
366 },
367
f8b2c1b4 368 err => this.notifier.error(err.message)
2186386c 369 )
d38b8281
C
370 }
371
597a9266
C
372 private async onVideoFetched (
373 video: VideoDetails,
374 videoCaptions: VideoCaption[],
5efab546 375 urlOptions: CustomizationOptions & { playerMode: PlayerMode }
597a9266 376 ) {
df98563e 377 this.video = video
2f4c784a 378 this.videoCaptions = videoCaptions
92fb909c 379
c448d412
C
380 // Re init attributes
381 this.descriptionLoading = false
382 this.completeDescriptionShown = false
6d88de72 383 this.remoteServerDown = false
f0a39880 384 this.currentTime = undefined
c448d412 385
72675ebe 386 this.videoWatchPlaylist.updatePlaylistIndex(video)
e2f01c47 387
5efab546 388 let startTime = timeToInt(urlOptions.startTime) || (this.video.userHistory ? this.video.userHistory.currentTime : 0)
43483d12 389 // If we are at the end of the video, reset the timer
6e46de09
C
390 if (this.video.duration - startTime <= 1) startTime = 0
391
e2f01c47 392 if (this.isVideoBlur(this.video)) {
22b59e80 393 const res = await this.confirmService.confirm(
989e526a
C
394 this.i18n('This video contains mature or explicit content. Are you sure you want to watch it?'),
395 this.i18n('Mature or explicit content')
d6e32a2e 396 )
60c2bc80 397 if (res === false) return this.location.back()
92fb909c
C
398 }
399
09edde40
C
400 // Flush old player if needed
401 this.flushPlayer()
b891f9bc 402
60c2bc80 403 // Build video element, because videojs removes it on dispose
e2f01c47 404 const playerElementWrapper = this.elementRef.nativeElement.querySelector('#videojs-wrapper')
b891f9bc
C
405 this.playerElement = document.createElement('video')
406 this.playerElement.className = 'video-js vjs-peertube-skin'
e7eb5b39 407 this.playerElement.setAttribute('playsinline', 'true')
b891f9bc
C
408 playerElementWrapper.appendChild(this.playerElement)
409
16f7022b
C
410 const playerCaptions = videoCaptions.map(c => ({
411 label: c.language.label,
412 language: c.language.id,
413 src: environment.apiUrl + c.captionPath
414 }))
415
6ec0b75b 416 const options: PeertubePlayerManagerOptions = {
2adfc7ea
C
417 common: {
418 autoplay: this.isAutoplay(),
6ec0b75b 419
2adfc7ea 420 playerElement: this.playerElement,
6ec0b75b
C
421 onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
422
2adfc7ea
C
423 videoDuration: this.video.duration,
424 enableHotkeys: true,
425 inactivityTimeout: 2500,
426 poster: this.video.previewUrl,
5efab546 427
2adfc7ea 428 startTime,
f0a39880 429 stopTime: urlOptions.stopTime,
5efab546
C
430 controls: urlOptions.controls,
431 muted: urlOptions.muted,
432 loop: urlOptions.loop,
433 subtitle: urlOptions.subtitle,
434
435 peertubeLink: urlOptions.peertubeLink,
2adfc7ea
C
436
437 theaterMode: true,
438 captions: videoCaptions.length !== 0,
2adfc7ea 439
4c72c1cd
C
440 videoViewUrl: this.video.privacy.id !== VideoPrivacy.PRIVATE
441 ? this.videoService.getVideoViewUrl(this.video.uuid)
442 : null,
2adfc7ea
C
443 embedUrl: this.video.embedUrl,
444
445 language: this.localeId,
446
2adfc7ea
C
447 userWatching: this.user && this.user.videosHistoryEnabled === true ? {
448 url: this.videoService.getUserWatchingVideoUrl(this.video.uuid),
449 authorizationHeader: this.authService.getRequestHeaderValue()
450 } : undefined,
aa8b6df4 451
2adfc7ea
C
452 serverUrl: environment.apiUrl,
453
454 videoCaptions: playerCaptions
6ec0b75b
C
455 },
456
457 webtorrent: {
458 videoFiles: this.video.files
09209296 459 }
e945b184
C
460 }
461
65659166
C
462 let mode: PlayerMode
463
464 if (urlOptions.playerMode) {
465 if (urlOptions.playerMode === 'p2p-media-loader') mode = 'p2p-media-loader'
466 else mode = 'webtorrent'
467 } else {
468 if (this.video.hasHlsPlaylist()) mode = 'p2p-media-loader'
469 else mode = 'webtorrent'
470 }
597a9266
C
471
472 if (mode === 'p2p-media-loader') {
473 const hlsPlaylist = this.video.getHlsPlaylist()
e945b184 474
09209296
C
475 const p2pMediaLoader = {
476 playlistUrl: hlsPlaylist.playlistUrl,
477 segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
478 redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
479 trackerAnnounce: this.video.trackerUrls,
5a71acd2 480 videoFiles: hlsPlaylist.files
09209296
C
481 } as P2PMediaLoaderOptions
482
483 Object.assign(options, { p2pMediaLoader })
e945b184
C
484 }
485
e945b184 486 this.zone.runOutsideAngular(async () => {
bfbd9128 487 this.player = await PeertubePlayerManager.initialize(mode, options, player => this.player = player)
d275e754 488 this.player.focus()
9a18a625 489
2adfc7ea 490 this.player.on('customError', ({ err }: { err: any }) => this.handleError(err))
f0a39880
C
491
492 this.player.on('timeupdate', () => {
493 this.currentTime = Math.floor(this.player.currentTime())
494 })
e2f01c47
C
495
496 this.player.one('ended', () => {
497 if (this.playlist) {
72675ebe 498 this.zone.run(() => this.videoWatchPlaylist.navigateToNextPlaylistVideo())
6aa54148
L
499 } else if (this.user && this.user.autoPlayNextVideo) {
500 this.zone.run(() => this.autoplayNext())
e2f01c47
C
501 }
502 })
503
504 this.player.one('stopped', () => {
505 if (this.playlist) {
72675ebe 506 this.zone.run(() => this.videoWatchPlaylist.navigateToNextPlaylistVideo())
e2f01c47
C
507 }
508 })
9a18a625
C
509
510 this.player.on('theaterChange', (_: any, enabled: boolean) => {
511 this.zone.run(() => this.theaterEnabled = enabled)
512 })
5f85f8aa
RK
513
514 this.hooks.runAction('action:video-watch.player.loaded', 'video-watch', { player: this.player })
b891f9bc 515 })
22b59e80
C
516
517 this.setVideoDescriptionHTML()
518 this.setVideoLikesBarTooltipText()
519
520 this.setOpenGraphTags()
521 this.checkUserRating()
93cae479 522
5f85f8aa 523 this.hooks.runAction('action:video-watch.video.loaded', 'video-watch', { videojs })
92fb909c
C
524 }
525
6aa54148
L
526 private autoplayNext () {
527 if (this.nextVideoUuid) {
528 this.router.navigate([ '/videos/watch', this.nextVideoUuid ])
529 }
530 }
531
5c6d985f 532 private setRating (nextRating: UserVideoRateType) {
4c72c1cd
C
533 const ratingMethods: { [id in UserVideoRateType]: (id: number) => Observable<any> } = {
534 like: this.videoService.setVideoLike,
535 dislike: this.videoService.setVideoDislike,
536 none: this.videoService.unsetVideoLike
57a49263
BB
537 }
538
4c72c1cd 539 ratingMethods[nextRating].call(this.videoService, this.video.id)
2186386c
C
540 .subscribe(
541 () => {
542 // Update the video like attribute
543 this.updateVideoRating(this.userRating, nextRating)
544 this.userRating = nextRating
545 },
546
f8b2c1b4 547 (err: { message: string }) => this.notifier.error(err.message)
2186386c 548 )
57a49263
BB
549 }
550
5c6d985f 551 private updateVideoRating (oldRating: UserVideoRateType, newRating: UserVideoRateType) {
df98563e
C
552 let likesToIncrement = 0
553 let dislikesToIncrement = 0
d38b8281
C
554
555 if (oldRating) {
df98563e
C
556 if (oldRating === 'like') likesToIncrement--
557 if (oldRating === 'dislike') dislikesToIncrement--
d38b8281
C
558 }
559
df98563e
C
560 if (newRating === 'like') likesToIncrement++
561 if (newRating === 'dislike') dislikesToIncrement++
d38b8281 562
df98563e
C
563 this.video.likes += likesToIncrement
564 this.video.dislikes += dislikesToIncrement
20b40b19 565
22b59e80 566 this.video.buildLikeAndDislikePercents()
20b40b19 567 this.setVideoLikesBarTooltipText()
d38b8281
C
568 }
569
df98563e
C
570 private setOpenGraphTags () {
571 this.metaService.setTitle(this.video.name)
758b996d 572
df98563e 573 this.metaService.setTag('og:type', 'video')
3ec343a4 574
df98563e
C
575 this.metaService.setTag('og:title', this.video.name)
576 this.metaService.setTag('name', this.video.name)
3ec343a4 577
df98563e
C
578 this.metaService.setTag('og:description', this.video.description)
579 this.metaService.setTag('description', this.video.description)
3ec343a4 580
d38309c3 581 this.metaService.setTag('og:image', this.video.previewPath)
3ec343a4 582
df98563e 583 this.metaService.setTag('og:duration', this.video.duration.toString())
3ec343a4 584
df98563e 585 this.metaService.setTag('og:site_name', 'PeerTube')
3ec343a4 586
df98563e
C
587 this.metaService.setTag('og:url', window.location.href)
588 this.metaService.setTag('url', window.location.href)
3ec343a4 589 }
1f3e9fec 590
d4c6a3b9 591 private isAutoplay () {
bf079b7b
C
592 // We'll jump to the thread id, so do not play the video
593 if (this.route.snapshot.params['threadId']) return false
594
595 // Otherwise true by default
d4c6a3b9
C
596 if (!this.user) return true
597
598 // Be sure the autoPlay is set to false
599 return this.user.autoPlayVideo !== false
600 }
09edde40
C
601
602 private flushPlayer () {
603 // Remove player if it exists
604 if (this.player) {
536598cf
C
605 try {
606 this.player.dispose()
607 this.player = undefined
608 } catch (err) {
609 console.error('Cannot dispose player.', err)
610 }
09edde40
C
611 }
612 }
1c8ddbfa
C
613
614 private initHotkeys () {
615 this.hotkeys = [
4c72c1cd 616 new Hotkey('shift+l', () => {
1c8ddbfa
C
617 this.setLike()
618 return false
619 }, undefined, this.i18n('Like the video')),
4c72c1cd
C
620
621 new Hotkey('shift+d', () => {
1c8ddbfa
C
622 this.setDislike()
623 return false
624 }, undefined, this.i18n('Dislike the video')),
4c72c1cd
C
625
626 new Hotkey('shift+s', () => {
627 this.subscribeButton.subscribed ? this.subscribeButton.unsubscribe() : this.subscribeButton.subscribe()
1c8ddbfa
C
628 return false
629 }, undefined, this.i18n('Subscribe to the account'))
630 ]
631 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
632 }
689a4f69
C
633
634 private pausePlayer () {
635 if (!this.player) return
636
637 this.player.pause()
638 }
dc8bc31b 639}