geesawra.industries/hydraulophone
An unofficial YouTube Music app for iPhone, iPad, and Mac.
0
0
import Foundation
/// The ephemeral inputs needed to turn a ciphered player format into a native
/// media URL. The player script is supplied by the transport boundary so a
/// solver never needs to perform an untrusted or credential-bearing fetch.
///
/// `signature` is nil for a direct URL that only needs an `n` transformation.
/// Values in this request must remain in memory for the duration of the
/// decipher operation. In particular, neither the URL nor the player script
/// is suitable for persistence or diagnostics.
public struct PlayerStreamCipherRequest: Sendable, Equatable {
public let url: URL
/// The `s` signature for a ciphered format. This is nil for a direct URL
/// whose `n` query value still needs the player transformation.
public let signature: String?
public let signatureParameter: String
public let n: String?
public let playerScript: String
public init(
url: URL,
signature: String?,
signatureParameter: String = "sig",
n: String? = nil,
playerScript: String
) {
self.url = url
self.signature = signature
self.signatureParameter = signatureParameter.isEmpty ? "sig" : signatureParameter
self.n = n
self.playerScript = playerScript
}
}
enum PlayerStreamCipherStage: String, Sendable {
case script
case decipher
}
public enum PlayerStreamCipherError: String, Error, LocalizedError, Equatable, Sendable {
case unsupported
case invalidScript
case invalidCipher
case invalidResult
public var errorDescription: String? {
switch self {
case .unsupported:
return "No local player stream decipherer is available."
case .invalidScript:
return "The player script could not be used for stream deciphering."
case .invalidCipher:
return "The player stream cipher was not valid."
case .invalidResult:
return "The deciphered stream URL was not valid."
}
}
}
/// Deciphers one player format without owning transport, authentication, or
/// playback policy. Implementations must be cancellation-aware and return only
/// an ephemeral URL; callers reapply `InnerTubeMediaURLPolicy` before probing
/// or handing the URL to AVPlayer.
public protocol PlayerStreamCipher: Sendable {
func decipher(_ request: PlayerStreamCipherRequest) async throws -> URL
}
public protocol PlayerStreamCipherPreparing: Sendable {
func prepare(playerScript: String) async throws
}