aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-streaming-playlist.ts36
-rw-r--r--server/models/video/video.ts10
2 files changed, 40 insertions, 6 deletions
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts
index 2c4dbd8ec..f587989dc 100644
--- a/server/models/video/video-streaming-playlist.ts
+++ b/server/models/video/video-streaming-playlist.ts
@@ -16,8 +16,9 @@ import {
16 UpdatedAt 16 UpdatedAt
17} from 'sequelize-typescript' 17} from 'sequelize-typescript'
18import { getHLSPublicFileUrl } from '@server/lib/object-storage' 18import { getHLSPublicFileUrl } from '@server/lib/object-storage'
19import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename } from '@server/lib/paths'
19import { VideoFileModel } from '@server/models/video/video-file' 20import { VideoFileModel } from '@server/models/video/video-file'
20import { MStreamingPlaylist, MVideo } from '@server/types/models' 21import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models'
21import { sha1 } from '@shared/extra-utils' 22import { sha1 } from '@shared/extra-utils'
22import { VideoStorage } from '@shared/models' 23import { VideoStorage } from '@shared/models'
23import { AttributesOnly } from '@shared/typescript-utils' 24import { AttributesOnly } from '@shared/typescript-utils'
@@ -167,6 +168,22 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
167 return VideoStreamingPlaylistModel.findAll(query) 168 return VideoStreamingPlaylistModel.findAll(query)
168 } 169 }
169 170
171 static loadWithVideoAndFiles (id: number) {
172 const options = {
173 include: [
174 {
175 model: VideoModel.unscoped(),
176 required: true
177 },
178 {
179 model: VideoFileModel.unscoped()
180 }
181 ]
182 }
183
184 return VideoStreamingPlaylistModel.findByPk<MStreamingPlaylistFilesVideo>(id, options)
185 }
186
170 static loadWithVideo (id: number) { 187 static loadWithVideo (id: number) {
171 const options = { 188 const options = {
172 include: [ 189 include: [
@@ -194,9 +211,22 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
194 211
195 static async loadOrGenerate (video: MVideo, transaction?: Transaction) { 212 static async loadOrGenerate (video: MVideo, transaction?: Transaction) {
196 let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id, transaction) 213 let playlist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id, transaction)
197 if (!playlist) playlist = new VideoStreamingPlaylistModel()
198 214
199 return Object.assign(playlist, { videoId: video.id, Video: video }) 215 if (!playlist) {
216 playlist = new VideoStreamingPlaylistModel({
217 p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION,
218 type: VideoStreamingPlaylistType.HLS,
219 storage: VideoStorage.FILE_SYSTEM,
220 p2pMediaLoaderInfohashes: [],
221 playlistFilename: generateHLSMasterPlaylistFilename(video.isLive),
222 segmentsSha256Filename: generateHlsSha256SegmentsFilename(video.isLive),
223 videoId: video.id
224 })
225
226 await playlist.save({ transaction })
227 }
228
229 return Object.assign(playlist, { Video: video })
200 } 230 }
201 231
202 static doesOwnedHLSPlaylistExist (videoUUID: string) { 232 static doesOwnedHLSPlaylistExist (videoUUID: string) {
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 7e9bb4db4..b8e383502 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -28,7 +28,7 @@ import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation
28import { LiveManager } from '@server/lib/live/live-manager' 28import { LiveManager } from '@server/lib/live/live-manager'
29import { removeHLSFileObjectStorage, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage' 29import { removeHLSFileObjectStorage, removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage'
30import { tracer } from '@server/lib/opentelemetry/tracing' 30import { tracer } from '@server/lib/opentelemetry/tracing'
31import { getHLSDirectory, getHLSRedundancyDirectory } from '@server/lib/paths' 31import { getHLSDirectory, getHLSRedundancyDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths'
32import { VideoPathManager } from '@server/lib/video-path-manager' 32import { VideoPathManager } from '@server/lib/video-path-manager'
33import { getServerActor } from '@server/models/application/application' 33import { getServerActor } from '@server/models/application/application'
34import { ModelCache } from '@server/models/model-cache' 34import { ModelCache } from '@server/models/model-cache'
@@ -769,7 +769,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
769 769
770 // Remove physical files and torrents 770 // Remove physical files and torrents
771 instance.VideoFiles.forEach(file => { 771 instance.VideoFiles.forEach(file => {
772 tasks.push(instance.removeWebTorrentFileAndTorrent(file)) 772 tasks.push(instance.removeWebTorrentFile(file))
773 }) 773 })
774 774
775 // Remove playlists file 775 // Remove playlists file
@@ -1783,7 +1783,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1783 .concat(toAdd) 1783 .concat(toAdd)
1784 } 1784 }
1785 1785
1786 removeWebTorrentFileAndTorrent (videoFile: MVideoFile, isRedundancy = false) { 1786 removeWebTorrentFile (videoFile: MVideoFile, isRedundancy = false) {
1787 const filePath = isRedundancy 1787 const filePath = isRedundancy
1788 ? VideoPathManager.Instance.getFSRedundancyVideoFilePath(this, videoFile) 1788 ? VideoPathManager.Instance.getFSRedundancyVideoFilePath(this, videoFile)
1789 : VideoPathManager.Instance.getFSVideoFileOutputPath(this, videoFile) 1789 : VideoPathManager.Instance.getFSVideoFileOutputPath(this, videoFile)
@@ -1829,8 +1829,12 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1829 await videoFile.removeTorrent() 1829 await videoFile.removeTorrent()
1830 await remove(filePath) 1830 await remove(filePath)
1831 1831
1832 const resolutionFilename = getHlsResolutionPlaylistFilename(videoFile.filename)
1833 await remove(VideoPathManager.Instance.getFSHLSOutputPath(this, resolutionFilename))
1834
1832 if (videoFile.storage === VideoStorage.OBJECT_STORAGE) { 1835 if (videoFile.storage === VideoStorage.OBJECT_STORAGE) {
1833 await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), videoFile.filename) 1836 await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), videoFile.filename)
1837 await removeHLSFileObjectStorage(streamingPlaylist.withVideo(this), resolutionFilename)
1834 } 1838 }
1835 } 1839 }
1836 1840