1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30
yattee/Model/ThumbnailsModel.swift
2022-10-27 18:03:57 +02:00

41 lines
933 B
Swift

import Defaults
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? {
for quality in availableQualitites {
let url = video.thumbnailURL(quality: quality)
if !isUnloadable(url) {
return url
}
}
return nil
}
private var availableQualitites: [Thumbnail.Quality] {
switch Defaults[.thumbnailsQuality] {
case .highest:
return [.maxresdefault, .medium, .default]
case .medium:
return [.medium, .default]
case .low:
return [.default]
}
}
}