2021-10-06 01:50:09 +05:30
|
|
|
import AVFoundation
|
2021-10-24 23:31:08 +05:30
|
|
|
import Defaults
|
2021-10-06 01:50:09 +05:30
|
|
|
import Foundation
|
|
|
|
|
2021-10-24 23:31:08 +05:30
|
|
|
struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable {
|
|
|
|
static let bridge = PlayerQueueItemBridge()
|
|
|
|
|
2021-10-06 01:50:09 +05:30
|
|
|
var id = UUID()
|
2021-10-24 23:31:08 +05:30
|
|
|
var video: Video!
|
|
|
|
var videoID: Video.ID
|
2022-12-13 05:08:26 +05:30
|
|
|
var app: VideosApp?
|
|
|
|
var instanceURL: URL?
|
2021-10-23 02:19:31 +05:30
|
|
|
var playbackTime: CMTime?
|
|
|
|
var videoDuration: TimeInterval?
|
2021-10-06 01:50:09 +05:30
|
|
|
|
2021-12-27 02:44:46 +05:30
|
|
|
static func from(_ watch: Watch, video: Video? = nil) -> Self {
|
|
|
|
.init(
|
|
|
|
video,
|
|
|
|
videoID: watch.videoID,
|
2022-12-13 05:08:26 +05:30
|
|
|
app: watch.app,
|
|
|
|
instanceURL: watch.instanceURL,
|
2021-12-27 02:44:46 +05:30
|
|
|
playbackTime: CMTime.secondsInDefaultTimescale(watch.stoppedAt),
|
|
|
|
videoDuration: watch.videoDuration
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-12-13 05:08:26 +05:30
|
|
|
init(
|
2022-12-19 00:09:03 +05:30
|
|
|
_ video: Video? = .fixture,
|
2022-12-13 05:08:26 +05:30
|
|
|
videoID: Video.ID? = nil,
|
|
|
|
app: VideosApp? = nil,
|
|
|
|
instanceURL: URL? = nil,
|
|
|
|
playbackTime: CMTime? = nil,
|
|
|
|
videoDuration: TimeInterval? = nil
|
|
|
|
) {
|
2021-10-06 01:50:09 +05:30
|
|
|
self.video = video
|
2021-10-24 23:31:08 +05:30
|
|
|
self.videoID = videoID ?? video!.videoID
|
2022-12-13 05:08:26 +05:30
|
|
|
self.app = app
|
|
|
|
self.instanceURL = instanceURL
|
2021-10-23 02:19:31 +05:30
|
|
|
self.playbackTime = playbackTime
|
|
|
|
self.videoDuration = videoDuration
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
var duration: TimeInterval {
|
2022-02-28 02:01:17 +05:30
|
|
|
videoDuration ?? video?.length ?? .zero
|
2021-10-23 02:19:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
var shouldRestartPlaying: Bool {
|
2022-08-29 21:28:26 +05:30
|
|
|
guard Defaults[.watchedVideoPlayNowBehavior] == .continue else { return true }
|
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
guard let seconds = playbackTime?.seconds else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-11-13 04:37:23 +05:30
|
|
|
if duration <= 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-11-19 18:41:04 +05:30
|
|
|
return (seconds / duration) * 100 > Double(Defaults[.watchedThreshold])
|
2021-10-23 02:19:31 +05:30
|
|
|
}
|
|
|
|
|
2022-06-26 16:42:32 +05:30
|
|
|
var hasDetailsLoaded: Bool {
|
2022-11-10 22:41:28 +05:30
|
|
|
guard let video else { return false }
|
|
|
|
return !video.streams.isEmpty
|
2022-06-26 16:42:32 +05:30
|
|
|
}
|
|
|
|
|
2021-10-23 02:19:31 +05:30
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(id)
|
|
|
|
}
|
2021-10-06 01:50:09 +05:30
|
|
|
}
|