]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/video.ts
Fix weblate conflicts
[github/Chocobozzz/PeerTube.git] / server / helpers / video.ts
index 4bcc6d0b9497e218dc0204aa2a80308cd622ff1f..999137c6d78c3605248cb35f145905ba2d6669a6 100644 (file)
@@ -1,5 +1,8 @@
-import { VideoModel } from '../models/video/video'
 import * as Bluebird from 'bluebird'
+import { Response } from 'express'
+import { CONFIG } from '@server/initializers/config'
+import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants'
+import { JobQueue } from '@server/lib/job-queue'
 import {
   isStreamingPlaylist,
   MStreamingPlaylistVideo,
@@ -11,12 +14,9 @@ import {
   MVideoImmutable,
   MVideoThumbnail,
   MVideoWithRights
-} from '@server/typings/models'
-import { Response } from 'express'
-import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants'
-import { JobQueue } from '@server/lib/job-queue'
-import { VideoPrivacy, VideoTranscodingPayload } from '@shared/models'
-import { CONFIG } from "@server/initializers/config"
+} from '@server/types/models'
+import { VideoPrivacy, VideoState, VideoTranscodingPayload } from '@shared/models'
+import { VideoModel } from '../models/video/video'
 
 type VideoFetchType = 'all' | 'only-video' | 'only-video-with-rights' | 'id' | 'none' | 'only-immutable-attributes'
 
@@ -104,12 +104,27 @@ function isPrivacyForFederation (privacy: VideoPrivacy) {
     (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true && castedPrivacy === VideoPrivacy.UNLISTED)
 }
 
+function isStateForFederation (state: VideoState) {
+  const castedState = parseInt(state + '', 10)
+
+  return castedState === VideoState.PUBLISHED || castedState === VideoState.WAITING_FOR_LIVE || castedState === VideoState.LIVE_ENDED
+
+}
+
 function getPrivaciesForFederation () {
   return (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true)
     ? [ { privacy: VideoPrivacy.PUBLIC }, { privacy: VideoPrivacy.UNLISTED } ]
     : [ { privacy: VideoPrivacy.PUBLIC } ]
 }
 
+function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mimeType: string) {
+  const value = mimeTypes[mimeType]
+
+  if (Array.isArray(value)) return value[0]
+
+  return value
+}
+
 export {
   VideoFetchType,
   VideoFetchByUrlType,
@@ -118,6 +133,8 @@ export {
   fetchVideoByUrl,
   addOptimizeOrMergeAudioJob,
   extractVideo,
+  getExtFromMimetype,
+  isStateForFederation,
   isPrivacyForFederation,
   getPrivaciesForFederation
 }