mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
35 lines
760 B
Swift
35 lines
760 B
Swift
//
|
|
// MPDAlbumArtImageDataProvider.swift
|
|
// Persephone
|
|
//
|
|
// Created by Daniel Barber on 2/1/20.
|
|
// Copyright © 2020 Dan Barber. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import Kingfisher
|
|
|
|
public struct MPDAlbumArtImageDataProvider: ImageDataProvider {
|
|
let song: MPDClient.MPDSong
|
|
|
|
init(song: MPDClient.MPDSong, cacheKey: String? = nil) {
|
|
self.song = song
|
|
self.cacheKey = cacheKey ?? song.uriString
|
|
}
|
|
|
|
public var cacheKey: String
|
|
|
|
public func data(handler: @escaping (Result<Data, Error>) -> Void) {
|
|
App.mpdClient.fetchAlbumArt(song: song) { imageData in
|
|
guard let imageData = imageData
|
|
else { return }
|
|
|
|
handler(.success(imageData))
|
|
}
|
|
}
|
|
|
|
public var contentURL: String? {
|
|
return song.uriString
|
|
}
|
|
}
|