diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-23 11:20:00 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-07-26 11:29:31 +0200 |
commit | 764b1a14fc494f2cfd7ea590d2f07b01df65c7ad (patch) | |
tree | 198ca5f242c63a205a05fa4cfd6d063277c541fd /shared | |
parent | 83903cb65d531a6b6b91715387493ba8312b264d (diff) | |
download | PeerTube-764b1a14fc494f2cfd7ea590d2f07b01df65c7ad.tar.gz PeerTube-764b1a14fc494f2cfd7ea590d2f07b01df65c7ad.tar.zst PeerTube-764b1a14fc494f2cfd7ea590d2f07b01df65c7ad.zip |
Use random names for VOD HLS playlists
Diffstat (limited to 'shared')
-rw-r--r-- | shared/core-utils/miscs/regexp.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/miscs/webtorrent.ts | 7 | ||||
-rw-r--r-- | shared/extra-utils/server/servers-command.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/videos/live.ts | 18 | ||||
-rw-r--r-- | shared/extra-utils/videos/streaming-playlists.ts | 5 |
5 files changed, 24 insertions, 13 deletions
diff --git a/shared/core-utils/miscs/regexp.ts b/shared/core-utils/miscs/regexp.ts index 862b8e00f..59eb87eb6 100644 --- a/shared/core-utils/miscs/regexp.ts +++ b/shared/core-utils/miscs/regexp.ts | |||
@@ -1 +1,5 @@ | |||
1 | export const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' | 1 | export const uuidRegex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' |
2 | |||
3 | export function removeFragmentedMP4Ext (path: string) { | ||
4 | return path.replace(/-fragmented.mp4$/i, '') | ||
5 | } | ||
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 @@ | |||
1 | import { readFile } from 'fs-extra' | 1 | import { readFile } from 'fs-extra' |
2 | import * as parseTorrent from 'parse-torrent' | 2 | import * as parseTorrent from 'parse-torrent' |
3 | import { join } from 'path' | 3 | import { basename, join } from 'path' |
4 | import * as WebTorrent from 'webtorrent' | 4 | import * as WebTorrent from 'webtorrent' |
5 | import { VideoFile } from '@shared/models' | ||
5 | import { PeerTubeServer } from '../server' | 6 | import { PeerTubeServer } from '../server' |
6 | 7 | ||
7 | let webtorrent: WebTorrent.Instance | 8 | let webtorrent: WebTorrent.Instance |
@@ -15,8 +16,8 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { | |||
15 | return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) | 16 | return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) |
16 | } | 17 | } |
17 | 18 | ||
18 | async function parseTorrentVideo (server: PeerTubeServer, videoUUID: string, resolution: number) { | 19 | async function parseTorrentVideo (server: PeerTubeServer, file: VideoFile) { |
19 | const torrentName = videoUUID + '-' + resolution + '.torrent' | 20 | const torrentName = basename(file.torrentUrl) |
20 | const torrentPath = server.servers.buildDirectory(join('torrents', torrentName)) | 21 | const torrentPath = server.servers.buildDirectory(join('torrents', torrentName)) |
21 | 22 | ||
22 | const data = await readFile(torrentPath) | 23 | 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 @@ | |||
1 | import { exec } from 'child_process' | 1 | import { exec } from 'child_process' |
2 | import { copy, ensureDir, readFile, remove } from 'fs-extra' | 2 | import { copy, ensureDir, readFile, remove } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { basename, join } from 'path' |
4 | import { basename } from 'path/posix' | ||
5 | import { root } from '@server/helpers/core-utils' | 4 | import { root } from '@server/helpers/core-utils' |
6 | import { HttpStatusCode } from '@shared/models' | 5 | import { HttpStatusCode } from '@shared/models' |
7 | import { getFileSize, isGithubCI, wait } from '../miscs' | 6 | 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 | |||
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) { | 79 | async function checkLiveCleanupAfterSave (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) { |
80 | const basePath = server.servers.buildDirectory('streaming-playlists') | 80 | const basePath = server.servers.buildDirectory('streaming-playlists') |
81 | const hlsPath = join(basePath, 'hls', videoUUID) | 81 | const hlsPath = join(basePath, 'hls', videoUUID) |
82 | 82 | ||
@@ -93,12 +93,18 @@ async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, reso | |||
93 | expect(files).to.have.lengthOf(resolutions.length * 2 + 2) | 93 | expect(files).to.have.lengthOf(resolutions.length * 2 + 2) |
94 | 94 | ||
95 | for (const resolution of resolutions) { | 95 | for (const resolution of resolutions) { |
96 | expect(files).to.contain(`${videoUUID}-${resolution}-fragmented.mp4`) | 96 | const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`)) |
97 | expect(files).to.contain(`${resolution}.m3u8`) | 97 | expect(fragmentedFile).to.exist |
98 | |||
99 | const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`)) | ||
100 | expect(playlistFile).to.exist | ||
98 | } | 101 | } |
99 | 102 | ||
100 | expect(files).to.contain('master.m3u8') | 103 | const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8')) |
101 | expect(files).to.contain('segments-sha256.json') | 104 | expect(masterPlaylistFile).to.exist |
105 | |||
106 | const shaFile = files.find(f => f.endsWith('-segments-sha256.json')) | ||
107 | expect(shaFile).to.exist | ||
102 | } | 108 | } |
103 | 109 | ||
104 | export { | 110 | export { |
@@ -107,5 +113,5 @@ export { | |||
107 | testFfmpegStreamError, | 113 | testFfmpegStreamError, |
108 | stopFfmpeg, | 114 | stopFfmpeg, |
109 | waitUntilLivePublishedOnAllServers, | 115 | waitUntilLivePublishedOnAllServers, |
110 | checkLiveCleanup | 116 | checkLiveCleanupAfterSave |
111 | } | 117 | } |
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 @@ | |||
1 | import { expect } from 'chai' | 1 | import { expect } from 'chai' |
2 | import { basename } from 'path' | 2 | import { basename } from 'path' |
3 | import { sha256 } from '@server/helpers/core-utils' | 3 | import { sha256 } from '@server/helpers/core-utils' |
4 | import { removeFragmentedMP4Ext } from '@shared/core-utils' | ||
4 | import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' | 5 | import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' |
5 | import { PeerTubeServer } from '../server' | 6 | import { PeerTubeServer } from '../server' |
6 | 7 | ||
@@ -15,11 +16,11 @@ async function checkSegmentHash (options: { | |||
15 | const { server, baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist } = options | 16 | const { server, baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist } = options |
16 | const command = server.streamingPlaylists | 17 | const command = server.streamingPlaylists |
17 | 18 | ||
18 | const playlist = await command.get({ url: `${baseUrlPlaylist}/${videoUUID}/${resolution}.m3u8` }) | ||
19 | |||
20 | const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) | 19 | const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) |
21 | const videoName = basename(file.fileUrl) | 20 | const videoName = basename(file.fileUrl) |
22 | 21 | ||
22 | const playlist = await command.get({ url: `${baseUrlPlaylist}/${videoUUID}/${removeFragmentedMP4Ext(videoName)}.m3u8` }) | ||
23 | |||
23 | const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) | 24 | const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) |
24 | 25 | ||
25 | const length = parseInt(matches[1], 10) | 26 | const length = parseInt(matches[1], 10) |