From 4521ede9a05256a4336c5828ce8e471ec1f4a2fd Mon Sep 17 00:00:00 2001 From: Omar Albeik <8127757+omaralbeik@users.noreply.github.com> Date: Sun, 24 Apr 2022 19:41:48 +0200 Subject: [PATCH] Call completion on main queue in parser (#7) --- README.md | 6 +++--- Sources/M3UKit/Models/Channel.swift | 5 ----- Sources/M3UKit/Parsers/PlaylistParser.swift | 4 +++- Tests/M3UKitTests/ChannelTests.swift | 18 ------------------ 4 files changed, 6 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 055a31f..8992ea1 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ The [Swift Package Manager](https://swift.org/package-manager/) is a tool for ma ```swift dependencies: [ - .package(url: "https://github.com/omaralbeik/M3UKit.git", from: "0.5.1") + .package(url: "https://github.com/omaralbeik/M3UKit.git", from: "0.5.2") ] ``` @@ -121,7 +121,7 @@ $ swift build To integrate M3UKit into your Xcode project using [CocoaPods](https://cocoapods.org), specify it in your Podfile: ```rb -pod 'M3UKit', :git => 'https://github.com/omaralbeik/M3UKit.git', :tag => '0.5.1' +pod 'M3UKit', :git => 'https://github.com/omaralbeik/M3UKit.git', :tag => '0.5.2' ``` ### Carthage @@ -129,7 +129,7 @@ pod 'M3UKit', :git => 'https://github.com/omaralbeik/M3UKit.git', :tag => '0.5.1 To integrate M3UKit into your Xcode project using [Carthage](https://github.com/Carthage/Carthage), specify it in your Cartfile: ``` -github "omaralbeik/M3UKit" ~> 0.5.1 +github "omaralbeik/M3UKit" ~> 0.5.2 ``` ### Manually diff --git a/Sources/M3UKit/Models/Channel.swift b/Sources/M3UKit/Models/Channel.swift index 750061d..ce2d6d9 100644 --- a/Sources/M3UKit/Models/Channel.swift +++ b/Sources/M3UKit/Models/Channel.swift @@ -70,10 +70,5 @@ extension Playlist { /// Channel URL. public var url: URL - - /// Whether the channel is a live channel (its URL ends with .m3u8) or not. - public var isLive: Bool { - url.absoluteString.hasSuffix(".m3u8") - } } } diff --git a/Sources/M3UKit/Parsers/PlaylistParser.swift b/Sources/M3UKit/Parsers/PlaylistParser.swift index 3fecc31..21b874d 100644 --- a/Sources/M3UKit/Parsers/PlaylistParser.swift +++ b/Sources/M3UKit/Parsers/PlaylistParser.swift @@ -134,7 +134,9 @@ public final class PlaylistParser: Parser { queue.async { do { let playlist = try self.parse(input) - completion(.success(playlist)) + DispatchQueue.main.async { + completion(.success(playlist)) + } } catch { DispatchQueue.main.async { completion(.failure(error)) diff --git a/Tests/M3UKitTests/ChannelTests.swift b/Tests/M3UKitTests/ChannelTests.swift index 2cc6659..224464a 100644 --- a/Tests/M3UKitTests/ChannelTests.swift +++ b/Tests/M3UKitTests/ChannelTests.swift @@ -44,24 +44,6 @@ final class ChannelTests: XCTestCase { XCTAssertEqual(channel.url, url) } - func testIsLive() { - let liveChannel = Playlist.Channel( - duration: -1, - attributes: .init(), - name: "Channel", - url: URL(string: "https://cnn-cnninternational-1-de.samsung.wurl.com/manifest/playlist.m3u8")! - ) - XCTAssert(liveChannel.isLive) - - let channel = Playlist.Channel( - duration: -1, - attributes: .init(), - name: "Channel", - url: URL(string: "https://not.a/real/url")! - ) - XCTAssertFalse(channel.isLive) - } - func testExtractingDuration() throws { let parser = ChannelMetadataParser() XCTAssertThrowsError(try parser.extractDuration((1, "invalid")))