yattee/Model/Video.swift

103 lines
2.4 KiB
Swift
Raw Normal View History

2021-06-10 22:50:10 +00:00
import Alamofire
2021-06-14 18:05:02 +00:00
import AVKit
2021-06-10 22:50:10 +00:00
import Foundation
import SwiftyJSON
struct Video: Identifiable, Equatable, Hashable {
2021-06-10 22:50:10 +00:00
let id: String
let videoID: String
2021-06-10 22:50:10 +00:00
var title: String
2021-07-07 22:39:18 +00:00
var thumbnails: [Thumbnail]
2021-06-10 22:50:10 +00:00
var author: String
2021-06-11 00:05:59 +00:00
var length: TimeInterval
var published: String
var views: Int
2021-10-20 22:21:50 +00:00
var description: String?
var genre: String?
2021-06-11 21:11:59 +00:00
2021-07-22 12:43:13 +00:00
// index used when in the Playlist
let indexID: String?
2021-07-22 12:43:13 +00:00
var live: Bool
var upcoming: Bool
2021-06-14 18:05:02 +00:00
var streams = [Stream]()
2021-07-22 12:43:13 +00:00
2021-08-22 19:13:33 +00:00
var publishedAt: Date?
var likes: Int?
var dislikes: Int?
var keywords = [String]()
2021-08-25 22:12:59 +00:00
var channel: Channel
2021-07-22 12:43:13 +00:00
init(
id: String? = nil,
videoID: String,
2021-07-22 12:43:13 +00:00
title: String,
author: String,
length: TimeInterval,
published: String,
views: Int,
2021-10-20 22:21:50 +00:00
description: String? = nil,
genre: String? = nil,
2021-08-25 22:12:59 +00:00
channel: Channel,
2021-07-22 12:43:13 +00:00
thumbnails: [Thumbnail] = [],
indexID: String? = nil,
live: Bool = false,
2021-08-22 19:13:33 +00:00
upcoming: Bool = false,
publishedAt: Date? = nil,
likes: Int? = nil,
dislikes: Int? = nil,
2021-10-20 22:21:50 +00:00
keywords: [String] = [],
streams: [Stream] = []
2021-07-22 12:43:13 +00:00
) {
self.id = id ?? UUID().uuidString
self.videoID = videoID
2021-07-22 12:43:13 +00:00
self.title = title
self.author = author
self.length = length
self.published = published
self.views = views
self.description = description
self.genre = genre
2021-08-25 22:12:59 +00:00
self.channel = channel
2021-07-22 12:43:13 +00:00
self.thumbnails = thumbnails
self.indexID = indexID
self.live = live
self.upcoming = upcoming
2021-08-22 19:13:33 +00:00
self.publishedAt = publishedAt
self.likes = likes
self.dislikes = dislikes
self.keywords = keywords
2021-10-20 22:21:50 +00:00
self.streams = streams
2021-07-22 12:43:13 +00:00
}
2021-06-10 22:50:10 +00:00
2021-07-22 12:43:13 +00:00
var publishedDate: String? {
(published.isEmpty || published == "0 seconds ago") ? nil : published
}
2021-08-22 19:13:33 +00:00
var viewsCount: String? {
views != 0 ? views.formattedAsAbbreviation() : nil
2021-08-22 19:13:33 +00:00
}
var likesCount: String? {
likes?.formattedAsAbbreviation()
2021-08-22 19:13:33 +00:00
}
var dislikesCount: String? {
dislikes?.formattedAsAbbreviation()
2021-06-11 00:05:59 +00:00
}
2021-06-14 18:05:02 +00:00
2021-07-22 12:43:13 +00:00
func thumbnailURL(quality: Thumbnail.Quality) -> URL? {
2021-10-24 21:36:24 +00:00
thumbnails.first { $0.quality == quality }?.url
2021-07-07 22:39:18 +00:00
}
2021-06-14 18:05:02 +00:00
static func == (lhs: Video, rhs: Video) -> Bool {
lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
2021-06-10 22:50:10 +00:00
}