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

115 lines
2.7 KiB
Swift
Raw Normal View History

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