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
+42 -25
View File
@@ -7,44 +7,61 @@
import SwiftUI
/// Small monochrome badge indicating which music provider an item comes from.
/// Uses the URI scheme first, then falls back to the image provider field.
/// Monochrome badges indicating which music provider(s) an item comes from.
/// For provider-specific URIs (e.g. spotify://) a single badge is shown.
/// For library:// items all distinct source providers found in the metadata
/// images are shown side by side.
struct ProviderBadge: View {
let uri: String
var imageProvider: String? = nil
var metadata: MediaItemMetadata? = nil
private var provider: MusicProvider? {
// Try URI scheme first (provider-specific items like subsonic://...)
if let fromScheme = MusicProvider.from(scheme: URL(string: uri)?.scheme),
fromScheme != .library {
return fromScheme
private var providers: [MusicProvider] {
// Use string-based parsing URL(string:) returns nil for schemes with
// underscores like "apple_music" which violate RFC 2396.
let scheme = uri.components(separatedBy: "://").first?.lowercased()
// Non-library URI show only that provider
if let fromScheme = MusicProvider.from(scheme: scheme), fromScheme != .library {
return [fromScheme]
}
// Fall back to the image provider metadata
if let imageProvider, let fromImage = MusicProvider.from(providerKey: imageProvider) {
return fromImage
// library:// URI collect all distinct providers from metadata images
var seen = Set<MusicProvider>()
var result = [MusicProvider]()
let keys = metadata?.images?.compactMap { $0.provider } ?? []
for key in keys {
if let p = MusicProvider.from(providerKey: key), !seen.contains(p) {
seen.insert(p)
result.append(p)
}
}
// URI scheme is library:// and no image provider show library badge
if URL(string: uri)?.scheme?.lowercased() == "library" {
return .library
// Nothing found for a library item fall back to the library badge
if result.isEmpty && scheme == "library" {
return [.library]
}
return nil
return result
}
var body: some View {
if let provider {
Image(systemName: provider.icon)
.font(.system(size: 9, weight: .bold))
.foregroundStyle(.white)
.frame(width: 20, height: 20)
.background(.black.opacity(0.55))
.clipShape(Circle())
HStack(spacing: 4) {
ForEach(providers, id: \.self) { provider in
Image(systemName: provider.icon)
.font(.system(size: 9, weight: .bold))
.foregroundStyle(.white)
.frame(width: 20, height: 20)
.background(.black.opacity(0.55))
.clipShape(Circle())
}
}
}
}
// MARK: - Provider Mapping
enum MusicProvider {
enum MusicProvider: Hashable {
case library
case subsonic
case spotify
@@ -64,7 +81,7 @@ enum MusicProvider {
var icon: String {
switch self {
case .library: return "building.columns.fill"
case .subsonic: return "sailboat.fill"
case .subsonic: return "ferry.fill"
case .spotify: return "antenna.radiowaves.left.and.right.circle.fill"
case .tidal: return "water.waves"
case .qobuz: return "hifispeaker.fill"
@@ -119,7 +136,7 @@ enum MusicProvider {
if k.hasPrefix("filesystem") { return .filesystem }
if k.hasPrefix("jellyfin") { return .jellyfin }
if k.hasPrefix("dlna") { return .dlna }
// Common image-only providers not a music source
// Image-only metadata providers not a music source
if k == "lastfm" || k == "musicbrainz" || k == "fanarttv" { return nil }
return nil