mirror of
https://github.com/danbee/persephone
synced 2025-03-04 08:39:11 +00:00
29 lines
775 B
Swift
29 lines
775 B
Swift
//
|
|
// AlbumArtService.swift
|
|
// Persephone
|
|
//
|
|
// Created by Daniel Barber on 2019/2/23.
|
|
// Copyright © 2019 Dan Barber. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
|
|
class AlbumArtService: NSObject {
|
|
let cachedArtworkSize = 180
|
|
let cachedArtworkQuality: CGFloat = 0.5
|
|
|
|
static var shared = AlbumArtService()
|
|
var preferences = Preferences()
|
|
|
|
var session = URLSession(configuration: .default)
|
|
let cacheQueue = DispatchQueue(label: "albumArtCacheQueue", attributes: .concurrent)
|
|
|
|
func fetchAlbumArt(for album: AlbumItem, callback: @escaping (_ image: NSImage) -> Void) {
|
|
cacheQueue.async { [unowned self] in
|
|
if !self.getCachedArtwork(for: album, callback: callback) {
|
|
self.getArtworkFromFilesystem(for: album, callback: callback)
|
|
}
|
|
}
|
|
}
|
|
}
|