]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/video-transcoding.ts
Fix video views
[github/Chocobozzz/PeerTube.git] / server / lib / video-transcoding.ts
index e932c0e553b59cdf3fec846074dba0c423ba99ad..0fe0ff12a4c0aa2fb4f15caba7a547bcaaf33471 100644 (file)
@@ -1,7 +1,7 @@
-import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY } from '../initializers'
-import { extname, join } from 'path'
-import { getVideoFileFPS, getVideoFileResolution, transcode } from '../helpers/ffmpeg-utils'
-import { copy, ensureDir, move, remove, stat } from 'fs-extra'
+import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers/constants'
+import { join } from 'path'
+import { getVideoFileFPS, transcode } from '../helpers/ffmpeg-utils'
+import { ensureDir, move, remove, stat } from 'fs-extra'
 import { logger } from '../helpers/logger'
 import { VideoResolution } from '../../shared/models/videos'
 import { VideoFileModel } from '../models/video/video-file'
@@ -9,6 +9,7 @@ import { VideoModel } from '../models/video/video'
 import { updateMasterHLSPlaylist, updateSha256Segments } from './hls'
 import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
 import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type'
+import { CONFIG } from '../initializers/config'
 
 async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) {
   const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
@@ -111,61 +112,21 @@ async function generateHlsPlaylist (video: VideoModel, resolution: VideoResoluti
   await updateMasterHLSPlaylist(video)
   await updateSha256Segments(video)
 
-  const playlistUrl = CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
+  const playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
 
   await VideoStreamingPlaylistModel.upsert({
     videoId: video.id,
     playlistUrl,
-    segmentsSha256Url: CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid),
+    segmentsSha256Url: WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid),
     p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrl, video.VideoFiles),
+    p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION,
 
     type: VideoStreamingPlaylistType.HLS
   })
 }
 
-async function importVideoFile (video: VideoModel, inputFilePath: string) {
-  const { videoFileResolution } = await getVideoFileResolution(inputFilePath)
-  const { size } = await stat(inputFilePath)
-  const fps = await getVideoFileFPS(inputFilePath)
-
-  let updatedVideoFile = new VideoFileModel({
-    resolution: videoFileResolution,
-    extname: extname(inputFilePath),
-    size,
-    fps,
-    videoId: video.id
-  })
-
-  const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution)
-
-  if (currentVideoFile) {
-    // Remove old file and old torrent
-    await video.removeFile(currentVideoFile)
-    await video.removeTorrent(currentVideoFile)
-    // Remove the old video file from the array
-    video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
-
-    // Update the database
-    currentVideoFile.set('extname', updatedVideoFile.extname)
-    currentVideoFile.set('size', updatedVideoFile.size)
-    currentVideoFile.set('fps', updatedVideoFile.fps)
-
-    updatedVideoFile = currentVideoFile
-  }
-
-  const outputPath = video.getVideoFilePath(updatedVideoFile)
-  await copy(inputFilePath, outputPath)
-
-  await video.createTorrentAndSetInfoHash(updatedVideoFile)
-
-  await updatedVideoFile.save()
-
-  video.VideoFiles.push(updatedVideoFile)
-}
-
 export {
   generateHlsPlaylist,
   optimizeVideofile,
-  transcodeOriginalVideofile,
-  importVideoFile
+  transcodeOriginalVideofile
 }