import { VideoCaptionService } from '@app/shared/video-caption'
import { VideoImportService } from '@app/shared/video-import'
import { scrollToTop } from '@app/shared/misc/utils'
+import { switchMap, map } from 'rxjs/operators'
@Component({
selector: 'my-video-import-url',
this.loadingBar.start()
- this.videoImportService.importVideoUrl(this.targetUrl, videoUpdate).subscribe(
- res => {
- this.loadingBar.complete()
- this.firstStepDone.emit(res.video.name)
- this.isImportingVideo = false
- this.hasImportedVideo = true
-
- this.video = new VideoEdit(Object.assign(res.video, {
- commentsEnabled: videoUpdate.commentsEnabled,
- downloadEnabled: videoUpdate.downloadEnabled,
- support: null,
- thumbnailUrl: null,
- previewUrl: null
- }))
-
- this.hydrateFormFromVideo()
- },
-
- err => {
- this.loadingBar.complete()
- this.isImportingVideo = false
- this.firstStepError.emit()
- this.notifier.error(err.message)
- }
- )
+ 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 }) => {
+ this.loadingBar.complete()
+ this.firstStepDone.emit(video.name)
+ this.isImportingVideo = false
+ this.hasImportedVideo = true
+
+ this.video = new VideoEdit(Object.assign(video, {
+ commentsEnabled: videoUpdate.commentsEnabled,
+ downloadEnabled: videoUpdate.downloadEnabled,
+ support: null,
+ thumbnailUrl: null,
+ previewUrl: null
+ }))
+
+ this.videoCaptions = videoCaptions
+
+ this.hydrateFormFromVideo()
+ },
+
+ err => {
+ this.loadingBar.complete()
+ this.isImportingVideo = false
+ this.firstStepError.emit()
+ this.notifier.error(err.message)
+ }
+ )
}
updateSecondStep () {