UNPKG

@iptv/playlist

Version:

An extremely fast M3U playlist parser and generator for Node and the browser.

116 lines (110 loc) 3.61 kB
/** * Represents a single channel in an M3U playlist, detailing its properties. */ export declare type M3uChannel = { /** Identifier for the channel in a TV guide */ tvgId?: string; /** Name for the channel in a TV guide */ tvgName?: string; /** Language of the channel */ tvgLanguage?: string; /** URL of the channel's logo */ tvgLogo?: string; /** URL for the channel's TV guide data */ tvgUrl?: string; /** Recording information for the channel */ tvgRec?: string; /** Channel number in the TV guide */ tvgChno?: string; /** Group title for categorizing the channel */ groupTitle?: string; /** URL for the channel's streaming content */ url?: string; urls?: string[]; /** Name of the channel */ name?: string; /** Timeshift value for the channel */ timeshift?: string; /** Catchup service information for the channel */ catchup?: string; /** Duration of the channel's content */ duration?: number; /** Number of days available for catchup service */ catchupDays?: string; /** Source URL for the catchup service */ catchupSource?: string; /** Additional custom properties */ extras?: Record<string, string | undefined>; }; /** * Represents the headers found in an M3U playlist file. * These headers often include metadata related to the entire playlist, like URLs for TV guide data. */ export declare type M3uHeaders = { [key: string]: string | undefined; /** URL for the TV guide in XMLTV format */ xTvgUrl?: string; /** Alternative URL for the TV guide */ urlTvg?: string; }; /** * Defines the structure of an M3U playlist, typically used for streaming media channels. * An M3U playlist contains a list of channels and optional headers providing additional metadata. */ export declare type M3uPlaylist = { /** Array of `M3uChannel` objects representing each channel in the playlist. */ channels: M3uChannel[]; /** `M3uHeaders` object containing metadata for the playlist. */ headers?: M3uHeaders; }; /** * parseM3U * * Parses an M3U file and returns an `M3uPlaylist` object * * @param m3uFileContents The contents of the M3U file * * @example * ```ts * import { parseM3U } from "@iptv/playlist"; * * const m3u = `#EXTM3U * #EXTINF:-1 tvg-id="1" tvg-name="Channel 1" tvg-language="English" tvg-logo="http://example.com/logo.png" group-title="News" tvg-url="http://example.com/tvg.xml" timeshift="1" catchup="default" catchup-days="7" catchup-source="default" x-tvg-url="http://example.com/tvg.xml" url-tvg="http://example.com/tvg.xml" tvg-rec="default",Channel 1 * http://example.com/stream.m3u8 * `; * * const playlist = parseM3U(m3u); * ``` */ export declare function parseM3U(m3uFileContents: string): M3uPlaylist; /** * writeM3U * * Converts an `M3uPlaylist` object to an M3U file * * @param playlist The `M3uPlaylist` object to convert * * @example * ```ts * import { writeM3U } from "@iptv/playlist"; * * const playlist = { * headers: { * "x-tvg-url": "http://example.com/tvg.xml", * }, * channels: [{ * tvgId: "1", * tvgName: "Channel 1", * tvgLanguage: "English", * tvgLogo: "http://example.com/logo.png", * groupTitle: "News", * name: "Channel 1", * url: "http://server:port/channel1", * }], * }; * * const m3u = writeM3U(playlist); * ``` */ export declare function writeM3U(playlist: M3uPlaylist): string; export { }