Yandex Music client for Apple TV
tvOS 17+ SwiftUI client for the unofficial Yandex Music API: rotor stations with feedback, library, search, artist and album pages, synced lyrics, and system Now Playing integration.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import CryptoKit
|
||||
import Foundation
|
||||
|
||||
enum Crypto {
|
||||
/// md5 hex digest, used by the legacy `download-info` signing scheme.
|
||||
static func md5Hex(_ string: String) -> String {
|
||||
let digest = Insecure.MD5.hash(data: Data(string.utf8))
|
||||
return digest.map { String(format: "%02x", $0) }.joined()
|
||||
}
|
||||
|
||||
/// base64(hmac-sha256(key, message)).
|
||||
///
|
||||
/// `get-file-info` wants the trailing "=" padding stripped; the lyrics
|
||||
/// endpoint wants it kept.
|
||||
static func hmacSHA256Base64(message: String, key: String, stripPadding: Bool = true) -> String {
|
||||
let mac = HMAC<SHA256>.authenticationCode(
|
||||
for: Data(message.utf8),
|
||||
using: SymmetricKey(data: Data(key.utf8))
|
||||
)
|
||||
let encoded = Data(mac).base64EncodedString()
|
||||
return stripPadding ? encoded.replacingOccurrences(of: "=", with: "") : encoded
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import Foundation
|
||||
import Security
|
||||
|
||||
/// Tiny keychain wrapper for the single secret we keep: the OAuth token.
|
||||
enum Keychain {
|
||||
private static let service = "com.yamusek.tv.oauth"
|
||||
|
||||
static func set(_ value: String?, for account: String) {
|
||||
let query: [String: Any] = [
|
||||
kSecClass as String: kSecClassGenericPassword,
|
||||
kSecAttrService as String: service,
|
||||
kSecAttrAccount as String: account,
|
||||
]
|
||||
SecItemDelete(query as CFDictionary)
|
||||
guard let value, !value.isEmpty else { return }
|
||||
var add = query
|
||||
add[kSecValueData as String] = Data(value.utf8)
|
||||
add[kSecAttrAccessible as String] = kSecAttrAccessibleAfterFirstUnlock
|
||||
SecItemAdd(add as CFDictionary, nil)
|
||||
}
|
||||
|
||||
static func get(_ account: String) -> String? {
|
||||
let query: [String: Any] = [
|
||||
kSecClass as String: kSecClassGenericPassword,
|
||||
kSecAttrService as String: service,
|
||||
kSecAttrAccount as String: account,
|
||||
kSecReturnData as String: true,
|
||||
kSecMatchLimit as String: kSecMatchLimitOne,
|
||||
]
|
||||
var item: CFTypeRef?
|
||||
guard SecItemCopyMatching(query as CFDictionary, &item) == errSecSuccess,
|
||||
let data = item as? Data else { return nil }
|
||||
return String(data: data, encoding: .utf8)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import Foundation
|
||||
import os
|
||||
|
||||
let log = Logger(subsystem: "com.yamusek.tv", category: "app")
|
||||
Reference in New Issue
Block a user