2020-01-03 15:01:17 +01:00
|
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { ScreenService } from '@app/core'
|
2020-11-13 14:36:30 +01:00
|
|
|
import { VideoState } from '@shared/models'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { Video } from '../shared-main'
|
2017-12-01 18:56:26 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-video-thumbnail',
|
|
|
|
styleUrls: [ './video-thumbnail.component.scss' ],
|
|
|
|
templateUrl: './video-thumbnail.component.html'
|
|
|
|
})
|
|
|
|
export class VideoThumbnailComponent {
|
|
|
|
@Input() video: Video
|
|
|
|
@Input() nsfw = false
|
2020-07-20 11:37:06 +02:00
|
|
|
|
2021-06-28 17:30:59 +02:00
|
|
|
@Input() videoRouterLink: string | any[]
|
2020-02-10 14:25:38 +01:00
|
|
|
@Input() queryParams: { [ p: string ]: any }
|
2020-07-20 11:37:06 +02:00
|
|
|
@Input() videoHref: string
|
|
|
|
@Input() videoTarget: string
|
2018-02-09 09:30:37 +01:00
|
|
|
|
2020-01-03 15:01:17 +01:00
|
|
|
@Input() displayWatchLaterPlaylist: boolean
|
|
|
|
@Input() inWatchLaterPlaylist: boolean
|
2020-01-02 13:07:18 +01:00
|
|
|
|
2020-01-03 15:01:17 +01:00
|
|
|
@Output() watchLaterClick = new EventEmitter<boolean>()
|
|
|
|
|
|
|
|
addToWatchLaterText: string
|
|
|
|
addedToWatchLaterText: string
|
2020-01-02 13:07:18 +01:00
|
|
|
|
2020-08-12 10:40:04 +02:00
|
|
|
constructor (private screenService: ScreenService) {
|
|
|
|
this.addToWatchLaterText = $localize`Add to watch later`
|
|
|
|
this.addedToWatchLaterText = $localize`Remove from watch later`
|
2019-03-13 14:18:58 +01:00
|
|
|
}
|
2018-06-15 16:52:15 +02:00
|
|
|
|
2020-11-13 14:36:30 +01:00
|
|
|
isLiveEnded () {
|
2020-12-17 13:46:52 +01:00
|
|
|
if (!this.video.state) return
|
|
|
|
|
2020-11-13 14:36:30 +01:00
|
|
|
return this.video.state.id === VideoState.LIVE_ENDED
|
|
|
|
}
|
|
|
|
|
2018-02-09 09:30:37 +01:00
|
|
|
getImageUrl () {
|
|
|
|
if (!this.video) return ''
|
|
|
|
|
2018-06-15 16:52:15 +02:00
|
|
|
if (this.screenService.isInMobileView()) {
|
2018-02-09 09:30:37 +01:00
|
|
|
return this.video.previewUrl
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.video.thumbnailUrl
|
|
|
|
}
|
2018-10-05 11:15:06 +02:00
|
|
|
|
|
|
|
getProgressPercent () {
|
|
|
|
if (!this.video.userHistory) return 0
|
|
|
|
|
|
|
|
const currentTime = this.video.userHistory.currentTime
|
|
|
|
|
|
|
|
return (currentTime / this.video.duration) * 100
|
|
|
|
}
|
2019-03-13 14:18:58 +01:00
|
|
|
|
|
|
|
getVideoRouterLink () {
|
2020-07-20 11:37:06 +02:00
|
|
|
if (this.videoRouterLink) return this.videoRouterLink
|
2019-03-13 14:18:58 +01:00
|
|
|
|
2021-06-28 17:30:59 +02:00
|
|
|
return Video.buildWatchUrl(this.video)
|
2019-03-13 14:18:58 +01:00
|
|
|
}
|
2020-01-02 13:07:18 +01:00
|
|
|
|
2020-01-03 15:01:17 +01:00
|
|
|
onWatchLaterClick (event: Event) {
|
|
|
|
this.watchLaterClick.emit(this.inWatchLaterPlaylist)
|
2020-01-02 13:07:18 +01:00
|
|
|
|
2020-01-03 15:01:17 +01:00
|
|
|
event.stopPropagation()
|
|
|
|
return false
|
2020-01-02 13:07:18 +01:00
|
|
|
}
|
2017-12-01 18:56:26 +01:00
|
|
|
}
|