Skip to content

Commit

Permalink
Add function to clean timedMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolassrod committed Apr 3, 2020
1 parent 280e87a commit eb7f9b7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Sources/FRadioPlayer/FRadioPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ open class FRadioPlayer: NSObject {
}

private func timedMetadataDidChange(rawValue: String?) {
let parts = rawValue?.components(separatedBy: " - ")
let cleanedRawValue = cleanMetadata(rawValue)
let parts = cleanedRawValue?.components(separatedBy: " - ")
delegate?.radioPlayer?(self, metadataDidChange: parts?.first, trackName: parts?.last)
delegate?.radioPlayer?(self, metadataDidChange: rawValue)
shouldGetArtwork(for: rawValue, enableArtwork)
Expand All @@ -418,7 +419,16 @@ open class FRadioPlayer: NSObject {
}
})
}


private func cleanMetadata(_ rawValue: String?) -> String? {
guard let rawValue = rawValue else { return nil }
return rawValue.replacingOccurrences(
of: #"(\(.*?\)\w*)|(\[.*?\]\w*)"#,
with: "",
options: .regularExpression
)
}

private func reloadItem() {
player?.replaceCurrentItem(with: nil)
player?.replaceCurrentItem(with: playerItem)
Expand Down

0 comments on commit eb7f9b7

Please sign in to comment.