~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/hydraulophone

An unofficial YouTube Music app for iPhone, iPad, and Mac.

0
0
main
30 lines · 1.1 KB Raw History
import Foundation

/// This is an attributed, public protocol client key, not an account credential.
/// Bundling it keeps ordinary home-screen launches independent of shell state.
enum PublicPlaybackKey {
  static func load(
    bundle: Bundle = .main, environment: [String: String] = ProcessInfo.processInfo.environment
  )
    -> String?
  {
    if let override = environment["HYDRAULOPHONE_PUBLIC_JNN_KEY"],
      !override.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
    {
      return override
    }
    guard let url = bundle.url(forResource: "PublicJNNKey", withExtension: "txt"),
      let text = try? String(contentsOf: url, encoding: .utf8)
    else { return nil }
    let values = text.components(separatedBy: .newlines)
      .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
      .filter { !$0.isEmpty && !$0.hasPrefix("#") }
    guard values.count == 1, let key = values.first, key.utf8.count == 39,
      key.utf8.allSatisfy({
        (65...90).contains($0) || (97...122).contains($0) || (48...57).contains($0)
          || $0 == 45 || $0 == 95
      })
    else { return nil }
    return key
  }
}