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/miscs/webtorrent.ts | 7 ++++--- shared/extra-utils/server/servers-command.ts | 3 +-- shared/extra-utils/videos/live.ts | 18 ++++++++++++------ shared/extra-utils/videos/streaming-playlists.ts | 5 +++-- 4 files changed, 20 insertions(+), 13 deletions(-) (limited to 'shared/extra-utils') diff --git a/shared/extra-utils/miscs/webtorrent.ts b/shared/extra-utils/miscs/webtorrent.ts index 815ea3d56..a1097effe 100644 --- a/shared/extra-utils/miscs/webtorrent.ts +++ b/shared/extra-utils/miscs/webtorrent.ts @@ -1,7 +1,8 @@ import { readFile } from 'fs-extra' import * as parseTorrent from 'parse-torrent' -import { join } from 'path' +import { basename, join } from 'path' import * as WebTorrent from 'webtorrent' +import { VideoFile } from '@shared/models' import { PeerTubeServer } from '../server' let webtorrent: WebTorrent.Instance @@ -15,8 +16,8 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { return new Promise(res => webtorrent.add(torrent, res)) } -async function parseTorrentVideo (server: PeerTubeServer, videoUUID: string, resolution: number) { - const torrentName = videoUUID + '-' + resolution + '.torrent' +async function parseTorrentVideo (server: PeerTubeServer, file: VideoFile) { + const torrentName = basename(file.torrentUrl) const torrentPath = server.servers.buildDirectory(join('torrents', torrentName)) const data = await readFile(torrentPath) diff --git a/shared/extra-utils/server/servers-command.ts b/shared/extra-utils/server/servers-command.ts index 441c728c1..40a11e8d7 100644 --- a/shared/extra-utils/server/servers-command.ts +++ b/shared/extra-utils/server/servers-command.ts @@ -1,7 +1,6 @@ import { exec } from 'child_process' import { copy, ensureDir, readFile, remove } from 'fs-extra' -import { join } from 'path' -import { basename } from 'path/posix' +import { basename, join } from 'path' import { root } from '@server/helpers/core-utils' import { HttpStatusCode } from '@shared/models' import { getFileSize, isGithubCI, wait } from '../miscs' 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