From 8d57d313be6dfea184e226f875eafdeae1ebeeb6 Mon Sep 17 00:00:00 2001 From: Christian Rackerseder Date: Sat, 23 Nov 2019 03:06:23 +0100 Subject: [PATCH] Create type definitions for hls-parser (#40600) --- types/hls-parser/hls-parser-tests.ts | 24 +++ types/hls-parser/index.d.ts | 284 +++++++++++++++++++++++++++ types/hls-parser/tsconfig.json | 23 +++ types/hls-parser/tslint.json | 1 + 4 files changed, 332 insertions(+) create mode 100644 types/hls-parser/hls-parser-tests.ts create mode 100644 types/hls-parser/index.d.ts create mode 100644 types/hls-parser/tsconfig.json create mode 100644 types/hls-parser/tslint.json diff --git a/types/hls-parser/hls-parser-tests.ts b/types/hls-parser/hls-parser-tests.ts new file mode 100644 index 0000000000..6b6fadf601 --- /dev/null +++ b/types/hls-parser/hls-parser-tests.ts @@ -0,0 +1,24 @@ +import HLS = require('hls-parser'); + +const playlist = HLS.parse(''); + +if (playlist.isMasterPlaylist) { + // Master playlist +} else { + // Media playlist +} + +const { MediaPlaylist, Segment } = HLS.types; + +new MediaPlaylist({ + targetDuration: 9, + playlistType: 'VOD', + segments: [ + new Segment({ + uri: 'low/1.m3u8', + duration: 9, + mediaSequenceNumber: 0, + discontinuitySequence: 0, + }), + ], +}); diff --git a/types/hls-parser/index.d.ts b/types/hls-parser/index.d.ts new file mode 100644 index 0000000000..32006da288 --- /dev/null +++ b/types/hls-parser/index.d.ts @@ -0,0 +1,284 @@ +// Type definitions for hls-parser 0.5 +// Project: https://github.com/kuu/hls-parser#readme +// Definitions by: Christian Rackerseder +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.4 + +/// + +export interface Byterange { + length: number; + offset: number; +} + +export interface Options { + strictMode: boolean; +} + +export class Data { + type: 'playlist' | 'segment'; +} + +export namespace types { + class Playlist extends Data { + isMasterPlaylist: boolean; + + uri?: string; + + version?: number; + + independentSegments: boolean; + + start?: { offset: number; precise: boolean }; + + source?: string; + + constructor(properties: { + isMasterPlaylist: boolean; + uri?: string; + version?: number; + independentSegments: boolean; + start?: { offset: number; precise: boolean }; + source?: string; + }); + } + + class MasterPlaylist extends Playlist { + variants: readonly Variant[]; + + currentVariant?: number; + + sessionDataList: readonly SessionData[]; + + sessionKeyList: readonly Key[]; + + constructor(properties: { + variants?: readonly Variant[]; + currentVariant?: number; + sessionDataList?: readonly SessionData[]; + sessionKeyList?: readonly Key[]; + source?: string; + }); + } + + class MediaPlaylist extends Playlist { + targetDuration: number; + + mediaSequenceBase?: number; + + discontinuitySequenceBase?: number; + + endlist: boolean; + + playlistType?: 'EVENT' | 'VOD'; + + isIFrame: boolean; + + segments: readonly Segment[]; + + constructor(properties: { + targetDuration: number; + mediaSequenceBase?: number; + discontinuitySequenceBase?: number; + endlist?: boolean; + playlistType?: 'EVENT' | 'VOD'; + isIFrame?: boolean; + segments?: readonly Segment[]; + source?: string; + }); + } + + class Variant { + uri: string; + + isIFrameOnly?: boolean; + + bandwidth: number; + + averageBandwidth?: number; + + codecs?: string; + + resolution?: { width: number; height: number }; + + frameRate?: number; + + hdcpLevel?: string; + + audio: ReadonlyArray>; + + video: ReadonlyArray>; + + subtitles: ReadonlyArray>; + + closedCaptions: ReadonlyArray>; + + currentRenditions: { audio?: number; video?: number; subtitles?: number; closedCaptions?: number }; + + constructor(properties: { + uri: string; + isIFrameOnly?: boolean; + bandwidth: number; + averageBandwidth?: number; + codecs?: string; + resolution?: { width: number; height: number }; + frameRate?: number; + hdcpLevel?: string; + audio?: ReadonlyArray>; + video?: ReadonlyArray>; + subtitles?: ReadonlyArray>; + closedCaptions?: ReadonlyArray>; + currentRenditions?: { audio?: number; video?: number; subtitles?: number; closedCaptions?: number }; + }); + } + + class Rendition { + type: T; + + uri?: string; + + groupId: string; + + language?: string; + + assocLanguage?: string; + + name: string; + + isDefault: boolean; + + autoselect: boolean; + + forced: boolean; + + instreamId?: string; + + characteristics?: string; + + channels?: string; + + constructor(properties: { + type: T; + uri?: string; + groupId: string; + language?: string; + assocLanguage?: string; + name: string; + isDefault?: boolean; + autoselect?: boolean; + forced?: boolean; + instreamId?: string; + characteristics?: string; + channels?: string; + }); + } + + class SessionData { + id: string; + + value?: string; + + uri?: string; + + language?: string; + + constructor(properties: { id: string; value?: string; uri?: string; language?: string }); + } + + class Segment extends Data { + uri: string; + + duration: number; + + title?: string; + + byterange?: Byterange; + + discontinuity?: boolean; + + mediaSequenceNumber: number; + + discontinuitySequence: number; + + key?: Key; + + map?: MediaInitializationSection; + + programDateTime?: Date; + + dateRange: DateRange; + + constructor(properties: { + uri: string; + duration: number; + title?: string; + byterange?: Byterange; + discontinuity?: boolean; + mediaSequenceNumber: number; + discontinuitySequence: number; + key?: Key; + map?: MediaInitializationSection; + programDateTime?: Date; + dateRange?: DateRange; + }); + } + + class Key { + method: string; + + uri?: string; + + iv?: Buffer; + + format?: string; + + formatVersion?: string; + + constructor(properties: { method: string; uri?: string; iv?: Buffer; format?: string; formatVersion?: string }); + } + + class MediaInitializationSection { + uri: string; + + byterange?: Byterange; + + constructor(properties: { uri: string; byterange?: Byterange }); + } + + class DateRange { + id: string; + + classId?: string; + + start: Date; + + end?: Date; + + duration?: number; + + plannedDuration?: number; + + endOnNext?: boolean; + + attributes?: object; + + constructor(properties: { + id: string; + classId?: string; + start: Date; + end?: Date; + duration?: number; + plannedDuration?: number; + endOnNext?: boolean; + attributes?: object; + }); + } +} + +export function parse(manifest: string): types.MasterPlaylist | types.MediaPlaylist; + +export function stringify(playlist: types.MasterPlaylist | types.MediaPlaylist): string; + +export function setOptions(overrides: Partial): void; + +export function getOptions(): Options; diff --git a/types/hls-parser/tsconfig.json b/types/hls-parser/tsconfig.json new file mode 100644 index 0000000000..00b6a5c7fe --- /dev/null +++ b/types/hls-parser/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "hls-parser-tests.ts" + ] +} diff --git a/types/hls-parser/tslint.json b/types/hls-parser/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/hls-parser/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }