mirror of
https://github.com/yattee/yattee.git
synced 2024-12-15 23:00:32 +05:30
31 lines
675 B
Swift
31 lines
675 B
Swift
import Foundation
|
|
|
|
final class ThumbnailsModel: ObservableObject {
|
|
@Published var unloadable = Set<URL>()
|
|
|
|
func insertUnloadable(_ url: URL) {
|
|
unloadable.insert(url)
|
|
}
|
|
|
|
func isUnloadable(_ url: URL!) -> Bool {
|
|
guard !url.isNil else {
|
|
return true
|
|
}
|
|
|
|
return unloadable.contains(url)
|
|
}
|
|
|
|
func best(_ video: Video) -> URL? {
|
|
let qualities = [Thumbnail.Quality.maxresdefault, .medium, .default]
|
|
|
|
for quality in qualities {
|
|
let url = video.thumbnailURL(quality: quality)
|
|
if !isUnloadable(url) {
|
|
return url
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|