1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 05:40:32 +05:30
yattee/Model/ChannelPlaylist.swift

38 lines
991 B
Swift
Raw Normal View History

2021-10-23 04:34:03 +05:30
import Foundation
2022-12-11 23:14:55 +05:30
import SwiftyJSON
2021-10-23 04:34:03 +05:30
struct ChannelPlaylist: Identifiable {
2022-12-17 01:07:05 +05:30
var id: String
2021-10-23 04:34:03 +05:30
var title: String
var thumbnailURL: URL?
var channel: Channel?
var videos = [Video]()
var videosCount: Int?
2022-12-11 23:14:55 +05:30
2022-12-17 01:07:05 +05:30
var cacheKey: String {
"channelplaylists-\(id)"
}
2022-12-11 23:14:55 +05:30
var json: JSON {
[
"id": id,
"title": title,
"thumbnailURL": thumbnailURL?.absoluteString ?? "",
"channel": channel?.json.object ?? "",
"videos": videos.map(\.json.object),
2022-12-11 23:14:55 +05:30
"videosCount": String(videosCount ?? 0)
]
}
static func from(_ json: JSON) -> Self {
2023-04-22 18:38:33 +05:30
Self(
2022-12-11 23:14:55 +05:30
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-23 04:34:03 +05:30
}