1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30
yattee/Model/Player/PlayerQueueItem.swift

78 lines
2.0 KiB
Swift
Raw Normal View History

import AVFoundation
import Defaults
import Foundation
struct PlayerQueueItem: Hashable, Identifiable, Defaults.Serializable {
static let bridge = PlayerQueueItemBridge()
var id = UUID()
var video: Video!
var videoID: Video.ID
var app: VideosApp?
var instanceURL: URL?
var playbackTime: CMTime?
var videoDuration: TimeInterval?
static func from(_ watch: Watch, video: Video? = nil) -> Self {
.init(
video,
videoID: watch.videoID,
app: watch.app,
instanceURL: watch.instanceURL,
playbackTime: CMTime.secondsInDefaultTimescale(watch.stoppedAt),
videoDuration: watch.videoDuration
)
}
init(
2022-12-19 00:09:03 +05:30
_ video: Video? = .fixture,
videoID: Video.ID? = nil,
app: VideosApp? = nil,
instanceURL: URL? = nil,
playbackTime: CMTime? = nil,
videoDuration: TimeInterval? = nil
) {
self.video = video
self.videoID = videoID ?? video!.videoID
self.app = app
self.instanceURL = instanceURL
self.playbackTime = playbackTime
self.videoDuration = videoDuration
}
var duration: TimeInterval {
2022-02-28 02:01:17 +05:30
videoDuration ?? video?.length ?? .zero
}
var shouldRestartPlaying: Bool {
guard Defaults[.watchedVideoPlayNowBehavior] == .continue else { return true }
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])
}
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
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
var contentItem: ContentItem {
.init(video: contentItemVideo)
}
var contentItemVideo: Video {
video ?? Video(app: app ?? .invidious, instanceURL: instanceURL, videoID: videoID, length: videoDuration ?? 0)
}
}