From 280e87a93fcb34c7e725fca6627feba750bf555b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicola=CC=81s=20A=2E=20Rodri=CC=81guez?= Date: Thu, 2 Apr 2020 20:38:20 -0500 Subject: [PATCH 1/3] Update Regex expression --- Sources/FRadioPlayer/FRadioAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/FRadioPlayer/FRadioAPI.swift b/Sources/FRadioPlayer/FRadioAPI.swift index f8e71fe..ab6b62d 100644 --- a/Sources/FRadioPlayer/FRadioAPI.swift +++ b/Sources/FRadioPlayer/FRadioAPI.swift @@ -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) From eb7f9b7832eebc7a64fe394c304f4b14ea8e8f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicola=CC=81s=20A=2E=20Rodri=CC=81guez?= Date: Thu, 2 Apr 2020 20:40:03 -0500 Subject: [PATCH 2/3] Add function to clean timedMetadata --- Sources/FRadioPlayer/FRadioPlayer.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/FRadioPlayer/FRadioPlayer.swift b/Sources/FRadioPlayer/FRadioPlayer.swift index 3810628..c333549 100644 --- a/Sources/FRadioPlayer/FRadioPlayer.swift +++ b/Sources/FRadioPlayer/FRadioPlayer.swift @@ -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) @@ -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) From 71848c260a1f6ffa4ee599d12386ab45e112c709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicola=CC=81s=20A=2E=20Rodri=CC=81guez?= Date: Fri, 3 Apr 2020 00:15:30 -0500 Subject: [PATCH 3/3] Rename constant from cleanedRawValue to metadataCleaned --- Sources/FRadioPlayer/FRadioPlayer.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/FRadioPlayer/FRadioPlayer.swift b/Sources/FRadioPlayer/FRadioPlayer.swift index c333549..d27beac 100644 --- a/Sources/FRadioPlayer/FRadioPlayer.swift +++ b/Sources/FRadioPlayer/FRadioPlayer.swift @@ -399,8 +399,8 @@ open class FRadioPlayer: NSObject { } private func timedMetadataDidChange(rawValue: String?) { - let cleanedRawValue = cleanMetadata(rawValue) - let parts = cleanedRawValue?.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)