2022-10-10 04:31:01 -05:00
|
|
|
import { wait } from '@shared/core-utils'
|
2021-07-16 03:42:24 -05:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2022-10-10 04:31:01 -05:00
|
|
|
import { unwrapBody, unwrapBodyOrDecodeToJSON, unwrapTextOrDecode } from '../requests'
|
2021-07-09 03:21:10 -05:00
|
|
|
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
|
|
|
|
|
|
|
export class StreamingPlaylistsCommand extends AbstractCommand {
|
|
|
|
|
2022-10-10 04:31:01 -05:00
|
|
|
async get (options: OverrideCommandOptions & {
|
2021-07-09 03:21:10 -05:00
|
|
|
url: string
|
2022-12-02 07:47:21 -06:00
|
|
|
|
|
|
|
videoFileToken?: string
|
|
|
|
reinjectVideoFileToken?: boolean
|
|
|
|
|
2022-10-10 04:31:01 -05:00
|
|
|
withRetry?: boolean // default false
|
|
|
|
currentRetry?: number
|
2021-07-09 03:21:10 -05:00
|
|
|
}) {
|
2022-12-02 07:47:21 -06:00
|
|
|
const { videoFileToken, reinjectVideoFileToken, withRetry, currentRetry = 1 } = options
|
2021-07-09 03:21:10 -05:00
|
|
|
|
2022-10-10 04:31:01 -05:00
|
|
|
try {
|
|
|
|
const result = await unwrapTextOrDecode(this.getRawRequest({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
url: options.url,
|
2022-12-02 07:47:21 -06:00
|
|
|
query: {
|
|
|
|
videoFileToken,
|
|
|
|
reinjectVideoFileToken
|
|
|
|
},
|
2022-10-10 04:31:01 -05:00
|
|
|
implicitToken: false,
|
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
}))
|
|
|
|
|
|
|
|
return result
|
|
|
|
} catch (err) {
|
|
|
|
if (!withRetry || currentRetry > 5) throw err
|
|
|
|
|
|
|
|
await wait(100)
|
|
|
|
|
|
|
|
return this.get({
|
|
|
|
...options,
|
|
|
|
|
|
|
|
withRetry,
|
|
|
|
currentRetry: currentRetry + 1
|
|
|
|
})
|
|
|
|
}
|
2021-07-09 03:21:10 -05:00
|
|
|
}
|
|
|
|
|
2022-10-04 03:03:17 -05:00
|
|
|
getFragmentedSegment (options: OverrideCommandOptions & {
|
2021-07-09 03:21:10 -05:00
|
|
|
url: string
|
|
|
|
range?: string
|
|
|
|
}) {
|
2021-07-09 09:23:01 -05:00
|
|
|
return unwrapBody<Buffer>(this.getRawRequest({
|
2021-07-09 03:21:10 -05:00
|
|
|
...options,
|
|
|
|
|
|
|
|
url: options.url,
|
|
|
|
range: options.range,
|
|
|
|
implicitToken: false,
|
2021-07-09 07:15:11 -05:00
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
2021-07-09 03:21:10 -05:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
getSegmentSha256 (options: OverrideCommandOptions & {
|
|
|
|
url: string
|
|
|
|
}) {
|
2021-08-17 01:26:20 -05:00
|
|
|
return unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({
|
2021-07-09 03:21:10 -05:00
|
|
|
...options,
|
|
|
|
|
|
|
|
url: options.url,
|
|
|
|
implicitToken: false,
|
|
|
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|