mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 05:53:41 +00:00
Fix player instance setting (fix #260)
This commit is contained in:
parent
16d96b8ad2
commit
bca909aab6
@ -509,6 +509,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
||||
}
|
||||
|
||||
return SingleAssetStream(
|
||||
instance: account.instance,
|
||||
avAsset: AVURLAsset(url: streamURL),
|
||||
resolution: Stream.Resolution.from(resolution: stream["resolution"].string ?? ""),
|
||||
kind: .stream,
|
||||
@ -538,6 +539,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
||||
}
|
||||
|
||||
return Stream(
|
||||
instance: account.instance,
|
||||
audioAsset: AVURLAsset(url: audioAssetURL),
|
||||
videoAsset: AVURLAsset(url: videoAssetURL),
|
||||
resolution: Stream.Resolution.from(resolution: videoStream["resolution"].stringValue),
|
||||
@ -550,7 +552,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
|
||||
|
||||
private func extractHLSStreams(from content: JSON) -> [Stream] {
|
||||
if let hlsURL = content.dictionaryValue["hlsUrl"]?.url {
|
||||
return [Stream(hlsURL: hlsURL)]
|
||||
return [Stream(instance: account.instance, hlsURL: hlsURL)]
|
||||
}
|
||||
|
||||
return []
|
||||
|
@ -517,7 +517,7 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
|
||||
var streams = [Stream]()
|
||||
|
||||
if let hlsURL = content.dictionaryValue["hls"]?.url {
|
||||
streams.append(Stream(hlsURL: hlsURL))
|
||||
streams.append(Stream(instance: account.instance, hlsURL: hlsURL))
|
||||
}
|
||||
|
||||
let audioStreams = content
|
||||
@ -560,6 +560,7 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
|
||||
if videoOnly {
|
||||
streams.append(
|
||||
Stream(
|
||||
instance: account.instance,
|
||||
audioAsset: audioAsset,
|
||||
videoAsset: videoAsset,
|
||||
resolution: resolution,
|
||||
@ -569,7 +570,12 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
|
||||
)
|
||||
} else {
|
||||
streams.append(
|
||||
SingleAssetStream(avAsset: videoAsset, resolution: resolution, kind: .stream)
|
||||
SingleAssetStream(
|
||||
instance: account.instance,
|
||||
avAsset: videoAsset,
|
||||
resolution: resolution,
|
||||
kind: .stream
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ final class CommentsModel: ObservableObject {
|
||||
|
||||
firstPage = page.isNil || page!.isEmpty
|
||||
|
||||
player.accounts.api.comments(video.videoID, page: page)?
|
||||
player.playerAPI.comments(video.videoID, page: page)?
|
||||
.load()
|
||||
.onSuccess { [weak self] response in
|
||||
if let page: CommentsPage = response.typedContent() {
|
||||
|
@ -13,7 +13,7 @@ extension PlayerModel {
|
||||
return
|
||||
}
|
||||
|
||||
accounts.api.video(id).load().onSuccess { [weak self] response in
|
||||
playerAPI.video(id).load().onSuccess { [weak self] response in
|
||||
guard let video: Video = response.typedContent() else {
|
||||
return
|
||||
}
|
||||
|
@ -651,7 +651,7 @@ final class PlayerModel: ObservableObject {
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.accounts.api.loadDetails(item, completionHandler: { newItem in
|
||||
self.playerAPI.loadDetails(item, completionHandler: { newItem in
|
||||
guard newItem.videoID == self.autoplayItem?.videoID else { return }
|
||||
self.autoplayItem = newItem
|
||||
self.updateRemoteCommandCenter()
|
||||
|
@ -56,20 +56,32 @@ extension PlayerModel {
|
||||
preservedTime = currentItem.playbackTime
|
||||
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let video = self?.currentVideo else {
|
||||
guard let self = self else { return }
|
||||
guard let video = self.currentVideo else {
|
||||
return
|
||||
}
|
||||
self?.videoBeingOpened = nil
|
||||
|
||||
if video.streams.isEmpty {
|
||||
self?.loadAvailableStreams(video)
|
||||
self.videoBeingOpened = nil
|
||||
|
||||
guard let playerInstance = self.playerInstance else { return }
|
||||
let streamsInstance = video.streams.compactMap(\.instance).first
|
||||
|
||||
if video.streams.isEmpty || streamsInstance != playerInstance {
|
||||
self.loadAvailableStreams(video)
|
||||
} else {
|
||||
guard let instance = self?.accounts.current?.instance ?? InstancesModel.forPlayer ?? InstancesModel.all.first else { return }
|
||||
self?.availableStreams = self?.streamsWithInstance(instance: instance, streams: video.streams) ?? video.streams
|
||||
self.availableStreams = self.streamsWithInstance(instance: playerInstance, streams: video.streams)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var playerInstance: Instance? {
|
||||
InstancesModel.forPlayer ?? accounts.current?.instance ?? InstancesModel.all.first
|
||||
}
|
||||
|
||||
var playerAPI: VideosAPI {
|
||||
playerInstance?.anonymous ?? accounts.api
|
||||
}
|
||||
|
||||
var qualityProfile: QualityProfile? {
|
||||
qualityProfileSelection ?? QualityProfilesModel.shared.automaticProfile
|
||||
}
|
||||
@ -135,7 +147,7 @@ extension PlayerModel {
|
||||
currentItem.playbackTime = time
|
||||
|
||||
let playTime = currentItem.shouldRestartPlaying ? CMTime.zero : time
|
||||
accounts.api.loadDetails(currentItem, failureHandler: videoLoadFailureHandler) { newItem in
|
||||
playerAPI.loadDetails(currentItem, failureHandler: videoLoadFailureHandler) { newItem in
|
||||
self.playItem(newItem, at: playTime)
|
||||
}
|
||||
}
|
||||
@ -178,7 +190,7 @@ extension PlayerModel {
|
||||
}
|
||||
|
||||
if loadDetails {
|
||||
accounts.api.loadDetails(item, failureHandler: videoLoadFailureHandler) { [weak self] newItem in
|
||||
playerAPI.loadDetails(item, failureHandler: videoLoadFailureHandler) { [weak self] newItem in
|
||||
guard let self = self else { return }
|
||||
videoDetailsLoadHandler(newItem.video, newItem)
|
||||
|
||||
@ -239,7 +251,7 @@ extension PlayerModel {
|
||||
func loadQueueVideoDetails(_ item: PlayerQueueItem) {
|
||||
guard !accounts.current.isNil, !item.hasDetailsLoaded else { return }
|
||||
|
||||
accounts.api.loadDetails(item, completionHandler: { newItem in
|
||||
playerAPI.loadDetails(item, completionHandler: { newItem in
|
||||
if let index = self.queue.firstIndex(where: { $0.id == item.id }) {
|
||||
self.queue[index] = newItem
|
||||
}
|
||||
|
@ -18,13 +18,10 @@ extension PlayerModel {
|
||||
func loadAvailableStreams(_ video: Video) {
|
||||
availableStreams = []
|
||||
|
||||
guard let playerInstance = InstancesModel.forPlayer ?? InstancesModel.all.first else {
|
||||
return
|
||||
}
|
||||
guard let playerInstance = playerInstance else { return }
|
||||
|
||||
logger.info("loading streams from \(playerInstance.description)")
|
||||
|
||||
fetchStreams(playerInstance.anonymous.video(video.videoID), instance: playerInstance, video: video)
|
||||
fetchStreams(playerAPI.video(video.videoID), instance: playerInstance, video: video)
|
||||
}
|
||||
|
||||
private func fetchStreams(
|
||||
|
@ -4,9 +4,9 @@ import Foundation
|
||||
final class SingleAssetStream: Stream {
|
||||
var avAsset: AVURLAsset
|
||||
|
||||
init(avAsset: AVURLAsset, resolution: Resolution, kind: Kind, encoding: String = "") {
|
||||
init(instance: Instance? = nil, avAsset: AVURLAsset, resolution: Resolution, kind: Kind, encoding: String = "") {
|
||||
self.avAsset = avAsset
|
||||
|
||||
super.init(audioAsset: avAsset, videoAsset: avAsset, resolution: resolution, kind: kind, encoding: encoding)
|
||||
super.init(instance: instance, audioAsset: avAsset, videoAsset: avAsset, resolution: resolution, kind: kind, encoding: encoding)
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ struct OpenURLHandler {
|
||||
Windows.main.open()
|
||||
#endif
|
||||
|
||||
accounts.api.video(id)
|
||||
player.playerAPI.video(id)
|
||||
.load()
|
||||
.onSuccess { response in
|
||||
if let video: Video = response.typedContent() {
|
||||
|
@ -27,7 +27,7 @@ struct ShareButton: View {
|
||||
|
||||
private var instanceActions: some View {
|
||||
Group {
|
||||
if let url = accounts.api.shareURL(contentItem) {
|
||||
if let url = player.playerAPI.shareURL(contentItem) {
|
||||
Button(labelForShareURL(accounts.app.name)) {
|
||||
shareAction(url)
|
||||
}
|
||||
@ -35,7 +35,7 @@ struct ShareButton: View {
|
||||
if contentItemIsPlayerCurrentVideo {
|
||||
Button(labelForShareURL(accounts.app.name, withTime: true)) {
|
||||
shareAction(
|
||||
accounts.api.shareURL(
|
||||
player.playerAPI.shareURL(
|
||||
contentItem,
|
||||
time: player.backend.currentTime
|
||||
)!
|
||||
|
Loading…
Reference in New Issue
Block a user