yattee/Model/ChannelPlaylist.swift

38 lines
1006 B
Swift
Raw Normal View History

2021-10-22 23:04:03 +00:00
import Foundation
2022-12-11 17:44:55 +00:00
import SwiftyJSON
2021-10-22 23:04:03 +00:00
struct ChannelPlaylist: Identifiable {
2022-12-16 19:37:05 +00:00
var id: String
2021-10-22 23:04:03 +00:00
var title: String
var thumbnailURL: URL?
var channel: Channel?
var videos = [Video]()
var videosCount: Int?
2022-12-11 17:44:55 +00:00
2022-12-16 19:37:05 +00:00
var cacheKey: String {
"channelplaylists-\(id)"
}
2022-12-11 17:44:55 +00:00
var json: JSON {
[
"id": id,
"title": title,
"thumbnailURL": thumbnailURL?.absoluteString ?? "",
"channel": channel?.json.object ?? "",
"videos": videos.map { $0.json.object },
"videosCount": String(videosCount ?? 0)
]
}
static func from(_ json: JSON) -> Self {
ChannelPlaylist(
id: json["id"].stringValue,
title: json["title"].stringValue,
thumbnailURL: json["thumbnailURL"].url,
channel: Channel.from(json["channel"]),
videos: json["videos"].arrayValue.map { Video.from($0) },
videosCount: json["videosCount"].int
)
}
2021-10-22 23:04:03 +00:00
}