]>
Commit | Line | Data |
---|---|---|
34aa316f | 1 | import { wait } from '@shared/core-utils' |
c0e8b12e | 2 | import { HttpStatusCode } from '@shared/models' |
34aa316f | 3 | import { unwrapBody, unwrapBodyOrDecodeToJSON, unwrapTextOrDecode } from '../requests' |
57f879a5 C |
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
5 | ||
6 | export class StreamingPlaylistsCommand extends AbstractCommand { | |
7 | ||
34aa316f | 8 | async get (options: OverrideCommandOptions & { |
57f879a5 | 9 | url: string |
71e3e879 C |
10 | |
11 | videoFileToken?: string | |
12 | reinjectVideoFileToken?: boolean | |
13 | ||
34aa316f C |
14 | withRetry?: boolean // default false |
15 | currentRetry?: number | |
57f879a5 | 16 | }) { |
71e3e879 | 17 | const { videoFileToken, reinjectVideoFileToken, withRetry, currentRetry = 1 } = options |
57f879a5 | 18 | |
34aa316f C |
19 | try { |
20 | const result = await unwrapTextOrDecode(this.getRawRequest({ | |
21 | ...options, | |
22 | ||
23 | url: options.url, | |
71e3e879 C |
24 | query: { |
25 | videoFileToken, | |
26 | reinjectVideoFileToken | |
27 | }, | |
34aa316f C |
28 | implicitToken: false, |
29 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
30 | })) | |
31 | ||
32 | return result | |
33 | } catch (err) { | |
34 | if (!withRetry || currentRetry > 5) throw err | |
35 | ||
36 | await wait(100) | |
37 | ||
38 | return this.get({ | |
39 | ...options, | |
40 | ||
41 | withRetry, | |
42 | currentRetry: currentRetry + 1 | |
43 | }) | |
44 | } | |
57f879a5 C |
45 | } |
46 | ||
cfd57d2c | 47 | getFragmentedSegment (options: OverrideCommandOptions & { |
57f879a5 C |
48 | url: string |
49 | range?: string | |
50 | }) { | |
dd0ebb71 | 51 | return unwrapBody<Buffer>(this.getRawRequest({ |
57f879a5 C |
52 | ...options, |
53 | ||
54 | url: options.url, | |
55 | range: options.range, | |
56 | implicitToken: false, | |
12edc149 | 57 | defaultExpectedStatus: HttpStatusCode.OK_200 |
57f879a5 C |
58 | })) |
59 | } | |
60 | ||
61 | getSegmentSha256 (options: OverrideCommandOptions & { | |
62 | url: string | |
63 | }) { | |
0305db28 | 64 | return unwrapBodyOrDecodeToJSON<{ [ id: string ]: string }>(this.getRawRequest({ |
57f879a5 C |
65 | ...options, |
66 | ||
67 | url: options.url, | |
68 | implicitToken: false, | |
69 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
70 | })) | |
71 | } | |
72 | } |