import { VideoFileModel } from '../models/video/video-file'
import { CONFIG } from '../initializers/config'
import { sequelizeTypescript } from '../initializers/database'
-import { MVideoWithFile } from '@server/typings/models'
+import { MVideoWithFile } from '@server/types/models'
import { getVideoFilename, getVideoFilePath } from './video-paths'
async function updateStreamingPlaylistsInfohashesIfNeeded () {
let line = `#EXT-X-STREAM-INF:${bandwidth},${resolution}`
if (file.fps) line += ',FRAME-RATE=' + file.fps
- const audioCodec = await getAudioStreamCodec(videoFilePath)
const videoCodec = await getVideoStreamCodec(videoFilePath)
- line += `,CODECS="${videoCodec},${audioCodec}"`
+ line += `,CODECS="${videoCodec}`
+
+ const audioCodec = await getAudioStreamCodec(videoFilePath)
+ if (audioCodec) line += `,${audioCodec}`
+
+ line += '"'
masterPlaylists.push(line)
masterPlaylists.push(VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution))
await writeFile(masterPlaylistPath, masterPlaylists.join('\n') + '\n')
}
-async function updateSha256Segments (video: MVideoWithFile) {
+async function updateSha256VODSegments (video: MVideoWithFile) {
const json: { [filename: string]: { [range: string]: string } } = {}
const playlistDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)
await outputJSON(outputPath, json)
}
-function getRangesFromPlaylist (playlistContent: string) {
- const ranges: { offset: number, length: number }[] = []
- const lines = playlistContent.split('\n')
- const regex = /^#EXT-X-BYTERANGE:(\d+)@(\d+)$/
-
- for (const line of lines) {
- const captured = regex.exec(line)
-
- if (captured) {
- ranges.push({ length: parseInt(captured[1], 10), offset: parseInt(captured[2], 10) })
- }
- }
-
- return ranges
+async function buildSha256Segment (segmentPath: string) {
+ const buf = await readFile(segmentPath)
+ return sha256(buf)
}
function downloadPlaylistSegments (playlistUrl: string, destinationDir: string, timeout: number) {
export {
updateMasterHLSPlaylist,
- updateSha256Segments,
+ updateSha256VODSegments,
+ buildSha256Segment,
downloadPlaylistSegments,
updateStreamingPlaylistsInfohashesIfNeeded
}
// ---------------------------------------------------------------------------
+
+function getRangesFromPlaylist (playlistContent: string) {
+ const ranges: { offset: number, length: number }[] = []
+ const lines = playlistContent.split('\n')
+ const regex = /^#EXT-X-BYTERANGE:(\d+)@(\d+)$/
+
+ for (const line of lines) {
+ const captured = regex.exec(line)
+
+ if (captured) {
+ ranges.push({ length: parseInt(captured[1], 10), offset: parseInt(captured[2], 10) })
+ }
+ }
+
+ return ranges
+}