From 50ad0a1c1699fb1799c9ba2a99bf888894f88df4 Mon Sep 17 00:00:00 2001 From: kimsible Date: Sat, 11 Apr 2020 04:24:42 +0200 Subject: Add getSubs to YoutubeDL video import --- .../video-import-url.component.ts | 64 +++++++++++++--------- 1 file changed, 39 insertions(+), 25 deletions(-) (limited to 'client') diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts index a5578bebd..a17d73683 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts +++ b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts @@ -12,6 +12,7 @@ import { FormValidatorService } from '@app/shared' 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', @@ -76,31 +77,44 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, CanCom 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 () { -- cgit v1.2.3