m3u8-parser icon indicating copy to clipboard operation
m3u8-parser copied to clipboard

for the love of god please add typedefs

Open castdrian opened this issue 2 years ago • 4 comments

castdrian avatar Jul 03 '23 11:07 castdrian

Are there any plans for this? Would love to have proper Typescript support

willemmulder avatar Mar 08 '24 12:03 willemmulder

Honestly just use this lib instead https://www.npmjs.com/package/parse-hls

castdrian avatar Mar 08 '24 13:03 castdrian

Not 100% complete but should do the job. Modify to your needs.

declare module "m3u8-parser" {
  type Manifest = {
    allowCache?: boolean;
    endList?: boolean;
    mediaSequence?: number;
    dateRanges?: any[];
    discontinuitySequence?: number;
    playlistType?: string;
    custom?: Record<any, any>;
    playlists?: {
      attributes?: Record<any, any>;
      Manifest?: Manifest;
    }[];
    mediaGroups?: {
      AUDIO?: {
        "GROUP-ID"?: {
          NAME?: {
            default?: boolean;
            autoselect?: boolean;
            language?: string;
            uri?: string;
            instreamId?: string;
            characteristics?: string;
            forced?: boolean;
          };
        };
      };
      VIDEO?: Record<any, any>;
      "CLOSED-CAPTIONS"?: Record<any, any>;
      SUBTITLES?: Record<any, any>;
    };
    dateTimeString?: string;
    dateTimeObject?: Date;
    targetDuration?: number;
    totalDuration?: number;
    discontinuityStarts?: number[];
    segments?: {
      title?: string;
      byterange?: {
        length?: number;
        offset?: number;
      };
      duration?: number;
      programDateTime?: number;
      attributes?: Record<any, any>;
      discontinuity?: number;
      uri?: string;
      timeline?: number;
      key?: {
        method?: string;
        uri?: string;
        iv?: string;
      };
      map?: {
        uri?: string;
        byterange?: {
          length?: number;
          offset?: number;
        };
      };
      "cue-out"?: string;
      "cue-out-cont"?: string;
      "cue-in"?: string;
      custom?: Record<any, any>;
    }[];
  };

  export class Parser {
    manifest: Manifest;

    constructor();

    push(chunk: string): void;

    end(): void;

    addParser(options: {
      expression: RegExp;
      customType: string;
      dataParser?: (line: string) => any;
      segment?: boolean;
    }): void;

    addTagMapper(options: {
      expression: RegExp;
      map: (line: string) => string;
    }): void;
  }
}

t1mp4 avatar Apr 28 '24 05:04 t1mp4

Awesome! Can this be added to the repo?

willemmulder avatar May 01 '24 20:05 willemmulder