Crates.io | m3u8-parser |
lib.rs | m3u8-parser |
version | 0.6.1 |
source | src |
created_at | 2024-11-01 16:27:53.283577 |
updated_at | 2024-11-05 21:19:22.939968 |
description | A Rust crate for parsing and creating M3U8 files (HLS). |
homepage | https://github.com/includeamin/m3u8-parser |
repository | https://github.com/includeamin/m3u8-parser |
max_upload_size | |
id | 1432020 |
size | 78,618 |
A Rust crate for parsing and creating M3U8 version 7 files for HTTP Live Streaming (HLS), as specified by RFC 8216.
[!IMPORTANT] This project is currently under active development. Please note that features and APIs are subject to change. My goal is to ensure full compatibility with RFC 8216.
#EXTM3U
#EXT-X-VERSION
#EXT-X-TARGETDURATION
#EXT-X-MEDIA-SEQUENCE
#EXT-X-ALLOW-CACHE
#EXT-X-DISCONTINUITY-SEQUENCE
#EXT-X-MEDIA
#EXT-X-STREAM-INF
#EXT-X-I-FRAME-STREAM-INF
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-BYTERANGE
#EXT-X-SESSION-DATA
#EXT-X-SESSION-KEY
#EXT-X-DEFINE
#EXTINF
#EXT-X-KEY
#EXT-X-BYTERANGE
#EXT-X-MAP
#EXT-X-GAP
#EXT-X-PROGRAM-DATE-TIME
#EXT-X-PART
#EXT-X-PRELOAD-HINT
#EXT-X-START
#EXT-X-DATERANGE
#EXT-X-KEY
#EXT-X-SESSION-KEY
#EXT-X-DATERANGE
#EXT-X-ENDLIST
#EXT-X-STREAM-INF
#EXT-X-MEDIA
#EXT-X-STREAM-INF
#EXT-X-I-FRAME-STREAM-INF
#EXT-X-PROGRAM-DATE-TIME
Add this to your Cargo.toml
:
[dependencies]
m3u8-parser = "0.6.1"
use m3u8_parser::m3u8::playlist::Playlist;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let data = r#"
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:6
#EXTINF:5.009,
https://media.example.com/first.ts
#EXTINF:5.009,
https://media.example.com/second.ts
#EXTINF:3.003,
https://media.example.com/third.ts
#EXT-X-ENDLIST
"#;
let playlist = Playlist::from_reader(data.as_bytes())?;
println!("{:?}", playlist);
Ok(())
}
use m3u8_parser::m3u8::playlist::builder::PlaylistBuilder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let playlist = PlaylistBuilder::new()
.extm3u()
.version(7)
.target_duration(6)
.extinf(5.009, None)
.uri("https://media.example.com/first.ts".to_string())
.extinf(5.009, None)
.uri("https://media.example.com/second.ts".to_string())
.extinf(3.003, None)
.uri("https://media.example.com/third.ts".to_string())
.end_list()
.build()?;
playlist.write_to_file("playlist.m3u8")?;
Ok(())
}