UNPKG

m3u8parse

Version:

Structural parsing of Apple HTTP Live Streaming .m3u8 format

50 lines (49 loc) 3.07 kB
import type * as AttrT from './attr-types.js'; import type { TAnyAttr, AttrType, ImmutableAttrList } from './attrlist.js'; import type { ImmutableMediaSegment, MediaSegment } from './media-segment.js'; import { AttrList } from './attrlist.js'; import type { Proto } from './types.js'; export type UriMapFunction<T extends string = string> = (uri: string | undefined, type: T, data: unknown) => string | undefined | void; export type ImmutableUriMapFunction<T extends string = string> = (uri: string | undefined, type: T, data: unknown) => undefined | void; type ImmutableMap<K, V> = Omit<Map<K, V>, 'clear' | 'set' | 'delete'>; export type Immutify<T> = T extends Function ? T : T extends AttrList<infer U> ? ImmutableAttrList<U> : T extends Map<string, AttrList<infer U>[]> ? ImmutableMap<string, AttrList<U>[]> : T extends MediaSegment ? ImmutableMediaSegment : T extends object ? { readonly [P in keyof T]: Immutify<T[P]>; } : T; export declare const cloneAttrArray: <T extends TAnyAttr>(src?: readonly ImmutableAttrList<T>[]) => AttrList<T>[]; export declare const cloneAttrMap: <T extends TAnyAttr>(src?: Iterable<[string, readonly ImmutableAttrList<T>[]]> | { [key: string]: readonly ImmutableAttrList<T>[]; }) => Map<string, AttrList<T>[]>; export declare const isStringish: (val: unknown) => val is string; type AnyAttrWithUri = TAnyAttr & { uri: AttrType.String; }; export declare const rewriteAttr: (mapFn: UriMapFunction<any>, attrs: AttrList<AnyAttrWithUri> | null | undefined, type: string) => void; export declare const rewriteAttrs: (mapFn: UriMapFunction<any>, list: AttrList<AnyAttrWithUri>[] | null | undefined, type: string) => void; export declare const rewriteMappedAttrs: (mapFn: UriMapFunction<any>, map: Map<string, AttrList<AnyAttrWithUri>[]>, type: string) => void; export interface IRewritableUris { rewriteUris(mapFn: UriMapFunction): this; } export interface ImmutableIRewritableUris extends IRewritableUris { rewriteUris(mapFn: ImmutableUriMapFunction): this; } export declare class BasePlaylist { /** `true` for main playlists, otherwise `false` */ readonly master: boolean; /** @see {@link https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-16#section-4.4.1.2 `EXT-X-VERSION`} */ version: number; /** @see {@link https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-16#section-4.4.2.1 `EXT-X-INDEPENDENT-SEGMENTS`} */ independent_segments?: boolean; /** @see {@link https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-16#section-4.4.2.2 `EXT-X-START`} */ start?: AttrList<AttrT.Start>; /** @see {@link https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-16#section-4.4.2.3 `EXT-X-DEFINE`} */ defines: AttrList<AttrT.Define>[]; /** Custom vendor-defined properties */ vendor?: Iterable<[string, string | null]>; constructor(obj: Immutify<Proto<BasePlaylist>>); /** * Returns true if the playlist is expected to be updated by the server. */ isLive(): boolean; toString(): string; } export {};