yattee/Model/Playlist.swift

48 lines
1.2 KiB
Swift
Raw Normal View History

2021-06-26 09:39:35 +00:00
import Foundation
import SwiftyJSON
struct Playlist: Identifiable, Equatable, Hashable {
2021-07-22 12:43:13 +00:00
enum Visibility: String, CaseIterable, Identifiable {
case `public`, unlisted, `private`
var id: String {
rawValue
}
var name: String {
rawValue.capitalized
}
}
2021-06-26 09:39:35 +00:00
let id: String
var title: String
2021-07-22 12:43:13 +00:00
var visibility: Visibility
2021-06-26 09:39:35 +00:00
var updated: TimeInterval
2021-06-26 09:39:35 +00:00
var videos = [Video]()
init(id: String, title: String, visibility: Visibility, updated: TimeInterval) {
self.id = id
self.title = title
self.visibility = visibility
self.updated = updated
}
2021-06-26 09:39:35 +00:00
init(_ json: JSON) {
id = json["playlistId"].stringValue
title = json["title"].stringValue
2021-07-08 17:18:36 +00:00
visibility = json["isListed"].boolValue ? .public : .private
updated = json["updated"].doubleValue
2021-10-23 11:51:02 +00:00
videos = json["videos"].arrayValue.map { InvidiousAPI.extractVideo(from: $0) }
2021-06-26 09:39:35 +00:00
}
static func == (lhs: Playlist, rhs: Playlist) -> Bool {
lhs.id == rhs.id && lhs.updated == rhs.updated
2021-06-26 09:39:35 +00:00
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}