]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/videos/videos-command.ts
Add ability to run transcoding jobs
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / videos-command.ts
index c1a9ec806e5cdfc23682297f2d56be7fa15f9feb..7ec9c3647cbc67a419d67c5e2454014de5887771 100644 (file)
@@ -19,7 +19,7 @@ import {
   VideoFileMetadata,
   VideoPrivacy,
   VideosCommonQuery,
-  VideosWithSearchCommonQuery
+  VideoTranscodingCreate
 } from '@shared/models'
 import { buildAbsoluteFixturePath, wait } from '../miscs'
 import { unwrapBody } from '../requests'
@@ -246,7 +246,7 @@ export class VideosCommand extends AbstractCommand {
     })
   }
 
-  listByAccount (options: OverrideCommandOptions & VideosWithSearchCommonQuery & {
+  listByAccount (options: OverrideCommandOptions & VideosCommonQuery & {
     handle: string
   }) {
     const { handle, search } = options
@@ -262,7 +262,7 @@ export class VideosCommand extends AbstractCommand {
     })
   }
 
-  listByChannel (options: OverrideCommandOptions & VideosWithSearchCommonQuery & {
+  listByChannel (options: OverrideCommandOptions & VideosCommonQuery & {
     handle: string
   }) {
     const { handle } = options
@@ -470,8 +470,11 @@ export class VideosCommand extends AbstractCommand {
     attributes: VideoEdit
     size: number
     mimetype: string
+
+    originalName?: string
+    lastModified?: number
   }) {
-    const { attributes, size, mimetype } = options
+    const { attributes, originalName, lastModified, size, mimetype } = options
 
     const path = '/api/v1/videos/upload-resumable'
 
@@ -483,7 +486,14 @@ export class VideosCommand extends AbstractCommand {
         'X-Upload-Content-Type': mimetype,
         'X-Upload-Content-Length': size.toString()
       },
-      fields: { filename: attributes.fixture, ...this.buildUploadFields(options.attributes) },
+      fields: {
+        filename: attributes.fixture,
+        originalName,
+        lastModified,
+
+        ...this.buildUploadFields(options.attributes)
+      },
+
       // Fixture will be sent later
       attaches: this.buildUploadAttaches(omit(options.attributes, 'fixture')),
       implicitToken: true,
@@ -593,6 +603,54 @@ export class VideosCommand extends AbstractCommand {
 
   // ---------------------------------------------------------------------------
 
+  removeHLSFiles (options: OverrideCommandOptions & {
+    videoId: number | string
+  }) {
+    const path = '/api/v1/videos/' + options.videoId + '/hls'
+
+    return this.deleteRequest({
+      ...options,
+
+      path,
+      implicitToken: true,
+      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+  }
+
+  removeWebTorrentFiles (options: OverrideCommandOptions & {
+    videoId: number | string
+  }) {
+    const path = '/api/v1/videos/' + options.videoId + '/webtorrent'
+
+    return this.deleteRequest({
+      ...options,
+
+      path,
+      implicitToken: true,
+      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+  }
+
+  runTranscoding (options: OverrideCommandOptions & {
+    videoId: number | string
+    transcodingType: 'hls' | 'webtorrent'
+  }) {
+    const path = '/api/v1/videos/' + options.videoId + '/transcoding'
+
+    const fields: VideoTranscodingCreate = pick(options, [ 'transcodingType' ])
+
+    return this.postBodyRequest({
+      ...options,
+
+      path,
+      fields,
+      implicitToken: true,
+      defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+    })
+  }
+
+  // ---------------------------------------------------------------------------
+
   private buildListQuery (options: VideosCommonQuery) {
     return pick(options, [
       'start',
@@ -605,7 +663,8 @@ export class VideosCommand extends AbstractCommand {
       'languageOneOf',
       'tagsOneOf',
       'tagsAllOf',
-      'filter',
+      'isLocal',
+      'include',
       'skipCount'
     ])
   }