Avoid using a regex to get the channels count.

This commit is contained in:
Damiano Galassi committed 2019-04-22 10:01:31 +02:00
1 parent a847b95644
commit 79c73c33f6
5 files changed
+38 -35

No files matched your search

+3 -16
View File
@@ -461,24 +461,11 @@ class QueuePrettifyAudioTrackNameAction : NSObject, QueueActionProtocol {
func runAction(_ item: QueueItem) -> Bool {
if let tracks = item.mp4File?.tracks {
// Iterate audio tracks
for track in tracks {
if let audioTrack = track as? MP42AudioTrack {
// Parse format summary for channel count
if let range = audioTrack.formatSummary.range(of: "(\\d+)(?=\\D*$)", options: .regularExpression) {
let channelCount = Int(audioTrack.formatSummary[range])!
// Use channel count to determine track name
if channelCount == 1 {
audioTrack.name = "Mono Audio"
} else if channelCount == 2 {
audioTrack.name = "Stereo Audio"
} else {
audioTrack.name = "Surround Audio"
}
}
}
for track in tracks.compactMap({ $0 as? MP42AudioTrack }) {
track.name = track.prettyTrackName
}
}
return true
}