Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@smt-lib/m3u-parser
Advanced tools
解释: HLS(http live stream), Apple 公司于2009年提出的基于 HTTP 协议的流媒体协议. 支持度: iOS、MacOSX 及 Apple TV 原生支持; Android 3.0+ 支持.
它的传输内容包括两部份, 一是 M3U8 描述文件, 二是 TS 媒体文件,这里主要解决 M3U8 描述文件的解析问题
M3U8 是 M3U 的 UTF8 编码版本, M3U 是一种列表文件, 只提供一些描述信息.
M3U 文件中可以包含多个 tag, 每个 tag 的功能和属性如下:
#EXTM3U
文件的头部,必须是文件的第一行。
#EXTINF
指示多媒体文件的信息,包括播放时间和标题。
#EXT-X-MEDIA-SEQUENCE:
每一个media URI 在 PlayList 中只有唯一的序号, 相邻之间序号 +1, 一个 media URI 并不是必须要包含的, 如果没有, 默认为 0
#EXT-X-TARGETDURATION:
指定最大的媒体段时间长(秒). 所以#EXTINF中指定的时间长度必须小于或是等于这个最大值. 这个 tag 在整个 PlayList 文件中只能出现一次 (在嵌套的情况下, 一般有真正 TS url 的 m3u8 才会出现该 tag)
#EXTINF: [, ]
duration 指定每个媒体段(ts)的持续时间(秒), 仅对其后面的URI有效, title 是下载资源的 url
#EXT-X-PROGRAM-DATE-TIME
将一个绝对时间或是日期和一个媒体段中的第一个 Sample 相关联, 只对下一个 meida URI 有效 例子: #EXT-X-PROGRAM-DATE-TIME:2010-02-19T14:54:23.031+08:00
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:15
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PROGRAM-DATE-TIME:2019-12-27T13:52:58.107325501+08:00
#EXTINF:0.000,
/v1/liveshowstatic/3262140290_1577425980848091643.ts?authorization=bce-auth-v1/3a9861ff96dd472f875791b14cb0b6a1/2019-12-27T05:53:00Z/604800/host/b0572bf3ff1643d95f5f4b64c788461912c2c8e880b003fd7f87fa68a8093f13
#EXT-X-PROGRAM-DATE-TIME:2019-12-27T13:53:04.423748954+08:00
#EXTINF:0.000,
/v1/liveshowstatic/3262140290_1577425985846621096.ts?authorization=bce-auth-v1/3a9861ff96dd472f875791b14cb0b6a1/2019-12-27T05:53:05Z/604800/host/7ede18cc10a376b33ddd3fcb3faad0c75b117d3bebc3118dd955839791bff2fb
#EXT-X-PROGRAM-DATE-TIME:2019-12-27T13:53:19.473701505+08:00
#EXTINF:0.000,
/v1/liveshowstatic/3262140290_1577426000864220299.ts?authorization=bce-auth-v1/3a9861ff96dd472f875791b14cb0b6a1/2019-12-27T05:53:20Z/604800/host/21ce1874cc833778edad812a88267769ca48ad879feee9b29acfe416f1928880
ts媒体文件是根据业务不同自定义的格式,比如直播消息流的ts文件格式是json string,而视频编码主要格式 h264/mpeg4, 音频为 acc/MP3。由于TS 媒体文件的定制化比较高,这里就不一一介绍了。
npm使用方法方法,见npm使用说明
npm install @smt-lib/m3u-parser
// m3u-index文件内容
import {parseM3U8Text} from '@smt-lib/m3u-parser';
const m3uIndexText = '#EXTM3U\r\n...';
// 解析后的json格式m3u-index文件
cosnt m3uJson = parseM3U8Text(m3uIndexText);
// console.log(m3uJson);
parseM3U8Text
注册异常监听函数
字段名 | 类型 | 必有 | 说明 |
---|---|---|---|
fileText | string | Y | m3u-index文件内容 |
返回参数说明
字段名 | 类型 | 必有 | 说明 |
---|---|---|---|
version | string | N | 含义详见M3U描述文件 #EXT-X-VERSION |
duration | string | N | #EXT-X-TARGETDURATION |
sequence | string | N | #EXT-X-MEDIA-SEQUENCE |
fileQueue | array | N | 文件队列 |
fileQueue-item 项说明
字段名 | 类型 | 必有 | 说明 |
---|---|---|---|
item.programTime | string | N | #EXT-X-PROGRAM-DATE-TIME 进度条时间 |
item.info | object | N | 信息,包含title标题和duration持续时间 |
item.path | string | Y | TS文件地址或嵌套m3u地址, 注意: path可能不包含host和protocol |
item.type | number | y | 枚举 0:带进度条型ts文件项,1:不带进度条型ts文件项,2:m3u-index嵌套项 |
// type=0
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:15
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PROGRAM-DATE-TIME:2019-12-27T13:52:58.107325501+08:00
#EXTINF:0.000,
/v1/liveshowstatic/3262140290_1577425980848091643.ts?authorization=bce-auth-v1/3a9861ff96dd472f875791b14cb0b6a1/2019-12-27T05:53:00Z/604800/host/b0572bf3ff1643d95f5f4b64c788461912c2c8e880b003fd7f87fa68a8093f13
#EXT-X-PROGRAM-DATE-TIME:2019-12-27T13:53:04.423748954+08:00
#EXTINF:0.000,
/v1/liveshowstatic/3262140290_1577425985846621096.ts?authorization=bce-auth-v1/3a9861ff96dd472f875791b14cb0b6a1/2019-12-27T05:53:05Z/604800/host/7ede18cc10a376b33ddd3fcb3faad0c75b117d3bebc3118dd955839791bff2fb
#EXT-X-PROGRAM-DATE-TIME:2019-12-27T13:53:19.473701505+08:00
#EXTINF:0.000,
/v1/liveshowstatic/3262140290_1577426000864220299.ts?authorization=bce-auth-v1/3a9861ff96dd472f875791b14cb0b6a1/2019-12-27T05:53:20Z/604800/host/21ce1874cc833778edad812a88267769ca48ad879feee9b29acfe416f1928880
// type=1
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:15
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:0.000,
/v1/liveshowstatic/3262140290_1577425980848091643.ts?authorization=bce-auth-v1/3a9861ff96dd472f875791b14cb0b6a1/2019-12-27T05:53:00Z/604800/host/b0572bf3ff1643d95f5f4b64c788461912c2c8e880b003fd7f87fa68a8093f13
#EXTINF:0.000,
/v1/liveshowstatic/3262140290_1577425985846621096.ts?authorization=bce-auth-v1/3a9861ff96dd472f875791b14cb0b6a1/2019-12-27T05:53:05Z/604800/host/7ede18cc10a376b33ddd3fcb3faad0c75b117d3bebc3118dd955839791bff2fb
#EXTINF:0.000,
/v1/liveshowstatic/3262140290_1577426000864220299.ts?authorization=bce-auth-v1/3a9861ff96dd472f875791b14cb0b6a1/2019-12-27T05:53:20Z/604800/host/21ce1874cc833778edad812a88267769ca48ad879feee9b29acfe416f1928880
// type=2
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1280000
http://example.com/low.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2560000
http://example.com/mid.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=7680000
http://example.com/hi.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=65000,CODECS="mp4a.40.5"
http://example.com/audio-only.m3u8
FAQs
m3u index parser
The npm package @smt-lib/m3u-parser receives a total of 4 weekly downloads. As such, @smt-lib/m3u-parser popularity was classified as not popular.
We found that @smt-lib/m3u-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.