Apple Music fix

This commit is contained in:
2026-04-07 20:15:56 +02:00
parent fe3ed1e204
commit f55b7e478b
7 changed files with 145 additions and 51 deletions
+19 -5
View File
@@ -491,12 +491,26 @@ final class MAService {
/// Parse a Music Assistant URI into (provider, itemId)
/// MA URIs follow the format: scheme://media_type/item_id
///
/// Uses manual string parsing because some schemes contain underscores
/// (e.g. "apple_music") which are invalid per RFC 2396, causing Swift's
/// URL(string:) initialiser to return nil for those URIs.
private func parseMAUri(_ uri: String) -> (provider: String, itemId: String)? {
guard let url = URL(string: uri),
let provider = url.scheme,
let host = url.host else { return nil }
let itemId = url.path.isEmpty ? host : String(url.path.dropFirst())
return (provider, itemId)
guard let sepRange = uri.range(of: "://") else { return nil }
let provider = String(uri[uri.startIndex..<sepRange.lowerBound])
guard !provider.isEmpty else { return nil }
let remainder = String(uri[sepRange.upperBound...])
guard !remainder.isEmpty else { return nil }
// remainder is "media_type/item_id" or just "item_id"
if let slashIdx = remainder.firstIndex(of: "/") {
let itemId = String(remainder[remainder.index(after: slashIdx)...])
guard !itemId.isEmpty else { return nil }
return (provider, itemId)
} else {
return (provider, remainder)
}
}
// MARK: - Image Proxy