Skip to content

Commit

Permalink
Doc coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhvorost committed Jul 23, 2024
1 parent d0c04b2 commit 193be5e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion Sources/M3U8Decoder/M3U8Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/M3U8Decoder/M3U8Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class M3U8Parser {
case .parse:
parse(tag: tag, attributes: attributes)

case .parsed(let value):
case .apply(let value):
value
}
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/M3U8Decoder/MasterPlaylist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<URI>`.
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
}
9 changes: 9 additions & 0 deletions Sources/M3U8Decoder/MediaPlaylist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<URI>`.
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
}
2 changes: 1 addition & 1 deletion Tests/M3U8DecoderTests/M3U8DecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 193be5e

Please sign in to comment.