if let artist = track.artist.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
if let name: String = track.name.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
if let url = URL(string: "\(apiURL)&artist=\(artist)&song=\(name)") {
if let artist = track.artist.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
if let name: String = track.name.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
if let url = URL(string: "\(apiURL)&artist=\(artist)&song=\(name)") {
// Call the API and unlock when you're done
fetchLyricsFromAPI(withURL: url, completionHandler: {lyricsResult -> Void in
// Call the API and unlock when you're done
fetchLyricsFromAPI(withURL: url, completionHandler: {lyricsResult -> Void in
private func fetchLyricsFromAPI(withURL url: URL, completionHandler: @escaping (String?) -> Void) {
var apiRequest = URLRequest(url: url)
private func fetchLyricsFromAPI(withURL url: URL, completionHandler: @escaping (String?) -> Void) {
var apiRequest = URLRequest(url: url)
private func fetchLyricsFromPage(withURL url: URL, completionHandler: @escaping (String?) -> Void) {
var pageRequest = URLRequest(url: url)
private func fetchLyricsFromPage(withURL url: URL, completionHandler: @escaping (String?) -> Void) {
var pageRequest = URLRequest(url: url)
if let regex = try? NSRegularExpression(pattern: lyricsMatcher) {
let matches = regex.matches(in: body, range: NSRange(location: 0, length: body.characters.count))
if let regex = try? NSRegularExpression(pattern: lyricsMatcher) {
let matches = regex.matches(in: body, range: NSRange(location: 0, length: body.characters.count))