diff --git a/src/error.rs b/src/error.rs index d4666c7..5d089a9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -49,6 +49,12 @@ pub enum ErrorKind { #[fail(display = "IoError: {}", _0)] Io(String), + #[fail( + display = "VersionError: required_version: {:?}, specified_version: {:?}", + _0, _1 + )] + VersionError(String, String), + /// Hints that destructuring should not be exhaustive. /// /// This enum may grow additional variants, so this makes sure clients @@ -171,6 +177,17 @@ impl Error { pub(crate) fn io(value: T) -> Self { Self::from(ErrorKind::Io(value.to_string())) } + + pub(crate) fn required_version(required_version: T, specified_version: U) -> Self + where + T: ToString, + U: ToString, + { + Self::from(ErrorKind::VersionError( + required_version.to_string(), + specified_version.to_string(), + )) + } } impl From for Error { diff --git a/src/master_playlist.rs b/src/master_playlist.rs index 85ba8fe..683640d 100644 --- a/src/master_playlist.rs +++ b/src/master_playlist.rs @@ -73,9 +73,8 @@ impl MasterPlaylistBuilder { let required_version = self.required_version(); let specified_version = self.version.unwrap_or(required_version); - if required_version <= specified_version { - // "required_version:{}, specified_version:{}" - return Err(Error::invalid_input()); + if required_version < specified_version { + return Err(Error::required_version(required_version, specified_version)); } (self.validate_stream_inf_tags())?; @@ -379,5 +378,21 @@ mod tests { use super::*; #[test] - fn test_parser() {} + fn test_parser() { + let playlist = r#" + #EXTM3U + #EXT-X-STREAM-INF:BANDWIDTH=150000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2" + http://example.com/low/index.m3u8 + #EXT-X-STREAM-INF:BANDWIDTH=240000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2" + http://example.com/lo_mid/index.m3u8 + #EXT-X-STREAM-INF:BANDWIDTH=440000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2" + http://example.com/hi_mid/index.m3u8 + #EXT-X-STREAM-INF:BANDWIDTH=640000,RESOLUTION=640x360,CODECS="avc1.42e00a,mp4a.40.2" + http://example.com/high/index.m3u8 + #EXT-X-STREAM-INF:BANDWIDTH=64000,CODECS="mp4a.40.5" + http://example.com/audio/index.m3u8 + "# + .parse::() + .unwrap(); + } }