aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/miscs/webtorrent.ts7
-rw-r--r--shared/extra-utils/server/servers-command.ts3
-rw-r--r--shared/extra-utils/videos/live.ts18
-rw-r--r--shared/extra-utils/videos/streaming-playlists.ts5
4 files changed, 20 insertions, 13 deletions
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 @@
1import { readFile } from 'fs-extra' 1import { readFile } from 'fs-extra'
2import * as parseTorrent from 'parse-torrent' 2import * as parseTorrent from 'parse-torrent'
3import { join } from 'path' 3import { basename, join } from 'path'
4import * as WebTorrent from 'webtorrent' 4import * as WebTorrent from 'webtorrent'
5import { VideoFile } from '@shared/models'
5import { PeerTubeServer } from '../server' 6import { PeerTubeServer } from '../server'
6 7
7let webtorrent: WebTorrent.Instance 8let 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
18async function parseTorrentVideo (server: PeerTubeServer, videoUUID: string, resolution: number) { 19async 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 @@
1import { exec } from 'child_process' 1import { exec } from 'child_process'
2import { copy, ensureDir, readFile, remove } from 'fs-extra' 2import { copy, ensureDir, readFile, remove } from 'fs-extra'
3import { join } from 'path' 3import { basename, join } from 'path'
4import { basename } from 'path/posix'
5import { root } from '@server/helpers/core-utils' 4import { root } from '@server/helpers/core-utils'
6import { HttpStatusCode } from '@shared/models' 5import { HttpStatusCode } from '@shared/models'
7import { getFileSize, isGithubCI, wait } from '../miscs' 6import { 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
79async function checkLiveCleanup (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) { 79async 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
104export { 110export {
@@ -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 @@
1import { expect } from 'chai' 1import { expect } from 'chai'
2import { basename } from 'path' 2import { basename } from 'path'
3import { sha256 } from '@server/helpers/core-utils' 3import { sha256 } from '@server/helpers/core-utils'
4import { removeFragmentedMP4Ext } from '@shared/core-utils'
4import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' 5import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models'
5import { PeerTubeServer } from '../server' 6import { 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)