2021-06-17 22:43:29 +00:00
|
|
|
import CoreMedia
|
|
|
|
import Foundation
|
|
|
|
import SwiftyJSON
|
|
|
|
|
|
|
|
// swiftlint:disable:next final_class
|
|
|
|
class Segment: ObservableObject, Hashable {
|
|
|
|
let category: String
|
|
|
|
let segment: [Double]
|
|
|
|
let uuid: String
|
|
|
|
let videoDuration: Int
|
|
|
|
|
2021-06-18 10:17:01 +00:00
|
|
|
var start: Double {
|
|
|
|
segment.first!
|
|
|
|
}
|
|
|
|
|
|
|
|
var end: Double {
|
|
|
|
segment.last!
|
|
|
|
}
|
|
|
|
|
2022-02-16 20:23:11 +00:00
|
|
|
var duration: Double {
|
|
|
|
end - start
|
|
|
|
}
|
|
|
|
|
2022-06-18 12:39:49 +00:00
|
|
|
var durationText: String {
|
|
|
|
let formatter = NumberFormatter()
|
|
|
|
formatter.minimumFractionDigits = 0
|
|
|
|
formatter.maximumFractionDigits = 1
|
|
|
|
|
2022-06-26 11:57:02 +00:00
|
|
|
return formatter.string(from: NSNumber(value: duration.rounded())) ?? ""
|
2022-06-18 12:39:49 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 16:49:45 +00:00
|
|
|
var endTime: CMTime {
|
2022-06-14 21:20:19 +00:00
|
|
|
.secondsInDefaultTimescale(end)
|
2021-10-23 16:49:45 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 22:43:29 +00:00
|
|
|
init(category: String, segment: [Double], uuid: String, videoDuration: Int) {
|
|
|
|
self.category = category
|
|
|
|
self.segment = segment
|
|
|
|
self.uuid = uuid
|
|
|
|
self.videoDuration = videoDuration
|
|
|
|
}
|
|
|
|
|
|
|
|
func timeInSegment(_ time: CMTime) -> Bool {
|
2021-06-18 10:17:01 +00:00
|
|
|
(start ... end).contains(time.seconds)
|
2021-06-17 22:43:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(uuid)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func == (lhs: Segment, rhs: Segment) -> Bool {
|
|
|
|
lhs.uuid == rhs.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
func title() -> String {
|
|
|
|
category
|
|
|
|
}
|
|
|
|
}
|