Skip to content

Commit

Permalink
feat: Add ExtXPlaylistType support in M3U8 tags and builder
Browse files Browse the repository at this point in the history
This commit introduces the `ExtXPlaylistType` tag to the M3U8 playlist parser, which provides mutability information about the playlist. It also updates the builder to support adding this tag, and includes a new Makefile for testing and linting with cargo.
  • Loading branch information
includeamin committed Nov 4, 2024
1 parent 6b4bd3d commit c221cb1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
check:
cargo test
cargo clippy --fix --allow-dirty --allow-staged
6 changes: 6 additions & 0 deletions src/m3u8/playlist/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,10 @@ impl PlaylistBuilder {
Err(errors) => Err(errors),
}
}

/// Adds an `ExtXPlaylistType` tag.
pub fn playlist_type(mut self, playlist_type: String) -> Self {
self.tags.push(Tag::ExtXPlaylistType(playlist_type));
self
}
}
15 changes: 14 additions & 1 deletion src/m3u8/playlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,19 @@ impl Playlist {

return Ok(Some(target_duration_tag));
}
"#EXT-X-PLAYLIST-TYPE" => {
let attributes = parse_attributes(stripped)?;
let playlist_type = attributes
.get("PLAYLIST-TYPE")
.ok_or("Missing PLAYLIST-TYPE attribute")?
.clone();

if playlist_type != "EVENT" && playlist_type != "VOD" {
return Err("Invalid PLAYLIST-TYPE value".to_string());
}

return Ok(Some(Tag::ExtXPlaylistType(playlist_type)));
}
_ => {}
}
}
Expand Down Expand Up @@ -556,7 +569,7 @@ impl Playlist {
));
}
}

// if end_date.is_some_and(move |t| {t.is_empty()}) {
// // Add checks for end_date format or validity as needed
// } else {
Expand Down
8 changes: 8 additions & 0 deletions src/m3u8/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ pub enum Tag {
ExtM3U,
/// Specifies the version of the M3U8 playlist.
ExtXVersion(u8),
/// The EXT-X-PLAYLIST-TYPE tag provides mutability information about the
// Media Playlist file. It applies to the entire Media Playlist file.
// It is OPTIONAL. Its format is:
ExtXPlaylistType(String),
/// Represents a media segment with a duration and an optional title.
ExtInf(f32, Option<String>),
/// Indicates the target duration for media segments.
Expand Down Expand Up @@ -474,6 +478,10 @@ impl std::fmt::Display for Tag {
}
Ok(())
}
Tag::ExtXPlaylistType(playlist_type) => {
write!(f, "#EXT-X-PLAYLIST-TYPE:{}", playlist_type)?;
Ok(())
}
}
}
}

0 comments on commit c221cb1

Please sign in to comment.