Skip to content

Commit

Permalink
Add priority on supported streaming methods (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
waliid authored Aug 30, 2023
1 parent 369e3fa commit 225d38a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Sources/CoreBusiness/Model/Chapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public struct Chapter: Decodable {
public extension Chapter {
/// The resource recommended for playback on Apple platforms.
var recommendedResource: Resource? {
resources.first { StreamingMethod.supportedMethods.contains($0.streamingMethod) }
let resourceBuckets = Dictionary(grouping: resources) { $0.streamingMethod }
guard let preferredMethod = StreamingMethod.supportedMethods.first(where: { method in
resourceBuckets[method] != nil
}) else { return nil }
return resourceBuckets[preferredMethod]?.first
}
}
2 changes: 1 addition & 1 deletion Sources/CoreBusiness/Model/StreamingMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public enum StreamingMethod: String, Decodable {

/// The supported streaming methods on Apple platforms.
public static var supportedMethods: [Self] {
[.progressive, .m3uPlaylist, .hls, .http, .https]
[.hls, .https, .http, .m3uPlaylist, .progressive]
}
}

0 comments on commit 225d38a

Please sign in to comment.