2020-06-23 14:10:17 +02:00
|
|
|
import { map, switchMap } from 'rxjs/operators'
|
2018-08-02 15:34:09 +02:00
|
|
|
import { Component, EventEmitter, OnInit, Output } from '@angular/core'
|
|
|
|
import { Router } from '@angular/router'
|
2020-06-23 14:10:17 +02:00
|
|
|
import { AuthService, CanComponentDeactivate, Notifier, ServerService } from '@app/core'
|
|
|
|
import { getAbsoluteAPIUrl, scrollToTop } from '@app/helpers'
|
|
|
|
import { FormValidatorService } from '@app/shared/shared-forms'
|
|
|
|
import { VideoCaptionService, VideoEdit, VideoImportService, VideoService } from '@app/shared/shared-main'
|
|
|
|
import { LoadingBarService } from '@ngx-loading-bar/core'
|
|
|
|
import { VideoPrivacy, VideoUpdate } from '@shared/models'
|
2020-09-17 09:20:52 +02:00
|
|
|
import { hydrateFormFromVideo } from '../shared/video-edit-utils'
|
2020-08-12 10:40:04 +02:00
|
|
|
import { VideoSend } from './video-send'
|
2018-08-02 15:34:09 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-08-06 15:18:35 +02:00
|
|
|
selector: 'my-video-import-url',
|
|
|
|
templateUrl: './video-import-url.component.html',
|
2018-08-02 15:34:09 +02:00
|
|
|
styleUrls: [
|
2018-08-06 15:30:24 +02:00
|
|
|
'../shared/video-edit.component.scss',
|
2019-01-16 16:05:40 +01:00
|
|
|
'./video-send.scss'
|
2018-08-02 15:34:09 +02:00
|
|
|
]
|
|
|
|
})
|
2018-08-06 15:18:35 +02:00
|
|
|
export class VideoImportUrlComponent extends VideoSend implements OnInit, CanComponentDeactivate {
|
2018-08-02 15:34:09 +02:00
|
|
|
@Output() firstStepDone = new EventEmitter<string>()
|
2018-11-16 10:05:25 +01:00
|
|
|
@Output() firstStepError = new EventEmitter<void>()
|
2018-08-02 15:34:09 +02:00
|
|
|
|
|
|
|
targetUrl = ''
|
|
|
|
|
|
|
|
isImportingVideo = false
|
|
|
|
hasImportedVideo = false
|
|
|
|
isUpdatingVideo = false
|
|
|
|
|
|
|
|
video: VideoEdit
|
2018-11-16 10:05:25 +01:00
|
|
|
error: string
|
2018-08-02 15:34:09 +02:00
|
|
|
|
2018-08-07 09:54:36 +02:00
|
|
|
protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PUBLIC
|
2018-08-06 15:12:54 +02:00
|
|
|
|
2018-08-02 15:34:09 +02:00
|
|
|
constructor (
|
|
|
|
protected formValidatorService: FormValidatorService,
|
2018-08-06 15:12:54 +02:00
|
|
|
protected loadingBar: LoadingBarService,
|
2018-12-19 16:04:34 +01:00
|
|
|
protected notifier: Notifier,
|
2018-08-06 15:12:54 +02:00
|
|
|
protected authService: AuthService,
|
|
|
|
protected serverService: ServerService,
|
|
|
|
protected videoService: VideoService,
|
|
|
|
protected videoCaptionService: VideoCaptionService,
|
2018-08-02 15:34:09 +02:00
|
|
|
private router: Router,
|
2020-08-12 10:40:04 +02:00
|
|
|
private videoImportService: VideoImportService
|
|
|
|
) {
|
2018-08-02 15:34:09 +02:00
|
|
|
super()
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit () {
|
2018-08-06 15:12:54 +02:00
|
|
|
super.ngOnInit()
|
2018-08-02 15:34:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
canDeactivate () {
|
|
|
|
return { canDeactivate: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
isTargetUrlValid () {
|
|
|
|
return this.targetUrl && this.targetUrl.match(/https?:\/\//)
|
|
|
|
}
|
|
|
|
|
|
|
|
importVideo () {
|
|
|
|
this.isImportingVideo = true
|
|
|
|
|
|
|
|
const videoUpdate: VideoUpdate = {
|
|
|
|
privacy: this.firstStepPrivacyId,
|
|
|
|
waitTranscoding: false,
|
|
|
|
commentsEnabled: true,
|
2018-10-08 14:45:22 +02:00
|
|
|
downloadEnabled: true,
|
2018-08-02 15:34:09 +02:00
|
|
|
channelId: this.firstStepChannelId
|
|
|
|
}
|
|
|
|
|
2020-08-06 16:14:58 +02:00
|
|
|
this.loadingBar.useRef().start()
|
2018-08-03 11:10:31 +02:00
|
|
|
|
2020-04-11 04:24:42 +02:00
|
|
|
this.videoImportService
|
|
|
|
.importVideoUrl(this.targetUrl, videoUpdate)
|
|
|
|
.pipe(
|
|
|
|
switchMap(res => {
|
|
|
|
return this.videoCaptionService
|
|
|
|
.listCaptions(res.video.id)
|
|
|
|
.pipe(
|
|
|
|
map(result => ({ video: res.video, videoCaptions: result.data }))
|
|
|
|
)
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe(
|
|
|
|
({ video, videoCaptions }) => {
|
2020-08-06 16:14:58 +02:00
|
|
|
this.loadingBar.useRef().complete()
|
2020-04-11 04:24:42 +02:00
|
|
|
this.firstStepDone.emit(video.name)
|
|
|
|
this.isImportingVideo = false
|
|
|
|
this.hasImportedVideo = true
|
|
|
|
|
2020-04-20 10:28:38 +02:00
|
|
|
const absoluteAPIUrl = getAbsoluteAPIUrl()
|
|
|
|
|
|
|
|
const thumbnailUrl = video.thumbnailPath
|
|
|
|
? absoluteAPIUrl + video.thumbnailPath
|
|
|
|
: null
|
|
|
|
|
|
|
|
const previewUrl = video.previewPath
|
|
|
|
? absoluteAPIUrl + video.previewPath
|
|
|
|
: null
|
|
|
|
|
2020-04-11 04:24:42 +02:00
|
|
|
this.video = new VideoEdit(Object.assign(video, {
|
|
|
|
commentsEnabled: videoUpdate.commentsEnabled,
|
|
|
|
downloadEnabled: videoUpdate.downloadEnabled,
|
|
|
|
support: null,
|
2020-04-20 10:28:38 +02:00
|
|
|
thumbnailUrl,
|
|
|
|
previewUrl
|
2020-04-11 04:24:42 +02:00
|
|
|
}))
|
|
|
|
|
|
|
|
this.videoCaptions = videoCaptions
|
|
|
|
|
2020-09-17 09:20:52 +02:00
|
|
|
hydrateFormFromVideo(this.form, this.video, true)
|
2020-04-11 04:24:42 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
err => {
|
2020-08-06 16:14:58 +02:00
|
|
|
this.loadingBar.useRef().complete()
|
2020-04-11 04:24:42 +02:00
|
|
|
this.isImportingVideo = false
|
|
|
|
this.firstStepError.emit()
|
|
|
|
this.notifier.error(err.message)
|
|
|
|
}
|
|
|
|
)
|
2018-08-02 15:34:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
updateSecondStep () {
|
|
|
|
if (this.checkForm() === false) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.video.patch(this.form.value)
|
|
|
|
|
|
|
|
this.isUpdatingVideo = true
|
|
|
|
|
|
|
|
// Update the video
|
2018-08-06 15:12:54 +02:00
|
|
|
this.updateVideoAndCaptions(this.video)
|
2018-08-02 15:34:09 +02:00
|
|
|
.subscribe(
|
|
|
|
() => {
|
|
|
|
this.isUpdatingVideo = false
|
2020-08-12 10:40:04 +02:00
|
|
|
this.notifier.success($localize`Video to import updated.`)
|
2018-08-02 15:34:09 +02:00
|
|
|
|
2018-08-03 17:00:19 +02:00
|
|
|
this.router.navigate([ '/my-account', 'video-imports' ])
|
2018-08-02 15:34:09 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
err => {
|
2018-11-16 10:05:25 +01:00
|
|
|
this.error = err.message
|
|
|
|
scrollToTop()
|
2018-08-02 15:34:09 +02:00
|
|
|
console.error(err)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|