mirror of
https://github.com/yattee/yattee.git
synced 2024-12-23 05:53:41 +00:00
Add tvOS streams selection
This commit is contained in:
parent
62e17d5a18
commit
0d1eaaca5c
@ -20,13 +20,13 @@ struct Instance: Defaults.Serializable, Hashable, Identifiable {
|
|||||||
let sid: String
|
let sid: String
|
||||||
let anonymous: Bool
|
let anonymous: Bool
|
||||||
|
|
||||||
init(id: String? = nil, instanceID: UUID, name: String? = nil, url: String, sid: String? = nil, anonymous: Bool = false) {
|
init(id: String? = nil, instanceID: UUID? = nil, name: String? = nil, url: String? = nil, sid: String? = nil, anonymous: Bool = false) {
|
||||||
self.anonymous = anonymous
|
self.anonymous = anonymous
|
||||||
|
|
||||||
self.id = id ?? (anonymous ? "anonymous-\(instanceID)" : UUID().uuidString)
|
self.id = id ?? (anonymous ? "anonymous-\(instanceID!)" : UUID().uuidString)
|
||||||
self.instanceID = instanceID
|
self.instanceID = instanceID ?? UUID()
|
||||||
self.name = name
|
self.name = name
|
||||||
self.url = url
|
self.url = url ?? ""
|
||||||
self.sid = sid ?? ""
|
self.sid = sid ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ final class InvidiousAPI: Service, ObservableObject {
|
|||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
guard !account.isNil else {
|
guard !account.isNil else {
|
||||||
|
self.account = .init(name: "Empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ extension PlayerModel {
|
|||||||
!stream.isNil && stream != streamSelection
|
!stream.isNil && stream != streamSelection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var availableStreamsSorted: [Stream] {
|
||||||
|
availableStreams.sorted(by: streamsSorter)
|
||||||
|
}
|
||||||
|
|
||||||
func loadAvailableStreams(
|
func loadAvailableStreams(
|
||||||
_ video: Video,
|
_ video: Video,
|
||||||
completionHandler: @escaping ([Stream]) -> Void = { _ in }
|
completionHandler: @escaping ([Stream]) -> Void = { _ in }
|
||||||
@ -97,4 +101,8 @@ extension PlayerModel {
|
|||||||
func streamsWithAssetsFromInstance(instance: Instance, streams: [Stream]) -> [Stream] {
|
func streamsWithAssetsFromInstance(instance: Instance, streams: [Stream]) -> [Stream] {
|
||||||
streams.map { stream in stream.withAssetsFrom(instance) }
|
streams.map { stream in stream.withAssetsFrom(instance) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func streamsSorter(_ lhs: Stream, _ rhs: Stream) -> Bool {
|
||||||
|
lhs.kind == rhs.kind ? (lhs.resolution.height > rhs.resolution.height) : (lhs.kind < rhs.kind)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,10 +78,12 @@ struct ContentView: View {
|
|||||||
func configure() {
|
func configure() {
|
||||||
SiestaLog.Category.enabled = .common
|
SiestaLog.Category.enabled = .common
|
||||||
|
|
||||||
if let account = instances.defaultAccount {
|
if let account = instances.defaultAccount ??
|
||||||
|
// TODO: Remove when piped supports videos information
|
||||||
|
accounts.all.first(where: { $0.instance.app == .invidious })
|
||||||
|
{
|
||||||
accounts.setAccount(account)
|
accounts.setAccount(account)
|
||||||
}
|
}
|
||||||
|
|
||||||
player.accounts = accounts
|
player.accounts = accounts
|
||||||
playlists.accounts = accounts
|
playlists.accounts = accounts
|
||||||
search.accounts = accounts
|
search.accounts = accounts
|
||||||
|
@ -139,14 +139,10 @@ struct PlaybackBar: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func availableStreamsForInstance(_ instance: Instance) -> [Stream.Kind: [Stream]] {
|
private func availableStreamsForInstance(_ instance: Instance) -> [Stream.Kind: [Stream]] {
|
||||||
let streams = player.availableStreams.filter { $0.instance == instance }.sorted(by: streamsSorter)
|
let streams = player.availableStreams.filter { $0.instance == instance }.sorted(by: player.streamsSorter)
|
||||||
|
|
||||||
return Dictionary(grouping: streams, by: \.kind!)
|
return Dictionary(grouping: streams, by: \.kind!)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func streamsSorter(_ lhs: Stream, _ rhs: Stream) -> Bool {
|
|
||||||
lhs.kind == rhs.kind ? (lhs.resolution.height > rhs.resolution.height) : (lhs.kind < rhs.kind)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PlaybackBar_Previews: PreviewProvider {
|
struct PlaybackBar_Previews: PreviewProvider {
|
||||||
|
@ -20,8 +20,37 @@ struct Player: UIViewControllerRepresentable {
|
|||||||
controller.playerModel = player
|
controller.playerModel = player
|
||||||
player.controller = controller
|
player.controller = controller
|
||||||
|
|
||||||
|
#if os(tvOS)
|
||||||
|
player.controller?.playerViewController.transportBarCustomMenuItems = [streamingQualityMenu]
|
||||||
|
#endif
|
||||||
|
|
||||||
return controller
|
return controller
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUIViewController(_: PlayerViewController, context _: Context) {}
|
func updateUIViewController(_: PlayerViewController, context _: Context) {
|
||||||
|
#if os(tvOS)
|
||||||
|
player.controller?.playerViewController.transportBarCustomMenuItems = [streamingQualityMenu]
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if os(tvOS)
|
||||||
|
var streamingQualityMenu: UIMenu {
|
||||||
|
UIMenu(
|
||||||
|
title: "Streaming quality",
|
||||||
|
image: UIImage(systemName: "antenna.radiowaves.left.and.right"),
|
||||||
|
children: streamingQualityMenuActions
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
var streamingQualityMenuActions: [UIAction] {
|
||||||
|
player.availableStreamsSorted.map { stream in
|
||||||
|
let image = player.streamSelection == stream ? UIImage(systemName: "checkmark") : nil
|
||||||
|
|
||||||
|
return UIAction(title: stream.description, image: image) { _ in
|
||||||
|
self.player.streamSelection = stream
|
||||||
|
self.player.upgradeToStream(stream)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ struct WatchNowView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.id(UUID())
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
.edgesIgnoringSafeArea(.horizontal)
|
.edgesIgnoringSafeArea(.horizontal)
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user