Channel playlists cache

This commit is contained in:
Arkadiusz Fal
2022-12-11 18:44:55 +01:00
parent 38593ed488
commit d4ec360581
6 changed files with 151 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
import Foundation
import SwiftyJSON
struct ChannelPlaylist: Identifiable {
var id: String = UUID().uuidString
@@ -7,4 +8,26 @@ struct ChannelPlaylist: Identifiable {
var channel: Channel?
var videos = [Video]()
var videosCount: Int?
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
)
}
}