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 {
|
2022-09-26 21:00:59 +05:30
|
|
|
rawValue.capitalized.localized()
|
2021-07-22 18:13:13 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2022-09-12 20:53:20 +05:30
|
|
|
var editable = true
|
2021-06-26 15:09:35 +05:30
|
|
|
|
2022-04-10 20:37:10 +05:30
|
|
|
var updated: TimeInterval?
|
2021-07-09 20:23:53 +05:30
|
|
|
|
2021-06-26 15:09:35 +05:30
|
|
|
var videos = [Video]()
|
|
|
|
|
2022-12-11 22:34:39 +05:30
|
|
|
init(
|
|
|
|
id: String,
|
|
|
|
title: String,
|
|
|
|
visibility: Visibility,
|
|
|
|
editable: Bool = true,
|
|
|
|
updated: TimeInterval? = nil,
|
|
|
|
videos: [Video] = []
|
|
|
|
) {
|
2021-08-16 21:22:42 +05:30
|
|
|
self.id = id
|
|
|
|
self.title = title
|
|
|
|
self.visibility = visibility
|
2022-09-12 20:53:20 +05:30
|
|
|
self.editable = editable
|
2021-08-16 21:22:42 +05:30
|
|
|
self.updated = updated
|
2021-12-17 22:09:26 +05:30
|
|
|
self.videos = videos
|
2021-08-16 21:22:42 +05:30
|
|
|
}
|
|
|
|
|
2022-12-11 22:34:39 +05:30
|
|
|
var json: JSON {
|
2022-12-16 17:01:43 +05:30
|
|
|
[
|
2022-12-11 22:34:39 +05:30
|
|
|
"id": id,
|
|
|
|
"title": title,
|
|
|
|
"visibility": visibility.rawValue,
|
|
|
|
"editable": editable ? "editable" : "",
|
|
|
|
"updated": updated ?? "",
|
|
|
|
"videos": videos.map(\.json).map(\.object)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
static func from(_ json: JSON) -> Self {
|
2022-12-16 17:01:43 +05:30
|
|
|
.init(
|
2022-12-11 22:34:39 +05:30
|
|
|
id: json["id"].stringValue,
|
|
|
|
title: json["title"].stringValue,
|
|
|
|
visibility: .init(rawValue: json["visibility"].stringValue) ?? .public,
|
|
|
|
updated: json["updated"].doubleValue,
|
|
|
|
videos: json["videos"].arrayValue.map { Video.from($0) }
|
|
|
|
)
|
2021-06-26 15:09:35 +05:30
|
|
|
}
|
|
|
|
|
2023-06-17 17:39:51 +05:30
|
|
|
static func == (lhs: Self, rhs: Self) -> 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)
|
|
|
|
}
|
2022-12-11 23:14:55 +05:30
|
|
|
|
|
|
|
var channelPlaylist: ChannelPlaylist {
|
|
|
|
ChannelPlaylist(id: id, title: title, videos: videos, videosCount: videos.count)
|
|
|
|
}
|
2021-06-26 15:09:35 +05:30
|
|
|
}
|