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

38 lines
995 B
Swift
Raw Permalink 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 { $0.json.object },
"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
}