Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiyuyizhi/mpd-m3u8-to-json
m3u8 parser, mpd parser , parse mpeg dash manifests(.mpd) to json, parse hls manifests(.m3u8) to json
https://github.com/xiyuyizhi/mpd-m3u8-to-json
dash hls m3u8-parser mpd-parser
Last synced: 24 days ago
JSON representation
m3u8 parser, mpd parser , parse mpeg dash manifests(.mpd) to json, parse hls manifests(.m3u8) to json
- Host: GitHub
- URL: https://github.com/xiyuyizhi/mpd-m3u8-to-json
- Owner: xiyuyizhi
- Created: 2020-03-26T12:07:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-04-27T12:40:14.000Z (over 4 years ago)
- Last Synced: 2024-09-18T04:14:41.363Z (about 2 months ago)
- Topics: dash, hls, m3u8-parser, mpd-parser
- Language: TypeScript
- Homepage:
- Size: 23.4 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mpd-m3u8-to-json
## install
```js
VParser.m3u8Parser();
VParser.mpdParser();or
npm install mpd-m3u8-to-json
import {m3u8Parser,mpdParser} from "mpd-m3u8-to-json"```
## m3u8Parser [test](./test/m3u8.spec.ts)
```ts
type AttrInfo = string | number | Array < string | number > | Object;type TagInfo = {
[propName : string]: AttrInfo;
url?: string
}type Segment = {
start: number,
end: number,
duration: number,
url: string,
cc: number,
sn: number,
keyIndex?: number
}type LevelM3u8 = {
master: boolean,
m3u8Url: string,
duration: number,
segments: Array < Segment >,
startSN: number,
endSN: number,
live: boolean,
key?: Array < any >
}type Level = {
m3u8Url: string,
levelId: number,
brandwidth?: number,
codecs?: string,
audio?: string,
details?: LevelM3u8
}type MasterM3u8 = {
master: boolean,
m3u8Url: string,
medias: Array < any >,
levels: Array < Level >,
map?: {
url: string
}
}type M3u8JSON = MasterM3u8 | LevelM3u8 | {
error: 1,
msg: string
};type PostHooks = (x : TagInfo, y : M3u8JSON) => M3u8JSON
m3u8Parser(text : string, m3u8Url : string, postHooks?: PostHooks) : M3u8JSON
const m3u8 =`
#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:3
#EXTINF:9
1.ts
#EXTINF:9
2.ts
EXT-X-DISCONTINUITY
#EXTINF:3,
3.ts
#EXT-X-ENDLIST
`m3u8Parser(m3u8,'https://a.b.c.com')
m3u8Parser(m3u8,'https://a.b.c.com',(tagInfo,result)=>{
// do something with current parsed tag
console.log(tagInfo);
return result; // must return
})```
## mpdParser [test](./test/dash.spec.ts)
```ts
type TagAttrs = {
[PropName: string]: any
}type TagInfo = {
tagName?: string;
attrs?: TagAttrs;
closed?: boolean;
};type MPDJSON = {
[TagName: string]: any
}type PostHooks = (tagName: string, attrs: TagAttrs) => TagAttrs
mpdParser(text: string, postHooks?: PostHooks): MPDJSON
const mpd = `
`mpdParser(mpd);
mpdParser(mpd,(tagName,attrs)=>{
if(tagName === 'segmentTemplate'){
attrs.duration = parseFloat(attrs.duration)
}
if(tagName === 'xxxx'){
//
}
return attrs // must return
})
```