@remotion/media-parser 4.0.264 → 4.0.266

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/dist/buffer-iterator.d.ts +1 -0
  2. package/dist/buffer-iterator.js +17 -0
  3. package/dist/containers/aac/parse-aac.js +1 -1
  4. package/dist/containers/avc/create-sps-pps-data.js +15 -1
  5. package/dist/containers/avc/interpret-sps.js +8 -2
  6. package/dist/containers/avc/parse-avc.js +23 -24
  7. package/dist/containers/flac/get-channel-count.d.ts +1 -1
  8. package/dist/containers/flac/m3u/after-manifest-fetch.d.ts +14 -0
  9. package/dist/containers/flac/m3u/after-manifest-fetch.js +53 -0
  10. package/dist/containers/flac/m3u/fetch-m3u8-stream.d.ts +3 -0
  11. package/dist/containers/flac/m3u/fetch-m3u8-stream.js +15 -0
  12. package/dist/containers/flac/m3u/get-chunks.d.ts +6 -0
  13. package/dist/containers/flac/m3u/get-chunks.js +20 -0
  14. package/dist/containers/flac/m3u/get-duration-from-m3u.d.ts +2 -0
  15. package/dist/containers/flac/m3u/get-duration-from-m3u.js +9 -0
  16. package/dist/containers/flac/m3u/get-playlist.d.ts +3 -0
  17. package/dist/containers/flac/m3u/get-playlist.js +19 -0
  18. package/dist/containers/flac/m3u/get-streams.d.ts +13 -0
  19. package/dist/containers/flac/m3u/get-streams.js +41 -0
  20. package/dist/containers/flac/m3u/parse-directive.d.ts +2 -0
  21. package/dist/containers/flac/m3u/parse-directive.js +64 -0
  22. package/dist/containers/flac/m3u/parse-m3u-manifest.d.ts +8 -0
  23. package/dist/containers/flac/m3u/parse-m3u-manifest.js +18 -0
  24. package/dist/containers/flac/m3u/parse-m3u.d.ts +4 -0
  25. package/dist/containers/flac/m3u/parse-m3u.js +35 -0
  26. package/dist/containers/flac/m3u/parse-m3u8-text.d.ts +2 -0
  27. package/dist/containers/flac/m3u/parse-m3u8-text.js +23 -0
  28. package/dist/containers/flac/m3u/parse-stream-inf.d.ts +3 -0
  29. package/dist/containers/flac/m3u/parse-stream-inf.js +61 -0
  30. package/dist/containers/flac/m3u/return-packets.d.ts +14 -0
  31. package/dist/containers/flac/m3u/return-packets.js +63 -0
  32. package/dist/containers/flac/m3u/select-stream.d.ts +10 -0
  33. package/dist/containers/flac/m3u/select-stream.js +15 -0
  34. package/dist/containers/flac/m3u/types.d.ts +48 -0
  35. package/dist/containers/flac/m3u/types.js +2 -0
  36. package/dist/containers/flac/parse-streaminfo.js +1 -1
  37. package/dist/containers/iso-base-media/get-moov-atom.js +3 -2
  38. package/dist/containers/iso-base-media/process-box.js +9 -2
  39. package/dist/containers/iso-base-media/trun.js +1 -1
  40. package/dist/containers/m3u/after-manifest-fetch.d.ts +14 -0
  41. package/dist/containers/m3u/after-manifest-fetch.js +67 -0
  42. package/dist/containers/m3u/fetch-m3u8-stream.d.ts +3 -0
  43. package/dist/containers/m3u/fetch-m3u8-stream.js +18 -0
  44. package/dist/containers/m3u/get-chunks.d.ts +6 -0
  45. package/dist/containers/m3u/get-chunks.js +20 -0
  46. package/dist/containers/m3u/get-duration-from-m3u.d.ts +2 -0
  47. package/dist/containers/m3u/get-duration-from-m3u.js +9 -0
  48. package/dist/containers/m3u/get-playlist.d.ts +3 -0
  49. package/dist/containers/m3u/get-playlist.js +27 -0
  50. package/dist/containers/m3u/get-streams.d.ts +14 -0
  51. package/dist/containers/m3u/get-streams.js +60 -0
  52. package/dist/containers/m3u/parse-directive.d.ts +2 -0
  53. package/dist/containers/m3u/parse-directive.js +64 -0
  54. package/dist/containers/m3u/parse-m3u-manifest.d.ts +8 -0
  55. package/dist/containers/m3u/parse-m3u-manifest.js +18 -0
  56. package/dist/containers/m3u/parse-m3u.d.ts +4 -0
  57. package/dist/containers/m3u/parse-m3u.js +35 -0
  58. package/dist/containers/m3u/parse-m3u8-text.d.ts +2 -0
  59. package/dist/containers/m3u/parse-m3u8-text.js +23 -0
  60. package/dist/containers/m3u/parse-stream-inf.d.ts +3 -0
  61. package/dist/containers/m3u/parse-stream-inf.js +61 -0
  62. package/dist/containers/m3u/return-packets.d.ts +16 -0
  63. package/dist/containers/m3u/return-packets.js +71 -0
  64. package/dist/containers/m3u/select-stream.d.ts +10 -0
  65. package/dist/containers/m3u/select-stream.js +19 -0
  66. package/dist/containers/m3u/types.d.ts +48 -0
  67. package/dist/containers/m3u/types.js +2 -0
  68. package/dist/containers/mp3/parse-mpeg-header.js +1 -1
  69. package/dist/containers/riff/expect-riff-box.js +1 -1
  70. package/dist/containers/transport-stream/boxes.d.ts +4 -1
  71. package/dist/containers/transport-stream/find-separator.d.ts +1 -2
  72. package/dist/containers/transport-stream/find-separator.js +7 -13
  73. package/dist/containers/transport-stream/handle-aac-packet.js +1 -1
  74. package/dist/containers/transport-stream/handle-avc-packet.js +1 -1
  75. package/dist/containers/transport-stream/parse-packet.js +7 -1
  76. package/dist/containers/transport-stream/parse-pat.d.ts +2 -1
  77. package/dist/containers/transport-stream/parse-pat.js +16 -1
  78. package/dist/containers/transport-stream/parse-stream-packet.js +86 -74
  79. package/dist/containers/wav/parse-fmt.js +1 -1
  80. package/dist/containers/webm/parse-ebml.js +9 -2
  81. package/dist/does-need-contentlength-contentrange.d.ts +2 -0
  82. package/dist/does-need-contentlength-contentrange.js +10 -0
  83. package/dist/download-and-parse-media.js +32 -29
  84. package/dist/emit-available-info.js +13 -1
  85. package/dist/emitter.d.ts +4 -0
  86. package/dist/emitter.js +4 -0
  87. package/dist/esm/from-fetch.mjs +65 -38
  88. package/dist/esm/from-node.mjs +2 -8
  89. package/dist/esm/from-web-file.mjs +2 -7
  90. package/dist/esm/index.mjs +1029 -289
  91. package/dist/file-types/detect-file-type.d.ts +5 -1
  92. package/dist/file-types/detect-file-type.js +5 -1
  93. package/dist/file-types/index.js +3 -0
  94. package/dist/forward-controller.d.ts +7 -0
  95. package/dist/forward-controller.js +25 -0
  96. package/dist/get-container.js +3 -0
  97. package/dist/get-duration.js +35 -2
  98. package/dist/get-fields-from-callbacks.js +1 -0
  99. package/dist/get-fps.js +7 -0
  100. package/dist/get-tracks.d.ts +2 -0
  101. package/dist/get-tracks.js +29 -4
  102. package/dist/has-all-info.js +4 -0
  103. package/dist/index.d.ts +46 -9
  104. package/dist/index.js +3 -1
  105. package/dist/init-video.js +8 -0
  106. package/dist/internal-parse-media.js +11 -4
  107. package/dist/is-audio-structure.js +3 -0
  108. package/dist/media-parser-controller.js +3 -1
  109. package/dist/metadata/get-metadata.js +26 -3
  110. package/dist/options.d.ts +9 -1
  111. package/dist/parse-media.js +11 -8
  112. package/dist/parse-result.d.ts +2 -1
  113. package/dist/readers/fetch/get-body-and-reader.d.ts +8 -0
  114. package/dist/readers/fetch/get-body-and-reader.js +41 -0
  115. package/dist/readers/fetch/resolve-url.d.ts +1 -0
  116. package/dist/readers/fetch/resolve-url.js +15 -0
  117. package/dist/readers/from-fetch.js +19 -40
  118. package/dist/readers/from-node.js +1 -7
  119. package/dist/readers/from-uintarray.d.ts +2 -0
  120. package/dist/readers/from-uintarray.js +27 -0
  121. package/dist/readers/from-web-file.js +1 -6
  122. package/dist/readers/reader.d.ts +1 -2
  123. package/dist/register-track.d.ts +8 -3
  124. package/dist/register-track.js +30 -17
  125. package/dist/run-parse-iteration.js +6 -1
  126. package/dist/state/can-skip-tracks.js +2 -1
  127. package/dist/state/emitted-fields.js +1 -0
  128. package/dist/state/m3u-state.d.ts +29 -0
  129. package/dist/state/m3u-state.js +48 -0
  130. package/dist/state/need-samples-for-fields.js +1 -0
  131. package/dist/state/parser-state.d.ts +36 -1
  132. package/dist/state/parser-state.js +4 -1
  133. package/dist/state/structure.d.ts +1 -0
  134. package/dist/state/structure.js +7 -0
  135. package/dist/version.d.ts +1 -1
  136. package/dist/version.js +1 -1
  137. package/package.json +3 -3
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.downloadAndParseMedia = void 0;
4
+ const select_stream_1 = require("./containers/m3u/select-stream");
4
5
  const internal_parse_media_1 = require("./internal-parse-media");
5
6
  const log_1 = require("./log");
6
7
  const from_fetch_1 = require("./readers/from-fetch");
7
8
  const downloadAndParseMedia = async (options) => {
8
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
9
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
9
10
  const logLevel = (_a = options.logLevel) !== null && _a !== void 0 ? _a : 'info';
10
11
  const content = await options.writer.createContent({
11
12
  filename: 'hmm',
@@ -20,38 +21,40 @@ const downloadAndParseMedia = async (options) => {
20
21
  onAudioTrack: null,
21
22
  onContainer: (_d = options.onContainer) !== null && _d !== void 0 ? _d : null,
22
23
  onDimensions: (_e = options.onDimensions) !== null && _e !== void 0 ? _e : null,
24
+ selectM3uStream: (_f = options.selectM3uStream) !== null && _f !== void 0 ? _f : select_stream_1.defaultSelectM3uStreamFn,
23
25
  onDiscardedData: async (data) => {
24
26
  await content.write(data);
25
27
  },
26
- onDurationInSeconds: (_f = options.onDurationInSeconds) !== null && _f !== void 0 ? _f : null,
27
- onFps: (_g = options.onFps) !== null && _g !== void 0 ? _g : null,
28
- onImages: (_h = options.onImages) !== null && _h !== void 0 ? _h : null,
29
- onInternalStats: (_j = options.onInternalStats) !== null && _j !== void 0 ? _j : null,
30
- onIsHdr: (_k = options.onIsHdr) !== null && _k !== void 0 ? _k : null,
31
- onKeyframes: (_l = options.onKeyframes) !== null && _l !== void 0 ? _l : null,
32
- onLocation: (_m = options.onLocation) !== null && _m !== void 0 ? _m : null,
33
- onMetadata: (_o = options.onMetadata) !== null && _o !== void 0 ? _o : null,
34
- onMimeType: (_p = options.onMimeType) !== null && _p !== void 0 ? _p : null,
35
- onName: (_q = options.onName) !== null && _q !== void 0 ? _q : null,
36
- onNumberOfAudioChannels: (_r = options.onNumberOfAudioChannels) !== null && _r !== void 0 ? _r : null,
37
- onParseProgress: (_s = options.onParseProgress) !== null && _s !== void 0 ? _s : null,
38
- onRotation: (_t = options.onRotation) !== null && _t !== void 0 ? _t : null,
39
- onSampleRate: (_u = options.onSampleRate) !== null && _u !== void 0 ? _u : null,
40
- onSize: (_v = options.onSize) !== null && _v !== void 0 ? _v : null,
41
- onSlowAudioBitrate: (_w = options.onSlowAudioBitrate) !== null && _w !== void 0 ? _w : null,
42
- onSlowDurationInSeconds: (_x = options.onSlowDurationInSeconds) !== null && _x !== void 0 ? _x : null,
43
- onSlowFps: (_y = options.onSlowFps) !== null && _y !== void 0 ? _y : null,
44
- onSlowKeyframes: (_z = options.onSlowKeyframes) !== null && _z !== void 0 ? _z : null,
45
- onSlowNumberOfFrames: (_0 = options.onSlowNumberOfFrames) !== null && _0 !== void 0 ? _0 : null,
46
- onSlowVideoBitrate: (_1 = options.onSlowVideoBitrate) !== null && _1 !== void 0 ? _1 : null,
47
- onStructure: (_2 = options.onStructure) !== null && _2 !== void 0 ? _2 : null,
48
- onTracks: (_3 = options.onTracks) !== null && _3 !== void 0 ? _3 : null,
49
- onUnrotatedDimensions: (_4 = options.onUnrotatedDimensions) !== null && _4 !== void 0 ? _4 : null,
50
- onVideoCodec: (_5 = options.onVideoCodec) !== null && _5 !== void 0 ? _5 : null,
28
+ onDurationInSeconds: (_g = options.onDurationInSeconds) !== null && _g !== void 0 ? _g : null,
29
+ onFps: (_h = options.onFps) !== null && _h !== void 0 ? _h : null,
30
+ onImages: (_j = options.onImages) !== null && _j !== void 0 ? _j : null,
31
+ onInternalStats: (_k = options.onInternalStats) !== null && _k !== void 0 ? _k : null,
32
+ onIsHdr: (_l = options.onIsHdr) !== null && _l !== void 0 ? _l : null,
33
+ onKeyframes: (_m = options.onKeyframes) !== null && _m !== void 0 ? _m : null,
34
+ onLocation: (_o = options.onLocation) !== null && _o !== void 0 ? _o : null,
35
+ onMetadata: (_p = options.onMetadata) !== null && _p !== void 0 ? _p : null,
36
+ onMimeType: (_q = options.onMimeType) !== null && _q !== void 0 ? _q : null,
37
+ onName: (_r = options.onName) !== null && _r !== void 0 ? _r : null,
38
+ onNumberOfAudioChannels: (_s = options.onNumberOfAudioChannels) !== null && _s !== void 0 ? _s : null,
39
+ onParseProgress: (_t = options.onParseProgress) !== null && _t !== void 0 ? _t : null,
40
+ onRotation: (_u = options.onRotation) !== null && _u !== void 0 ? _u : null,
41
+ onSampleRate: (_v = options.onSampleRate) !== null && _v !== void 0 ? _v : null,
42
+ onSize: (_w = options.onSize) !== null && _w !== void 0 ? _w : null,
43
+ onSlowAudioBitrate: (_x = options.onSlowAudioBitrate) !== null && _x !== void 0 ? _x : null,
44
+ onSlowDurationInSeconds: (_y = options.onSlowDurationInSeconds) !== null && _y !== void 0 ? _y : null,
45
+ onSlowFps: (_z = options.onSlowFps) !== null && _z !== void 0 ? _z : null,
46
+ onSlowKeyframes: (_0 = options.onSlowKeyframes) !== null && _0 !== void 0 ? _0 : null,
47
+ onSlowNumberOfFrames: (_1 = options.onSlowNumberOfFrames) !== null && _1 !== void 0 ? _1 : null,
48
+ onSlowVideoBitrate: (_2 = options.onSlowVideoBitrate) !== null && _2 !== void 0 ? _2 : null,
49
+ onStructure: (_3 = options.onStructure) !== null && _3 !== void 0 ? _3 : null,
50
+ onM3uStreams: (_4 = options.onM3uStreams) !== null && _4 !== void 0 ? _4 : null,
51
+ onTracks: (_5 = options.onTracks) !== null && _5 !== void 0 ? _5 : null,
52
+ onUnrotatedDimensions: (_6 = options.onUnrotatedDimensions) !== null && _6 !== void 0 ? _6 : null,
53
+ onVideoCodec: (_7 = options.onVideoCodec) !== null && _7 !== void 0 ? _7 : null,
51
54
  onVideoTrack: null,
52
- progressIntervalInMs: (_6 = options.progressIntervalInMs) !== null && _6 !== void 0 ? _6 : null,
53
- reader: (_7 = options.reader) !== null && _7 !== void 0 ? _7 : from_fetch_1.fetchReader,
54
- controller: (_8 = options.controller) !== null && _8 !== void 0 ? _8 : undefined,
55
+ progressIntervalInMs: (_8 = options.progressIntervalInMs) !== null && _8 !== void 0 ? _8 : null,
56
+ reader: (_9 = options.reader) !== null && _9 !== void 0 ? _9 : from_fetch_1.fetchReader,
57
+ controller: (_10 = options.controller) !== null && _10 !== void 0 ? _10 : undefined,
55
58
  src: options.src,
56
59
  onError: async (err) => {
57
60
  var _a, _b;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.emitAvailableInfo = void 0;
4
+ const get_streams_1 = require("./containers/m3u/get-streams");
4
5
  const get_audio_codec_1 = require("./get-audio-codec");
5
6
  const get_container_1 = require("./get-container");
6
7
  const get_dimensions_1 = require("./get-dimensions");
@@ -15,7 +16,7 @@ const get_tracks_1 = require("./get-tracks");
15
16
  const get_video_codec_1 = require("./get-video-codec");
16
17
  const get_metadata_1 = require("./metadata/get-metadata");
17
18
  const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name, mimeType, fieldsInReturnValue, }) => {
18
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
19
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
19
20
  const keys = Object.keys(hasInfo);
20
21
  const { emittedFields } = state;
21
22
  for (const key of keys) {
@@ -339,6 +340,17 @@ const emitAvailableInfo = async ({ hasInfo, callbacks, state, returnValue, name,
339
340
  }
340
341
  continue;
341
342
  }
343
+ if (key === 'm3uStreams') {
344
+ if (!emittedFields.m3uStreams && hasInfo.m3uStreams) {
345
+ const streams = (0, get_streams_1.getM3uStreams)(state.getStructureOrNull(), typeof state.src === 'string' ? state.src : null);
346
+ await ((_5 = callbacks.onM3uStreams) === null || _5 === void 0 ? void 0 : _5.call(callbacks, streams));
347
+ if (fieldsInReturnValue.m3uStreams) {
348
+ returnValue.m3uStreams = streams;
349
+ }
350
+ emittedFields.m3uStreams = true;
351
+ }
352
+ continue;
353
+ }
342
354
  throw new Error(`Unhandled key: ${key}`);
343
355
  }
344
356
  };
package/dist/emitter.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  type MediaParserEventMap = {
2
2
  pause: undefined;
3
3
  resume: undefined;
4
+ abort: {
5
+ reason?: unknown;
6
+ };
4
7
  };
5
8
  export type MediaParserEventTypes = keyof MediaParserEventMap;
6
9
  export type CallbackListener<T extends MediaParserEventTypes> = (data: {
@@ -16,5 +19,6 @@ export declare class MediaParserEmitter {
16
19
  private dispatchEvent;
17
20
  dispatchPause: () => void;
18
21
  dispatchResume: () => void;
22
+ dispatchAbort: (reason?: unknown) => void;
19
23
  }
20
24
  export {};
package/dist/emitter.js CHANGED
@@ -6,6 +6,7 @@ class MediaParserEmitter {
6
6
  this.listeners = {
7
7
  pause: [],
8
8
  resume: [],
9
+ abort: [],
9
10
  };
10
11
  this.addEventListener = (name, callback) => {
11
12
  this.listeners[name].push(callback);
@@ -19,6 +20,9 @@ class MediaParserEmitter {
19
20
  this.dispatchResume = () => {
20
21
  this.dispatchEvent('resume', undefined);
21
22
  };
23
+ this.dispatchAbort = (reason) => {
24
+ this.dispatchEvent('abort', { reason });
25
+ };
22
26
  }
23
27
  dispatchEvent(dispatchName, context) {
24
28
  this.listeners[dispatchName].forEach((callback) => {
@@ -124,6 +124,55 @@ var hasBeenAborted = (error) => {
124
124
  return error instanceof MediaParserAbortError;
125
125
  };
126
126
 
127
+ // src/readers/fetch/get-body-and-reader.ts
128
+ var getLengthAndReader = async (endsWithM3u8, res, ownController) => {
129
+ if (endsWithM3u8) {
130
+ const text = await res.text();
131
+ const stream = new ReadableStream({
132
+ start(controller) {
133
+ controller.enqueue(new TextEncoder().encode(text));
134
+ controller.close();
135
+ }
136
+ });
137
+ return {
138
+ contentLength: text.length,
139
+ reader: {
140
+ reader: stream.getReader(),
141
+ abort() {
142
+ ownController.abort();
143
+ }
144
+ },
145
+ needsContentRange: false
146
+ };
147
+ }
148
+ const length = res.headers.get("content-length");
149
+ const contentLength = length === null ? null : parseInt(length, 10);
150
+ if (!res.body) {
151
+ throw new Error("No body");
152
+ }
153
+ const reader = res.body.getReader();
154
+ return {
155
+ reader: {
156
+ reader,
157
+ abort: () => {
158
+ ownController.abort();
159
+ }
160
+ },
161
+ contentLength,
162
+ needsContentRange: true
163
+ };
164
+ };
165
+
166
+ // src/readers/fetch/resolve-url.ts
167
+ var resolveUrl = (src) => {
168
+ try {
169
+ const resolvedUrl = typeof window !== "undefined" && typeof window.location !== "undefined" ? new URL(src, window.location.origin) : new URL(src);
170
+ return resolvedUrl;
171
+ } catch {
172
+ return src;
173
+ }
174
+ };
175
+
127
176
  // src/readers/from-fetch.ts
128
177
  function parseContentRange(input) {
129
178
  const matches = input.match(/^(\w+) ((\d+)-(\d+)|\*)\/(\d+|\*)$/);
@@ -161,19 +210,22 @@ var fetchReader = {
161
210
  if (typeof src !== "string") {
162
211
  throw new Error("src must be a string when using `fetchReader`");
163
212
  }
164
- const resolvedUrl = typeof window !== "undefined" && typeof window.location !== "undefined" ? new URL(src, window.location.origin).toString() : src;
165
- if (!resolvedUrl.startsWith("https://") && !resolvedUrl.startsWith("blob:") && !resolvedUrl.startsWith("http://")) {
166
- return Promise.reject(new Error(resolvedUrl + " is not a URL - needs to start with http:// or https:// or blob:. If you want to read a local file, pass `reader: nodeReader` to parseMedia()."));
213
+ const resolvedUrl = resolveUrl(src);
214
+ const resolvedUrlString = resolvedUrl.toString();
215
+ if (!resolvedUrlString.startsWith("https://") && !resolvedUrlString.startsWith("blob:") && !resolvedUrlString.startsWith("http://")) {
216
+ return Promise.reject(new Error(`${resolvedUrlString} is not a URL - needs to start with http:// or https:// or blob:. If you want to read a local file, pass \`reader: nodeReader\` to parseMedia().`));
167
217
  }
168
218
  const ownController = new AbortController;
169
219
  const cache = typeof navigator !== "undefined" && navigator.userAgent.includes("Cloudflare-Workers") ? undefined : "no-store";
170
220
  const actualRange = range === null ? 0 : range;
221
+ const endsWithM3u8 = (typeof resolvedUrl === "string" ? resolvedUrl : resolvedUrl.pathname).endsWith(".m3u8");
222
+ const headers = actualRange === 0 && endsWithM3u8 ? {} : typeof actualRange === "number" ? {
223
+ Range: `bytes=${actualRange}-`
224
+ } : {
225
+ Range: `bytes=${`${actualRange[0]}-${actualRange[1]}`}`
226
+ };
171
227
  const res = await fetch(resolvedUrl, {
172
- headers: typeof actualRange === "number" ? {
173
- Range: `bytes=${actualRange}-`
174
- } : {
175
- Range: `bytes=${`${actualRange[0]}-${actualRange[1]}`}`
176
- },
228
+ headers,
177
229
  signal: ownController.signal,
178
230
  cache
179
231
  });
@@ -186,49 +238,24 @@ var fetchReader = {
186
238
  if (res.status.toString().startsWith("4") || res.status.toString().startsWith("5")) {
187
239
  throw new Error(`Server returned status code ${res.status} for ${src} and range ${actualRange}`);
188
240
  }
189
- if (!res.body) {
190
- throw new Error("No body");
191
- }
192
- const length = res.headers.get("content-length");
193
- const contentLength = length === null ? null : parseInt(length, 10);
194
241
  const contentDisposition = res.headers.get("content-disposition");
195
242
  const name = contentDisposition?.match(/filename="([^"]+)"/)?.[1];
196
243
  const fallbackName = src.split("/").pop();
197
- const reader = res.body.getReader();
244
+ const { contentLength, needsContentRange, reader } = await getLengthAndReader(endsWithM3u8, res, ownController);
198
245
  if (controller) {
199
246
  controller._internals.signal.addEventListener("abort", () => {
200
- reader.cancel().catch(() => {
247
+ reader.reader.cancel().catch(() => {
201
248
  });
202
249
  }, { once: true });
203
250
  }
204
251
  return {
205
- reader: {
206
- reader,
207
- abort: () => {
208
- ownController.abort();
209
- }
210
- },
252
+ reader,
211
253
  contentLength,
212
254
  contentType: res.headers.get("content-type"),
213
255
  name: name ?? fallbackName,
214
- supportsContentRange
256
+ supportsContentRange,
257
+ needsContentRange
215
258
  };
216
- },
217
- getLength: async (src) => {
218
- if (typeof src !== "string") {
219
- throw new Error("src must be a string when using `fetchReader`");
220
- }
221
- const res = await fetch(src, {
222
- method: "HEAD"
223
- });
224
- if (!res.body) {
225
- throw new Error("No body");
226
- }
227
- const length = res.headers.get("content-length");
228
- if (!length) {
229
- throw new Error("No content-length");
230
- }
231
- return parseInt(length, 10);
232
259
  }
233
260
  };
234
261
  export {
@@ -34,15 +34,9 @@ var nodeReader = {
34
34
  contentLength: stats.size,
35
35
  contentType: null,
36
36
  name: src.split(sep).pop(),
37
- supportsContentRange: true
37
+ supportsContentRange: true,
38
+ needsContentRange: true
38
39
  });
39
- },
40
- getLength: (src) => {
41
- if (typeof src !== "string") {
42
- throw new Error("src must be a string when using `nodeReader`");
43
- }
44
- const stats = statSync(src);
45
- return Promise.resolve(stats.size);
46
40
  }
47
41
  };
48
42
  export {
@@ -33,19 +33,14 @@ var webFileReader = {
33
33
  contentLength: src.size,
34
34
  name: src.name,
35
35
  supportsContentRange: true,
36
- contentType: src.type
36
+ contentType: src.type,
37
+ needsContentRange: true
37
38
  });
38
39
  };
39
40
  reader.onerror = (error) => {
40
41
  reject(error);
41
42
  };
42
43
  });
43
- },
44
- getLength: (src) => {
45
- if (typeof src === "string") {
46
- throw new Error("`inputTypeFileReader` only supports `File` objects");
47
- }
48
- return Promise.resolve(src.size);
49
44
  }
50
45
  };
51
46
  export {