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