]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/videos/streaming-playlists.ts
chore(refactor): remove shared folder dependencies to the server
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / streaming-playlists.ts
index e8fd2f232d5da1670f93f6319f9c5c5b5b622f69..0451c0efefb7b370fdd69d5165aaf85849df6c8e 100644 (file)
@@ -1,23 +1,24 @@
 import { expect } from 'chai'
-import { sha256 } from '@server/helpers/core-utils'
-import { HttpStatusCode } from '@shared/core-utils'
-import { VideoStreamingPlaylist } from '@shared/models'
-import { ServerInfo } from '../server'
+import { basename } from 'path'
+import { sha256 } from '@shared/core-utils/crypto'
+import { removeFragmentedMP4Ext } from '@shared/core-utils'
+import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models'
+import { PeerTubeServer } from '../server'
 
 async function checkSegmentHash (options: {
-  server: ServerInfo
+  server: PeerTubeServer
   baseUrlPlaylist: string
   baseUrlSegment: string
-  videoUUID: string
   resolution: number
   hlsPlaylist: VideoStreamingPlaylist
 }) {
-  const { server, baseUrlPlaylist, baseUrlSegment, videoUUID, resolution, hlsPlaylist } = options
+  const { server, baseUrlPlaylist, baseUrlSegment, 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 videoName = `${videoUUID}-${resolution}-fragmented.mp4`
+  const playlist = await command.get({ url: `${baseUrlPlaylist}/${removeFragmentedMP4Ext(videoName)}.m3u8` })
 
   const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist)
 
@@ -26,7 +27,7 @@ async function checkSegmentHash (options: {
   const range = `${offset}-${offset + length - 1}`
 
   const segmentBody = await command.getSegment({
-    url: `${baseUrlSegment}/${videoUUID}/${videoName}`,
+    url: `${baseUrlSegment}/${videoName}`,
     expectedStatus: HttpStatusCode.PARTIAL_CONTENT_206,
     range: `bytes=${range}`
   })
@@ -36,7 +37,7 @@ async function checkSegmentHash (options: {
 }
 
 async function checkLiveSegmentHash (options: {
-  server: ServerInfo
+  server: PeerTubeServer
   baseUrlSegment: string
   videoUUID: string
   segmentName: string
@@ -52,7 +53,7 @@ async function checkLiveSegmentHash (options: {
 }
 
 async function checkResolutionsInMasterPlaylist (options: {
-  server: ServerInfo
+  server: PeerTubeServer
   playlistUrl: string
   resolutions: number[]
 }) {