2021-10-24 22:26:25 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:53:43 +00:00
|
|
|
func best(_ video: Video) -> URL? {
|
2022-06-24 22:48:57 +00:00
|
|
|
let qualities = [Thumbnail.Quality.maxresdefault, .medium, .default]
|
2021-11-05 20:53:43 +00:00
|
|
|
|
|
|
|
for quality in qualities {
|
|
|
|
let url = video.thumbnailURL(quality: quality)
|
|
|
|
if !isUnloadable(url) {
|
|
|
|
return url
|
|
|
|
}
|
2021-10-24 22:26:25 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 20:53:43 +00:00
|
|
|
return nil
|
2021-10-24 22:26:25 +00:00
|
|
|
}
|
|
|
|
}
|