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, withRetry = false, currentRetry = 1 } = options
20 const result = await unwrapTextOrDecode(this.getRawRequest({
26 reinjectVideoFileToken
29 defaultExpectedStatus: HttpStatusCode.OK_200
34 if (!withRetry || currentRetry > 5) throw err
42 currentRetry: currentRetry + 1
47 async getFragmentedSegment (options: OverrideCommandOptions & {
51 withRetry?: boolean // default false
54 const { withRetry = false, currentRetry = 1 } = options
57 const result = await unwrapBody<Buffer>(this.getRawRequest({
63 responseType: 'application/octet-stream',
64 defaultExpectedStatus: HttpStatusCode.OK_200
69 if (!withRetry || currentRetry > 5) throw err
73 return this.getFragmentedSegment({
77 currentRetry: currentRetry + 1
82 async getSegmentSha256 (options: OverrideCommandOptions & {
85 withRetry?: boolean // default false
88 const { withRetry = false, currentRetry = 1 } = options
91 const result = await unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({
95 contentType: 'application/json',
97 defaultExpectedStatus: HttpStatusCode.OK_200
102 if (!withRetry || currentRetry > 5) throw err
106 return this.getSegmentSha256({
110 currentRetry: currentRetry + 1