]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/video-import/video-import.service.ts
Add ability to import video with youtube-dl
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video-import / video-import.service.ts
CommitLineData
fbad87b0
C
1import { catchError } from 'rxjs/operators'
2import { HttpClient } from '@angular/common/http'
3import { Injectable } from '@angular/core'
4import { Observable } from 'rxjs'
5import { VideoImport } from '../../../../../shared'
6import { environment } from '../../../environments/environment'
7import { RestExtractor, RestService } from '../rest'
8import { VideoImportCreate } from '../../../../../shared/models/videos/video-import-create.model'
9import { objectToFormData } from '@app/shared/misc/utils'
10import { VideoUpdate } from '../../../../../shared/models/videos'
11
12@Injectable()
13export class VideoImportService {
14 private static BASE_VIDEO_IMPORT_URL = environment.apiUrl + '/api/v1/videos/imports/'
15
16 constructor (
17 private authHttp: HttpClient,
18 private restService: RestService,
19 private restExtractor: RestExtractor
20 ) {}
21
22 importVideo (targetUrl: string, video: VideoUpdate): Observable<VideoImport> {
23 const url = VideoImportService.BASE_VIDEO_IMPORT_URL
24 const language = video.language || null
25 const licence = video.licence || null
26 const category = video.category || null
27 const description = video.description || null
28 const support = video.support || null
29 const scheduleUpdate = video.scheduleUpdate || null
30
31 const body: VideoImportCreate = {
32 targetUrl,
33
34 name: video.name,
35 category,
36 licence,
37 language,
38 support,
39 description,
40 channelId: video.channelId,
41 privacy: video.privacy,
42 tags: video.tags,
43 nsfw: video.nsfw,
44 waitTranscoding: video.waitTranscoding,
45 commentsEnabled: video.commentsEnabled,
46 thumbnailfile: video.thumbnailfile,
47 previewfile: video.previewfile,
48 scheduleUpdate
49 }
50
51 const data = objectToFormData(body)
52 return this.authHttp.post<VideoImport>(url, data)
53 .pipe(catchError(res => this.restExtractor.handleError(res)))
54 }
55
56}