aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-file.ts41
-rw-r--r--server/models/video/video.ts21
2 files changed, 56 insertions, 6 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index 4aaee1ffa..d4f07f85f 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -405,15 +405,16 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
405 mode: 'streaming-playlist' | 'video', 405 mode: 'streaming-playlist' | 'video',
406 transaction: Transaction 406 transaction: Transaction
407 ) { 407 ) {
408 const baseWhere = { 408 const baseFind = {
409 fps: videoFile.fps, 409 fps: videoFile.fps,
410 resolution: videoFile.resolution 410 resolution: videoFile.resolution,
411 transaction
411 } 412 }
412 413
413 if (mode === 'streaming-playlist') Object.assign(baseWhere, { videoStreamingPlaylistId: videoFile.videoStreamingPlaylistId }) 414 const element = mode === 'streaming-playlist'
414 else Object.assign(baseWhere, { videoId: videoFile.videoId }) 415 ? await VideoFileModel.loadHLSFile({ ...baseFind, playlistId: videoFile.videoStreamingPlaylistId })
416 : await VideoFileModel.loadWebTorrentFile({ ...baseFind, videoId: videoFile.videoId })
415 417
416 const element = await VideoFileModel.findOne({ where: baseWhere, transaction })
417 if (!element) return videoFile.save({ transaction }) 418 if (!element) return videoFile.save({ transaction })
418 419
419 for (const k of Object.keys(videoFile.toJSON())) { 420 for (const k of Object.keys(videoFile.toJSON())) {
@@ -423,6 +424,36 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
423 return element.save({ transaction }) 424 return element.save({ transaction })
424 } 425 }
425 426
427 static async loadWebTorrentFile (options: {
428 videoId: number
429 fps: number
430 resolution: number
431 transaction?: Transaction
432 }) {
433 const where = {
434 fps: options.fps,
435 resolution: options.resolution,
436 videoId: options.videoId
437 }
438
439 return VideoFileModel.findOne({ where, transaction: options.transaction })
440 }
441
442 static async loadHLSFile (options: {
443 playlistId: number
444 fps: number
445 resolution: number
446 transaction?: Transaction
447 }) {
448 const where = {
449 fps: options.fps,
450 resolution: options.resolution,
451 videoStreamingPlaylistId: options.playlistId
452 }
453
454 return VideoFileModel.findOne({ where, transaction: options.transaction })
455 }
456
426 static removeHLSFilesOfVideoId (videoStreamingPlaylistId: number) { 457 static removeHLSFilesOfVideoId (videoStreamingPlaylistId: number) {
427 const options = { 458 const options = {
428 where: { videoStreamingPlaylistId } 459 where: { videoStreamingPlaylistId }
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 55da53058..27e605be6 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -26,7 +26,7 @@ import {
26} from 'sequelize-typescript' 26} from 'sequelize-typescript'
27import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' 27import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video'
28import { LiveManager } from '@server/lib/live/live-manager' 28import { LiveManager } from '@server/lib/live/live-manager'
29import { removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage' 29import { removeHLSFileObjectStorage, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage'
30import { getHLSDirectory, getHLSRedundancyDirectory } from '@server/lib/paths' 30import { getHLSDirectory, getHLSRedundancyDirectory } from '@server/lib/paths'
31import { VideoPathManager } from '@server/lib/video-path-manager' 31import { VideoPathManager } from '@server/lib/video-path-manager'
32import { getServerActor } from '@server/models/application/application' 32import { getServerActor } from '@server/models/application/application'
@@ -1816,6 +1816,25 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1816 } 1816 }
1817 } 1817 }
1818 1818
1819 async removeStreamingPlaylistVideoFile (streamingPlaylist: MStreamingPlaylist, videoFile: MVideoFile) {
1820 const filePath = VideoPathManager.Instance.getFSHLSOutputPath(this, videoFile.filename)
1821 await videoFile.removeTorrent()
1822 await remove(filePath)
1823
1824 if (videoFile.storage === VideoStorage.OBJECT_STORAGE) {
1825 await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), videoFile.filename)
1826 }
1827 }
1828
1829 async removeStreamingPlaylistFile (streamingPlaylist: MStreamingPlaylist, filename: string) {
1830 const filePath = VideoPathManager.Instance.getFSHLSOutputPath(this, filename)
1831 await remove(filePath)
1832
1833 if (streamingPlaylist.storage === VideoStorage.OBJECT_STORAGE) {
1834 await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), filename)
1835 }
1836 }
1837
1819 isOutdated () { 1838 isOutdated () {
1820 if (this.isOwned()) return false 1839 if (this.isOwned()) return false
1821 1840