Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for the love of god please add typedefs #169

Open
castdrian opened this issue Jul 3, 2023 · 4 comments
Open

for the love of god please add typedefs #169

castdrian opened this issue Jul 3, 2023 · 4 comments

Comments

@castdrian
Copy link

No description provided.

@willemmulder
Copy link

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

@castdrian
Copy link
Author

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

@t1mp4
Copy link

t1mp4 commented Apr 28, 2024

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;
  }
}

@willemmulder
Copy link

Awesome! Can this be added to the repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants