From 764b1a14fc494f2cfd7ea590d2f07b01df65c7ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 23 Jul 2021 11:20:00 +0200 Subject: Use random names for VOD HLS playlists --- shared/extra-utils/videos/live.ts | 18 ++++++++++++------ shared/extra-utils/videos/streaming-playlists.ts | 5 +++-- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'shared/extra-utils/videos') diff --git a/shared/extra-utils/videos/live.ts b/shared/extra-utils/videos/live.ts index 502964b1a..94f5f5b59 100644 --- a/shared/extra-utils/videos/live.ts +++ b/shared/extra-utils/videos/live.ts @@ -76,7 +76,7 @@ async function waitUntilLivePublishedOnAllServers (servers: PeerTubeServer[], vi } } -async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) { +async function checkLiveCleanupAfterSave (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) { const basePath = server.servers.buildDirectory('streaming-playlists') const hlsPath = join(basePath, 'hls', videoUUID) @@ -93,12 +93,18 @@ async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, reso expect(files).to.have.lengthOf(resolutions.length * 2 + 2) for (const resolution of resolutions) { - expect(files).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) - expect(files).to.contain(`${resolution}.m3u8`) + const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`)) + expect(fragmentedFile).to.exist + + const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`)) + expect(playlistFile).to.exist } - expect(files).to.contain('master.m3u8') - expect(files).to.contain('segments-sha256.json') + const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8')) + expect(masterPlaylistFile).to.exist + + const shaFile = files.find(f => f.endsWith('-segments-sha256.json')) + expect(shaFile).to.exist } export { @@ -107,5 +113,5 @@ export { testFfmpegStreamError, stopFfmpeg, waitUntilLivePublishedOnAllServers, - checkLiveCleanup + checkLiveCleanupAfterSave } diff --git a/shared/extra-utils/videos/streaming-playlists.ts b/shared/extra-utils/videos/streaming-playlists.ts index db40c27be..a224b8f5f 100644 --- a/shared/extra-utils/videos/streaming-playlists.ts +++ b/shared/extra-utils/videos/streaming-playlists.ts @@ -1,6 +1,7 @@ import { expect } from 'chai' import { basename } from 'path' import { sha256 } from '@server/helpers/core-utils' +import { removeFragmentedMP4Ext } from '@shared/core-utils' import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' import { PeerTubeServer } from '../server' @@ -15,11 +16,11 @@ async function checkSegmentHash (options: { const { server, baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist } = options const command = server.streamingPlaylists - const playlist = await command.get({ url: `${baseUrlPlaylist}/${videoUUID}/${resolution}.m3u8` }) - const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) const videoName = basename(file.fileUrl) + const playlist = await command.get({ url: `${baseUrlPlaylist}/${videoUUID}/${removeFragmentedMP4Ext(videoName)}.m3u8` }) + const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) const length = parseInt(matches[1], 10) -- cgit v1.2.3