2021-06-18 04:13:29 +05:30
|
|
|
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 15:47:01 +05:30
|
|
|
var start: Double {
|
|
|
|
segment.first!
|
|
|
|
}
|
|
|
|
|
|
|
|
var end: Double {
|
|
|
|
segment.last!
|
|
|
|
}
|
|
|
|
|
2022-02-17 01:53:11 +05:30
|
|
|
var duration: Double {
|
|
|
|
end - start
|
|
|
|
}
|
|
|
|
|
2022-06-18 18:09:49 +05:30
|
|
|
var durationText: String {
|
|
|
|
let formatter = NumberFormatter()
|
|
|
|
formatter.minimumFractionDigits = 0
|
|
|
|
formatter.maximumFractionDigits = 1
|
|
|
|
|
2022-06-26 17:27:02 +05:30
|
|
|
return formatter.string(from: NSNumber(value: duration.rounded())) ?? ""
|
2022-06-18 18:09:49 +05:30
|
|
|
}
|
|
|
|
|
2021-10-23 22:19:45 +05:30
|
|
|
var endTime: CMTime {
|
2022-06-15 02:50:19 +05:30
|
|
|
.secondsInDefaultTimescale(end)
|
2021-10-23 22:19:45 +05:30
|
|
|
}
|
|
|
|
|
2021-06-18 04:13:29 +05:30
|
|
|
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 15:47:01 +05:30
|
|
|
(start ... end).contains(time.seconds)
|
2021-06-18 04:13:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(uuid)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func == (lhs: Segment, rhs: Segment) -> Bool {
|
|
|
|
lhs.uuid == rhs.uuid
|
|
|
|
}
|
|
|
|
|
|
|
|
func title() -> String {
|
|
|
|
category
|
|
|
|
}
|
|
|
|
}
|