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