2021-06-28 15:02:13 +00:00
|
|
|
import AVFoundation
|
|
|
|
import Defaults
|
|
|
|
import Foundation
|
2021-08-25 22:12:59 +00:00
|
|
|
import SwiftyJSON
|
2021-06-28 15:02:13 +00:00
|
|
|
|
2021-08-31 21:17:50 +00:00
|
|
|
struct Channel: Identifiable, Hashable {
|
2021-06-28 15:02:13 +00:00
|
|
|
var id: String
|
|
|
|
var name: String
|
2021-08-31 21:17:50 +00:00
|
|
|
var videos = [Video]()
|
|
|
|
|
|
|
|
private var subscriptionsCount: Int?
|
|
|
|
private var subscriptionsText: String?
|
2021-06-28 15:02:13 +00:00
|
|
|
|
2021-08-25 22:12:59 +00:00
|
|
|
init(json: JSON) {
|
|
|
|
id = json["authorId"].stringValue
|
|
|
|
name = json["author"].stringValue
|
2021-08-31 21:17:50 +00:00
|
|
|
subscriptionsCount = json["subCount"].int
|
|
|
|
subscriptionsText = json["subCountText"].string
|
|
|
|
|
|
|
|
if let channelVideos = json.dictionaryValue["latestVideos"] {
|
|
|
|
videos = channelVideos.arrayValue.map(Video.init)
|
|
|
|
}
|
2021-08-25 22:12:59 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 21:17:50 +00:00
|
|
|
init(id: String, name: String, subscriptionsCount: Int? = nil, videos: [Video] = []) {
|
2021-08-25 22:12:59 +00:00
|
|
|
self.id = id
|
|
|
|
self.name = name
|
|
|
|
self.subscriptionsCount = subscriptionsCount
|
2021-08-31 21:17:50 +00:00
|
|
|
self.videos = videos
|
|
|
|
}
|
|
|
|
|
|
|
|
var subscriptionsString: String? {
|
|
|
|
if subscriptionsCount != nil {
|
|
|
|
return subscriptionsCount!.formattedAsAbbreviation()
|
|
|
|
}
|
|
|
|
|
|
|
|
return subscriptionsText
|
|
|
|
}
|
|
|
|
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(id)
|
2021-06-28 15:02:13 +00:00
|
|
|
}
|
|
|
|
}
|