From 193be5e7ec0f42a2d9c6ea65fab83abc4fdf7fc6 Mon Sep 17 00:00:00 2001 From: Iurii Khvorost Date: Tue, 23 Jul 2024 09:14:48 +0300 Subject: [PATCH] Doc coverage --- README.md | 2 +- Sources/M3U8Decoder/M3U8Decoder.swift | 11 ++++++++++- Sources/M3U8Decoder/M3U8Parser.swift | 2 +- Sources/M3U8Decoder/MasterPlaylist.swift | 3 +++ Sources/M3U8Decoder/MediaPlaylist.swift | 9 +++++++++ Tests/M3U8DecoderTests/M3U8DecoderTests.swift | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4f94461..3d8f20d 100644 --- a/README.md +++ b/README.md @@ -448,7 +448,7 @@ decoder.parseHandler = { (tag: String, attributes: String) -> M3U8Decoder.ParseA do { if let data = attributes.data(using: .utf8) { let dict = try JSONSerialization.jsonObject(with: data) - return .parsed(dict) + return .apply(dict) } } catch { diff --git a/Sources/M3U8Decoder/M3U8Decoder.swift b/Sources/M3U8Decoder/M3U8Decoder.swift index 8af7fc7..812ea66 100644 --- a/Sources/M3U8Decoder/M3U8Decoder.swift +++ b/Sources/M3U8Decoder/M3U8Decoder.swift @@ -136,8 +136,11 @@ fileprivate extension JSONDecoder.DataDecodingStrategy { /// public class M3U8Decoder { + /// Decoding errors. public enum Error: String, LocalizedError { + /// Not Extended M3U Playlist file. case notPlaylist = "Not Extended M3U Playlist file." + /// Bad data. case badData = "Bad data." } @@ -180,12 +183,18 @@ public class M3U8Decoder { /// The strategy to use in decoding binary data. Defaults to `.hex`. public var dataDecodingStrategy: DataDecodingStrategy = .hex + /// The policy to pass back to the parsing handler. public enum ParseAction { + /// Parse the attributes. case parse - case parsed(Any) + /// Apply the attributes. + case apply(Any) } + /// The parsing handler function type. public typealias ParseHandler = (String, String) -> ParseAction + + /// The parsing handler to call to parse or apply the attributes. public var parseHandler: ParseHandler? private var decoder: JSONDecoder { diff --git a/Sources/M3U8Decoder/M3U8Parser.swift b/Sources/M3U8Decoder/M3U8Parser.swift index 7fa410a..8791082 100644 --- a/Sources/M3U8Decoder/M3U8Parser.swift +++ b/Sources/M3U8Decoder/M3U8Parser.swift @@ -329,7 +329,7 @@ class M3U8Parser { case .parse: parse(tag: tag, attributes: attributes) - case .parsed(let value): + case .apply(let value): value } } diff --git a/Sources/M3U8Decoder/MasterPlaylist.swift b/Sources/M3U8Decoder/MasterPlaylist.swift index c4a005d..940e5c0 100644 --- a/Sources/M3U8Decoder/MasterPlaylist.swift +++ b/Sources/M3U8Decoder/MasterPlaylist.swift @@ -146,7 +146,10 @@ public struct EXT_X_I_FRAME_STREAM_INF: Decodable { public let uri: String } +/// Specifies a Variant Stream by `#EXT-X-STREAM-INF` tag followed by a ``. public struct VariantStream: Decodable { + /// Specifies a Variant Stream, which is a set of Renditions that can be combined to play the presentation. public let ext_x_stream_inf: EXT_X_STREAM_INF + /// Specifies a Media Playlist that carries a Rendition of the Variant Stream. public let uri: String } diff --git a/Sources/M3U8Decoder/MediaPlaylist.swift b/Sources/M3U8Decoder/MediaPlaylist.swift index b526432..4d2d880 100644 --- a/Sources/M3U8Decoder/MediaPlaylist.swift +++ b/Sources/M3U8Decoder/MediaPlaylist.swift @@ -109,13 +109,22 @@ public struct EXT_X_BYTERANGE: Decodable { public let start: Int? } +/// Specifies a Media Segment by a series of tags followed by a ``. public struct MediaSegment: Decodable { + /// Specifies the duration of a Media Segment. public let extinf: EXTINF + /// Indicates that a Media Segment is a sub-range of the resource identified by its URI. public let ext_x_byterange: EXT_X_BYTERANGE? + /// Indicates a discontinuity between the Media Segment that follows it and the one that preceded it. public let ext_x_discontinuity: Bool? + /// Media Segments MAY be encrypted. public let ext_x_key: EXT_X_KEY? + /// Specifies how to obtain the Media Initialization Section required to parse the applicable Media Segments. public let ext_x_map: EXT_X_MAP? + /// Associates the first sample of a Media Segment with an absolute date and/or time. public let ext_x_program_date_time: Date? + /// Associates a Date Range (i.e., a range o time defined by a starting and ending date) with a set of attribute value pairs. public let ext_x_daterange: EXT_X_DATERANGE? + /// Uniform Resource Identifier to play. public let uri: String } diff --git a/Tests/M3U8DecoderTests/M3U8DecoderTests.swift b/Tests/M3U8DecoderTests/M3U8DecoderTests.swift index 7628c44..9873609 100644 --- a/Tests/M3U8DecoderTests/M3U8DecoderTests.swift +++ b/Tests/M3U8DecoderTests/M3U8DecoderTests.swift @@ -265,7 +265,7 @@ final class M3U8_All: XCTestCase { do { if let data = attributes.data(using: .utf8) { let dict = try JSONSerialization.jsonObject(with: data) - return .parsed(dict) + return .apply(dict) } } catch {