Skip to content

Commit

Permalink
Merge pull request #40 from nicolassrod/master
Browse files Browse the repository at this point in the history
Enhance metadata validators
  • Loading branch information
fethica authored Apr 3, 2020
2 parents b47cca8 + 71848c2 commit fc3cde5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/FRadioPlayer/FRadioAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal struct FRadioAPI {
// Strip off trailing '[???]' characters left there by ShoutCast and Centova Streams
// It will leave the string alone if the pattern is not there

let pattern = "(\\[.*?\\]\\w*$)"
let pattern = #"(\(.*?\)\w*)|(\[.*?\]\w*)"#
guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else { return rawValue }

let rawCleaned = NSMutableString(string: rawValue)
Expand Down
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 metadataCleaned = cleanMetadata(rawValue)
let parts = metadataCleaned?.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 fc3cde5

Please sign in to comment.