Files
yattee/Model/Accounts/Instance.swift
Arkadiusz Fal b0dfd2f9d2 Add experimental setting to hide videos without duration in Invidious
This adds a new instance setting for Invidious that filters out videos
without duration information from feeds, popular, trending, search results,
and channel pages. This can be used to hide YouTube Shorts.

The setting is labeled as "Experimental: Hide videos without duration" and
includes an explanation that it can be used to hide shorts.

Key changes:
- Added hideVideosWithoutDuration property to Instance model
- Updated InstancesBridge to serialize/deserialize the new setting
- Added UI toggle in InstanceSettings with explanatory footer text
- Implemented filtering in InvidiousAPI for:
  * Popular videos
  * Trending videos
  * Search results
  * Subscription feed
  * Channel content
- Videos accessed directly by URL are not filtered
2025-11-22 19:42:18 +01:00

80 lines
2.3 KiB
Swift

import Defaults
import Foundation
struct Instance: Defaults.Serializable, Hashable, Identifiable {
static var bridge = InstancesBridge()
let app: VideosApp
let id: String
let name: String
let apiURLString: String
var frontendURL: String?
var proxiesVideos: Bool
var invidiousCompanion: Bool
var hideVideosWithoutDuration: Bool
init(app: VideosApp, id: String? = nil, name: String? = nil, apiURLString: String, frontendURL: String? = nil, proxiesVideos: Bool = false, invidiousCompanion: Bool = false, hideVideosWithoutDuration: Bool = false) {
self.app = app
self.id = id ?? UUID().uuidString
self.name = name ?? app.rawValue
self.apiURLString = apiURLString
self.frontendURL = frontendURL
self.proxiesVideos = proxiesVideos
self.invidiousCompanion = invidiousCompanion
self.hideVideosWithoutDuration = hideVideosWithoutDuration
}
var apiURL: URL! {
URL(string: apiURLString)
}
var anonymous: VideosAPI! {
switch app {
case .invidious:
return InvidiousAPI(account: anonymousAccount)
case .piped:
return PipedAPI(account: anonymousAccount)
case .peerTube:
return PeerTubeAPI(account: anonymousAccount)
case .local:
return nil
}
}
var description: String {
"\(app.name) - \(shortDescription)"
}
var longDescription: String {
name.isEmpty ? "\(app.name) - \(apiURLString)" : "\(app.name) - \(name) (\(apiURLString))"
}
var shortDescription: String {
name.isEmpty ? apiURLString : name
}
var anonymousAccount: Account {
Account(instanceID: id, name: "Anonymous".localized(), urlString: apiURLString, anonymous: true)
}
var urlComponents: URLComponents {
URLComponents(url: apiURL, resolvingAgainstBaseURL: false)!
}
var frontendHost: String? {
guard let url = app == .invidious ? apiURLString : frontendURL else {
return nil
}
return URLComponents(string: url)?.host
}
func hash(into hasher: inout Hasher) {
hasher.combine(apiURL)
}
var accounts: [Account] {
AccountsModel.shared.all.filter { $0.instanceID == id }
}
}