aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/object-storage/videos.ts5
-rw-r--r--server/lib/transcoding/transcoding.ts28
2 files changed, 23 insertions, 10 deletions
diff --git a/server/lib/object-storage/videos.ts b/server/lib/object-storage/videos.ts
index 066b48ab0..66e738200 100644
--- a/server/lib/object-storage/videos.ts
+++ b/server/lib/object-storage/videos.ts
@@ -26,6 +26,10 @@ function removeHLSObjectStorage (playlist: MStreamingPlaylistVideo) {
26 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS) 26 return removePrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
27} 27}
28 28
29function removeHLSFileObjectStorage (playlist: MStreamingPlaylistVideo, filename: string) {
30 return removeObject(generateHLSObjectStorageKey(playlist, filename), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
31}
32
29function removeWebTorrentObjectStorage (videoFile: MVideoFile) { 33function removeWebTorrentObjectStorage (videoFile: MVideoFile) {
30 return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS) 34 return removeObject(generateWebTorrentObjectStorageKey(videoFile.filename), CONFIG.OBJECT_STORAGE.VIDEOS)
31} 35}
@@ -63,6 +67,7 @@ export {
63 storeHLSFile, 67 storeHLSFile,
64 68
65 removeHLSObjectStorage, 69 removeHLSObjectStorage,
70 removeHLSFileObjectStorage,
66 removeWebTorrentObjectStorage, 71 removeWebTorrentObjectStorage,
67 72
68 makeWebTorrentFileAvailable, 73 makeWebTorrentFileAvailable,
diff --git a/server/lib/transcoding/transcoding.ts b/server/lib/transcoding/transcoding.ts
index b64ce6e1f..69a973fbd 100644
--- a/server/lib/transcoding/transcoding.ts
+++ b/server/lib/transcoding/transcoding.ts
@@ -2,7 +2,9 @@ import { Job } from 'bull'
2import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' 2import { copyFile, ensureDir, move, remove, stat } from 'fs-extra'
3import { basename, extname as extnameUtil, join } from 'path' 3import { basename, extname as extnameUtil, join } from 'path'
4import { toEven } from '@server/helpers/core-utils' 4import { toEven } from '@server/helpers/core-utils'
5import { retryTransactionWrapper } from '@server/helpers/database-utils'
5import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 6import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
7import { sequelizeTypescript } from '@server/initializers/database'
6import { MStreamingPlaylistFilesVideo, MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' 8import { MStreamingPlaylistFilesVideo, MVideo, MVideoFile, MVideoFullLight } from '@server/types/models'
7import { VideoResolution, VideoStorage } from '../../../shared/models/videos' 9import { VideoResolution, VideoStorage } from '../../../shared/models/videos'
8import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 10import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
@@ -29,8 +31,6 @@ import {
29} from '../paths' 31} from '../paths'
30import { VideoPathManager } from '../video-path-manager' 32import { VideoPathManager } from '../video-path-manager'
31import { VideoTranscodingProfilesManager } from './default-transcoding-profiles' 33import { VideoTranscodingProfilesManager } from './default-transcoding-profiles'
32import { retryTransactionWrapper } from '@server/helpers/database-utils'
33import { sequelizeTypescript } from '@server/initializers/database'
34 34
35/** 35/**
36 * 36 *
@@ -259,6 +259,9 @@ async function onWebTorrentVideoFileTranscoding (
259 259
260 await createTorrentAndSetInfoHash(video, videoFile) 260 await createTorrentAndSetInfoHash(video, videoFile)
261 261
262 const oldFile = await VideoFileModel.loadWebTorrentFile({ videoId: video.id, fps: videoFile.fps, resolution: videoFile.resolution })
263 if (oldFile) await video.removeWebTorrentFileAndTorrent(oldFile)
264
262 await VideoFileModel.customUpsert(videoFile, 'video', undefined) 265 await VideoFileModel.customUpsert(videoFile, 'video', undefined)
263 video.VideoFiles = await video.$get('VideoFiles') 266 video.VideoFiles = await video.$get('VideoFiles')
264 267
@@ -311,17 +314,15 @@ async function generateHlsPlaylistCommon (options: {
311 await transcodeVOD(transcodeOptions) 314 await transcodeVOD(transcodeOptions)
312 315
313 // Create or update the playlist 316 // Create or update the playlist
314 const playlist = await retryTransactionWrapper(() => { 317 const { playlist, oldPlaylistFilename, oldSegmentsSha256Filename } = await retryTransactionWrapper(() => {
315 return sequelizeTypescript.transaction(async transaction => { 318 return sequelizeTypescript.transaction(async transaction => {
316 const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video, transaction) 319 const playlist = await VideoStreamingPlaylistModel.loadOrGenerate(video, transaction)
317 320
318 if (!playlist.playlistFilename) { 321 const oldPlaylistFilename = playlist.playlistFilename
319 playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive) 322 const oldSegmentsSha256Filename = playlist.segmentsSha256Filename
320 }
321 323
322 if (!playlist.segmentsSha256Filename) { 324 playlist.playlistFilename = generateHLSMasterPlaylistFilename(video.isLive)
323 playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(video.isLive) 325 playlist.segmentsSha256Filename = generateHlsSha256SegmentsFilename(video.isLive)
324 }
325 326
326 playlist.p2pMediaLoaderInfohashes = [] 327 playlist.p2pMediaLoaderInfohashes = []
327 playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION 328 playlist.p2pMediaLoaderPeerVersion = P2P_MEDIA_LOADER_PEER_VERSION
@@ -330,10 +331,13 @@ async function generateHlsPlaylistCommon (options: {
330 331
331 await playlist.save({ transaction }) 332 await playlist.save({ transaction })
332 333
333 return playlist 334 return { playlist, oldPlaylistFilename, oldSegmentsSha256Filename }
334 }) 335 })
335 }) 336 })
336 337
338 if (oldPlaylistFilename) await video.removeStreamingPlaylistFile(playlist, oldPlaylistFilename)
339 if (oldSegmentsSha256Filename) await video.removeStreamingPlaylistFile(playlist, oldSegmentsSha256Filename)
340
337 // Build the new playlist file 341 // Build the new playlist file
338 const extname = extnameUtil(videoFilename) 342 const extname = extnameUtil(videoFilename)
339 const newVideoFile = new VideoFileModel({ 343 const newVideoFile = new VideoFileModel({
@@ -364,11 +368,15 @@ async function generateHlsPlaylistCommon (options: {
364 368
365 await createTorrentAndSetInfoHash(playlist, newVideoFile) 369 await createTorrentAndSetInfoHash(playlist, newVideoFile)
366 370
371 const oldFile = await VideoFileModel.loadHLSFile({ playlistId: playlist.id, fps: newVideoFile.fps, resolution: newVideoFile.resolution })
372 if (oldFile) await video.removeStreamingPlaylistVideoFile(playlist, oldFile)
373
367 const savedVideoFile = await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined) 374 const savedVideoFile = await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined)
368 375
369 const playlistWithFiles = playlist as MStreamingPlaylistFilesVideo 376 const playlistWithFiles = playlist as MStreamingPlaylistFilesVideo
370 playlistWithFiles.VideoFiles = await playlist.$get('VideoFiles') 377 playlistWithFiles.VideoFiles = await playlist.$get('VideoFiles')
371 playlist.assignP2PMediaLoaderInfoHashes(video, playlistWithFiles.VideoFiles) 378 playlist.assignP2PMediaLoaderInfoHashes(video, playlistWithFiles.VideoFiles)
379 playlist.storage = VideoStorage.FILE_SYSTEM
372 380
373 await playlist.save() 381 await playlist.save()
374 382