1 import { wait } from '@shared/core-utils'
2 import { HttpStatusCode } from '@shared/models'
3 import { unwrapBody, unwrapBodyOrDecodeToJSON, unwrapTextOrDecode } from '../requests'
4 import { AbstractCommand, OverrideCommandOptions } from '../shared'
6 export class StreamingPlaylistsCommand extends AbstractCommand {
8 async get (options: OverrideCommandOptions & {
11 videoFileToken?: string
12 reinjectVideoFileToken?: boolean
14 withRetry?: boolean // default false
17 const { videoFileToken, reinjectVideoFileToken, expectedStatus, withRetry = false, currentRetry = 1 } = options
20 const result = await unwrapTextOrDecode(this.getRawRequest({
26 reinjectVideoFileToken
29 defaultExpectedStatus: HttpStatusCode.OK_200
32 // master.m3u8 could be empty
33 if (!result && (!expectedStatus || expectedStatus === HttpStatusCode.OK_200)) {
34 throw new Error('Empty result')
39 if (!withRetry || currentRetry > 10) throw err
47 currentRetry: currentRetry + 1
52 async getFragmentedSegment (options: OverrideCommandOptions & {
56 withRetry?: boolean // default false
59 const { withRetry = false, currentRetry = 1 } = options
62 const result = await unwrapBody<Buffer>(this.getRawRequest({
68 responseType: 'application/octet-stream',
69 defaultExpectedStatus: HttpStatusCode.OK_200
74 if (!withRetry || currentRetry > 10) throw err
78 return this.getFragmentedSegment({
82 currentRetry: currentRetry + 1
87 async getSegmentSha256 (options: OverrideCommandOptions & {
90 withRetry?: boolean // default false
93 const { withRetry = false, currentRetry = 1 } = options
96 const result = await unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({
100 contentType: 'application/json',
101 implicitToken: false,
102 defaultExpectedStatus: HttpStatusCode.OK_200
107 if (!withRetry || currentRetry > 10) throw err
111 return this.getSegmentSha256({
115 currentRetry: currentRetry + 1