aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-streaming-playlist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-streaming-playlist.ts')
-rw-r--r--server/models/video/video-streaming-playlist.ts40
1 files changed, 33 insertions, 7 deletions
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts
index 0ea90d28c..faad4cc2d 100644
--- a/server/models/video/video-streaming-playlist.ts
+++ b/server/models/video/video-streaming-playlist.ts
@@ -5,12 +5,14 @@ import { VideoModel } from './video'
5import { VideoRedundancyModel } from '../redundancy/video-redundancy' 5import { VideoRedundancyModel } from '../redundancy/video-redundancy'
6import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 6import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
7import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 7import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
8import { CONSTRAINTS_FIELDS, P2P_MEDIA_LOADER_PEER_VERSION, STATIC_PATHS } from '../../initializers/constants' 8import { CONSTRAINTS_FIELDS, P2P_MEDIA_LOADER_PEER_VERSION, STATIC_DOWNLOAD_PATHS, STATIC_PATHS } from '../../initializers/constants'
9import { join } from 'path' 9import { join } from 'path'
10import { sha1 } from '../../helpers/core-utils' 10import { sha1 } from '../../helpers/core-utils'
11import { isArrayOf } from '../../helpers/custom-validators/misc' 11import { isArrayOf } from '../../helpers/custom-validators/misc'
12import { Op, QueryTypes } from 'sequelize' 12import { Op, QueryTypes } from 'sequelize'
13import { MStreamingPlaylist, MVideoFile } from '@server/typings/models' 13import { MStreamingPlaylist, MVideoFile } from '@server/typings/models'
14import { VideoFileModel } from '@server/models/video/video-file'
15import { getTorrentFileName, getVideoFilename } from '@server/lib/video-paths'
14 16
15@Table({ 17@Table({
16 tableName: 'videoStreamingPlaylist', 18 tableName: 'videoStreamingPlaylist',
@@ -70,6 +72,14 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
70 }) 72 })
71 Video: VideoModel 73 Video: VideoModel
72 74
75 @HasMany(() => VideoFileModel, {
76 foreignKey: {
77 allowNull: true
78 },
79 onDelete: 'CASCADE'
80 })
81 VideoFiles: VideoFileModel[]
82
73 @HasMany(() => VideoRedundancyModel, { 83 @HasMany(() => VideoRedundancyModel, {
74 foreignKey: { 84 foreignKey: {
75 allowNull: false 85 allowNull: false
@@ -91,11 +101,11 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
91 .then(results => results.length === 1) 101 .then(results => results.length === 1)
92 } 102 }
93 103
94 static buildP2PMediaLoaderInfoHashes (playlistUrl: string, videoFiles: MVideoFile[]) { 104 static buildP2PMediaLoaderInfoHashes (playlistUrl: string, files: unknown[]) {
95 const hashes: string[] = [] 105 const hashes: string[] = []
96 106
97 // https://github.com/Novage/p2p-media-loader/blob/master/p2p-media-loader-core/lib/p2p-media-manager.ts#L115 107 // https://github.com/Novage/p2p-media-loader/blob/master/p2p-media-loader-core/lib/p2p-media-manager.ts#L115
98 for (let i = 0; i < videoFiles.length; i++) { 108 for (let i = 0; i < files.length; i++) {
99 hashes.push(sha1(`${P2P_MEDIA_LOADER_PEER_VERSION}${playlistUrl}+V${i}`)) 109 hashes.push(sha1(`${P2P_MEDIA_LOADER_PEER_VERSION}${playlistUrl}+V${i}`))
100 } 110 }
101 111
@@ -139,10 +149,6 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
139 return 'segments-sha256.json' 149 return 'segments-sha256.json'
140 } 150 }
141 151
142 static getHlsVideoName (uuid: string, resolution: number) {
143 return `${uuid}-${resolution}-fragmented.mp4`
144 }
145
146 static getHlsMasterPlaylistStaticPath (videoUUID: string) { 152 static getHlsMasterPlaylistStaticPath (videoUUID: string) {
147 return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, videoUUID, VideoStreamingPlaylistModel.getMasterHlsPlaylistFilename()) 153 return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, videoUUID, VideoStreamingPlaylistModel.getMasterHlsPlaylistFilename())
148 } 154 }
@@ -165,6 +171,26 @@ export class VideoStreamingPlaylistModel extends Model<VideoStreamingPlaylistMod
165 return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getStringType() + '/' + this.Video.uuid 171 return baseUrlHttp + STATIC_PATHS.REDUNDANCY + this.getStringType() + '/' + this.Video.uuid
166 } 172 }
167 173
174 getTorrentDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) {
175 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.TORRENTS + getTorrentFileName(this, videoFile)
176 }
177
178 getVideoFileDownloadUrl (videoFile: MVideoFile, baseUrlHttp: string) {
179 return baseUrlHttp + STATIC_DOWNLOAD_PATHS.HLS_VIDEOS + getVideoFilename(this, videoFile)
180 }
181
182 getVideoFileUrl (videoFile: MVideoFile, baseUrlHttp: string) {
183 return baseUrlHttp + join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, this.Video.uuid, getVideoFilename(this, videoFile))
184 }
185
186 getTorrentUrl (videoFile: MVideoFile, baseUrlHttp: string) {
187 return baseUrlHttp + join(STATIC_PATHS.TORRENTS, getTorrentFileName(this, videoFile))
188 }
189
190 getTrackerUrls (baseUrlHttp: string, baseUrlWs: string) {
191 return [ baseUrlWs + '/tracker/socket', baseUrlHttp + '/tracker/announce' ]
192 }
193
168 hasSameUniqueKeysThan (other: MStreamingPlaylist) { 194 hasSameUniqueKeysThan (other: MStreamingPlaylist) {
169 return this.type === other.type && 195 return this.type === other.type &&
170 this.videoId === other.videoId 196 this.videoId === other.videoId