1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30
yattee/Model/Thumbnail.swift

54 lines
1.3 KiB
Swift
Raw Normal View History

2021-07-08 04:09:18 +05:30
import Foundation
import SwiftyJSON
struct Thumbnail {
2021-07-22 18:13:13 +05:30
enum Quality: String, CaseIterable {
case maxres, maxresdefault, sddefault, high, medium, `default`, start, middle, end
2021-10-21 03:51:50 +05:30
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 18:13:13 +05:30
}
2021-07-08 04:09:18 +05:30
var url: URL
2021-07-22 18:13:13 +05:30
var quality: Quality
2021-07-08 04:09:18 +05:30
2021-07-22 18:13:13 +05:30
init(url: URL, quality: Quality) {
self.url = url
self.quality = quality
2021-07-08 04:09:18 +05:30
}
2022-12-10 05:53:13 +05:30
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-08 04:09:18 +05:30
}