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