1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30
yattee/Model/ThumbnailsModel.swift

43 lines
976 B
Swift
Raw Normal View History

2022-06-26 17:55:54 +05:30
import Defaults
2021-10-25 03:56:25 +05:30
import Foundation
final class ThumbnailsModel: ObservableObject {
static var shared = ThumbnailsModel()
2021-10-25 03:56:25 +05:30
@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-06 02:23:43 +05:30
func best(_ video: Video) -> URL? {
2022-06-26 17:55:54 +05:30
for quality in availableQualitites {
2021-11-06 02:23:43 +05:30
let url = video.thumbnailURL(quality: quality)
if !isUnloadable(url) {
return url
}
2021-10-25 03:56:25 +05:30
}
2021-11-06 02:23:43 +05:30
return nil
2021-10-25 03:56:25 +05:30
}
2022-06-26 17:55:54 +05:30
private var availableQualitites: [Thumbnail.Quality] {
switch Defaults[.thumbnailsQuality] {
case .highest:
return [.maxresdefault, .medium, .default]
case .medium:
return [.medium, .default]
case .low:
return [.default]
}
}
2021-10-25 03:56:25 +05:30
}