Add option to disable proxying video streams for Invidious

This commit is contained in:
Arkadiusz Fal 2022-07-21 23:52:09 +02:00
parent 6ce9ed3063
commit 827c64719c
7 changed files with 42 additions and 12 deletions

View File

@ -9,13 +9,15 @@ struct Instance: Defaults.Serializable, Hashable, Identifiable {
let name: String let name: String
let apiURL: String let apiURL: String
var frontendURL: String? var frontendURL: String?
var proxiesVideos: Bool
init(app: VideosApp, id: String? = nil, name: String, apiURL: String, frontendURL: String? = nil) { init(app: VideosApp, id: String? = nil, name: String, apiURL: String, frontendURL: String? = nil, proxiesVideos: Bool = false) {
self.app = app self.app = app
self.id = id ?? UUID().uuidString self.id = id ?? UUID().uuidString
self.name = name self.name = name
self.apiURL = apiURL self.apiURL = apiURL
self.frontendURL = frontendURL self.frontendURL = frontendURL
self.proxiesVideos = proxiesVideos
} }
var anonymous: VideosAPI { var anonymous: VideosAPI {

View File

@ -15,7 +15,8 @@ struct InstancesBridge: Defaults.Bridge {
"id": value.id, "id": value.id,
"name": value.name, "name": value.name,
"apiURL": value.apiURL, "apiURL": value.apiURL,
"frontendURL": value.frontendURL ?? "" "frontendURL": value.frontendURL ?? "",
"proxiesVideos": value.proxiesVideos ? "true" : "false"
] ]
} }
@ -30,8 +31,9 @@ struct InstancesBridge: Defaults.Bridge {
} }
let name = object["name"] ?? "" let name = object["name"] ?? ""
let frontendURL: String? = object["frontendURL"]!.isEmpty ? nil : object["frontendURL"] let frontendURL: String? = object["frontendURL"]!.isEmpty ? nil : object["frontendURL"]
return Instance(app: app, id: id, name: name, apiURL: apiURL, frontendURL: frontendURL) let proxiesVideos = object["proxiesVideos"] == "true"
return Instance(app: app, id: id, name: name, apiURL: apiURL, frontendURL: frontendURL, proxiesVideos: proxiesVideos)
} }
} }

View File

@ -52,6 +52,17 @@ final class InstancesModel: ObservableObject {
} }
} }
static func setProxiesVideos(_ instance: Instance, _ proxiesVideos: Bool) {
guard let index = Defaults[.instances].firstIndex(where: { $0.id == instance.id }) else {
return
}
var instance = Defaults[.instances][index]
instance.proxiesVideos = proxiesVideos
Defaults[.instances][index] = instance
}
static func remove(_ instance: Instance) { static func remove(_ instance: Instance) {
let accounts = Self.accounts(instance.id) let accounts = Self.accounts(instance.id)
if let index = Defaults[.instances].firstIndex(where: { $0.id == instance.id }) { if let index = Defaults[.instances].firstIndex(where: { $0.id == instance.id }) {

View File

@ -58,4 +58,8 @@ enum VideosApp: String, CaseIterable {
var supportsOpeningChannelsByName: Bool { var supportsOpeningChannelsByName: Bool {
self == .piped self == .piped
} }
var allowsDisablingVidoesProxying: Bool {
self == .invidious
}
} }

View File

@ -57,7 +57,7 @@ extension PlayerModel {
streams.map { stream in streams.map { stream in
stream.instance = instance stream.instance = instance
if instance.app == .invidious { if instance.app == .invidious, instance.proxiesVideos {
if let audio = stream.audioAsset { if let audio = stream.audioAsset {
stream.audioAsset = InvidiousAPI.proxiedAsset(instance: instance, asset: audio) stream.audioAsset = InvidiousAPI.proxiedAsset(instance: instance, asset: audio)
} }

View File

@ -6,7 +6,7 @@ struct AccountsNavigationLink: View {
var body: some View { var body: some View {
NavigationLink(instance.longDescription) { NavigationLink(instance.longDescription) {
InstanceSettings(instanceID: instance.id) InstanceSettings(instance: instance)
} }
.buttonStyle(.plain) .buttonStyle(.plain)
.contextMenu { .contextMenu {

View File

@ -1,22 +1,19 @@
import SwiftUI import SwiftUI
struct InstanceSettings: View { struct InstanceSettings: View {
let instanceID: Instance.ID? let instance: Instance
@State private var accountsChanged = false @State private var accountsChanged = false
@State private var presentingAccountForm = false @State private var presentingAccountForm = false
@State private var frontendURL = "" @State private var frontendURL = ""
@State private var proxiesVideos = false
var instance: Instance! {
InstancesModel.find(instanceID)
}
var body: some View { var body: some View {
List { List {
Section(header: Text("Accounts")) { Section(header: Text("Accounts")) {
if instance.app.supportsAccounts { if instance.app.supportsAccounts {
ForEach(InstancesModel.accounts(instanceID), id: \.self) { account in ForEach(InstancesModel.accounts(instance.id), id: \.self) { account in
#if os(tvOS) #if os(tvOS)
Button(account.description) {} Button(account.description) {}
.contextMenu { .contextMenu {
@ -80,6 +77,16 @@ struct InstanceSettings: View {
.keyboardType(.URL) .keyboardType(.URL)
} }
} }
if instance.app.allowsDisablingVidoesProxying {
proxiesVideosToggle
.onAppear {
proxiesVideos = instance.proxiesVideos
}
.onChange(of: proxiesVideos) { newValue in
InstancesModel.setProxiesVideos(instance, newValue)
}
}
} }
#if os(tvOS) #if os(tvOS)
.frame(maxWidth: 1000) .frame(maxWidth: 1000)
@ -90,6 +97,10 @@ struct InstanceSettings: View {
.navigationTitle(instance.description) .navigationTitle(instance.description)
} }
private var proxiesVideosToggle: some View {
Toggle("Proxy videos", isOn: $proxiesVideos)
}
private func removeAccount(_ account: Account) { private func removeAccount(_ account: Account) {
AccountsModel.remove(account) AccountsModel.remove(account)
accountsChanged.toggle() accountsChanged.toggle()