mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 05:40:32 +05:30
35534bcbb1
- ThumbnailsModel optionally returns the quality - Have constants for 4:3 and 16:9 aspect ratio - Add high quality options for thumbnails - Rename Highest quality to Best quality - make 4:3 thumbnails fill the VideoCell - use .maxes instead of .maxresdefault (the latter sometimes returns white images) Signed-off-by: Toni Förster <toni.foerster@gmail.com>
47 lines
1.1 KiB
Swift
47 lines
1.1 KiB
Swift
import Defaults
|
|
import Foundation
|
|
|
|
final class ThumbnailsModel: ObservableObject {
|
|
static var shared = ThumbnailsModel()
|
|
|
|
@Published var unloadable = Set<URL>()
|
|
|
|
func insertUnloadable(_ url: URL) {
|
|
DispatchQueue.main.async {
|
|
self.unloadable.insert(url)
|
|
}
|
|
}
|
|
|
|
func isUnloadable(_ url: URL!) -> Bool {
|
|
guard !url.isNil else {
|
|
return true
|
|
}
|
|
|
|
return unloadable.contains(url)
|
|
}
|
|
|
|
func best(_ video: Video) -> (url: URL?, quality: Thumbnail.Quality?) {
|
|
for quality in availableQualitites {
|
|
let url = video.thumbnailURL(quality: quality)
|
|
if !isUnloadable(url) {
|
|
return (url, quality)
|
|
}
|
|
}
|
|
|
|
return (nil, nil)
|
|
}
|
|
|
|
private var availableQualitites: [Thumbnail.Quality] {
|
|
switch Defaults[.thumbnailsQuality] {
|
|
case .highest:
|
|
return [.maxres, .high, .medium, .default]
|
|
case .high:
|
|
return [.high, .medium, .default]
|
|
case .medium:
|
|
return [.medium, .default]
|
|
case .low:
|
|
return [.default]
|
|
}
|
|
}
|
|
}
|