yattee/Model/Thumbnail.swift

54 lines
1.3 KiB
Swift
Raw Normal View History

2021-07-07 22:39:18 +00:00
import Foundation
import SwiftyJSON
struct Thumbnail {
2021-07-22 12:43:13 +00:00
enum Quality: String, CaseIterable {
case maxres, maxresdefault, sddefault, high, medium, `default`, start, middle, end
2021-10-20 22:21:50 +00:00
var filename: String {
switch self {
case .maxres:
return "maxres"
case .maxresdefault:
return "maxresdefault"
case .sddefault:
return "sddefault"
case .high:
return "hqdefault"
case .medium:
return "mqdefault"
case .default:
return "default"
case .start:
return "1"
case .middle:
return "2"
case .end:
return "3"
}
}
2021-07-22 12:43:13 +00:00
}
2021-07-07 22:39:18 +00:00
var url: URL
2021-07-22 12:43:13 +00:00
var quality: Quality
2021-07-07 22:39:18 +00:00
2021-07-22 12:43:13 +00:00
init(url: URL, quality: Quality) {
self.url = url
self.quality = quality
2021-07-07 22:39:18 +00:00
}
2022-12-10 00:23:13 +00:00
var json: JSON {
[
"url": url.absoluteString,
"quality": quality.rawValue
]
}
static func from(_ json: JSON) -> Self {
.init(
url: URL(string: json["url"].stringValue)!,
quality: .init(rawValue: json["quality"].stringValue) ?? .default
)
}
2021-07-07 22:39:18 +00:00
}