aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/hls.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-21 14:55:10 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commit0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch)
tree226d3dd1565b0bb56588897af3b8530e6216e96b /server/lib/hls.ts
parent6bcb854cdea8688a32240bc5719c7d139806e00b (diff)
downloadPeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.gz
PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.zst
PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.zip
Implement remote runner jobs in server
Move ffmpeg functions to @shared
Diffstat (limited to 'server/lib/hls.ts')
-rw-r--r--server/lib/hls.ts18
1 files changed, 15 insertions, 3 deletions
diff --git a/server/lib/hls.ts b/server/lib/hls.ts
index 053b5d326..fc1d7e1b0 100644
--- a/server/lib/hls.ts
+++ b/server/lib/hls.ts
@@ -3,10 +3,11 @@ import { flatten } from 'lodash'
3import PQueue from 'p-queue' 3import PQueue from 'p-queue'
4import { basename, dirname, join } from 'path' 4import { basename, dirname, join } from 'path'
5import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models' 5import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models'
6import { uniqify } from '@shared/core-utils' 6import { uniqify, uuidRegex } from '@shared/core-utils'
7import { sha256 } from '@shared/extra-utils' 7import { sha256 } from '@shared/extra-utils'
8import { getVideoStreamDimensionsInfo } from '@shared/ffmpeg'
8import { VideoStorage } from '@shared/models' 9import { VideoStorage } from '@shared/models'
9import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamDimensionsInfo } from '../helpers/ffmpeg' 10import { getAudioStreamCodec, getVideoStreamCodec } from '../helpers/ffmpeg'
10import { logger } from '../helpers/logger' 11import { logger } from '../helpers/logger'
11import { doRequest, doRequestAndSaveToFile } from '../helpers/requests' 12import { doRequest, doRequestAndSaveToFile } from '../helpers/requests'
12import { generateRandomString } from '../helpers/utils' 13import { generateRandomString } from '../helpers/utils'
@@ -234,6 +235,16 @@ function downloadPlaylistSegments (playlistUrl: string, destinationDir: string,
234 235
235// --------------------------------------------------------------------------- 236// ---------------------------------------------------------------------------
236 237
238async function renameVideoFileInPlaylist (playlistPath: string, newVideoFilename: string) {
239 const content = await readFile(playlistPath, 'utf8')
240
241 const newContent = content.replace(new RegExp(`${uuidRegex}-\\d+-fragmented.mp4`, 'g'), newVideoFilename)
242
243 await writeFile(playlistPath, newContent, 'utf8')
244}
245
246// ---------------------------------------------------------------------------
247
237function injectQueryToPlaylistUrls (content: string, queryString: string) { 248function injectQueryToPlaylistUrls (content: string, queryString: string) {
238 return content.replace(/\.(m3u8|ts|mp4)/gm, '.$1?' + queryString) 249 return content.replace(/\.(m3u8|ts|mp4)/gm, '.$1?' + queryString)
239} 250}
@@ -247,7 +258,8 @@ export {
247 downloadPlaylistSegments, 258 downloadPlaylistSegments,
248 updateStreamingPlaylistsInfohashesIfNeeded, 259 updateStreamingPlaylistsInfohashesIfNeeded,
249 updatePlaylistAfterFileChange, 260 updatePlaylistAfterFileChange,
250 injectQueryToPlaylistUrls 261 injectQueryToPlaylistUrls,
262 renameVideoFileInPlaylist
251} 263}
252 264
253// --------------------------------------------------------------------------- 265// ---------------------------------------------------------------------------