87 lines
2.7 KiB
Rust
87 lines
2.7 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use std::iter::zip;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Settings {
|
|
pub base_url: String,
|
|
pub hifi_url: String,
|
|
pub audio_quality: AudioQuality,
|
|
pub login: LoginConfig,
|
|
pub oauth: OauthConfig,
|
|
}
|
|
|
|
impl Default for Settings {
|
|
fn default() -> Self {
|
|
let client_id_key = b"abcdefghijklmnop";
|
|
let hidden_id_from_fulltext_search: &[u8] =
|
|
&[7, 58, 81, 46, 29, 2, 10, 6, 29, 48, 60, 39, 93, 7, 23, 36];
|
|
let mut client_id_bytes = Vec::new();
|
|
for (k, c) in zip(client_id_key, hidden_id_from_fulltext_search) {
|
|
client_id_bytes.push(*c ^ *k);
|
|
}
|
|
let client_id = String::from_utf8(client_id_bytes).unwrap();
|
|
|
|
let client_secret_key = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR";
|
|
let hidden_secret_from_fulltext_search: &[u8] = &[
|
|
80, 44, 14, 81, 36, 0, 35, 41, 3, 18, 25, 11, 39, 40, 37, 18, 58, 60, 36, 56, 16, 55,
|
|
14, 51, 62, 44, 6, 47, 10, 10, 48, 30, 23, 24, 5, 2, 29, 20, 12, 56, 55, 17, 54, 111,
|
|
];
|
|
let mut client_secret_bytes = Vec::new();
|
|
for (k, c) in zip(client_secret_key, hidden_secret_from_fulltext_search) {
|
|
client_secret_bytes.push(*c ^ *k);
|
|
}
|
|
let client_secret = String::from_utf8(client_secret_bytes).unwrap();
|
|
|
|
Self {
|
|
base_url: "https://api.tidal.com/v1".to_string(),
|
|
hifi_url: "https://api.tidalhifi.com/v1".to_string(),
|
|
audio_quality: AudioQuality::Lossless,
|
|
login: LoginConfig {
|
|
device_code: None,
|
|
user_id: None,
|
|
country_code: None,
|
|
access_token: None,
|
|
refresh_token: None,
|
|
expires_after: None,
|
|
},
|
|
oauth: OauthConfig {
|
|
client_id,
|
|
client_secret,
|
|
base_url: "https://auth.tidal.com/v1/oauth2".to_string(),
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct LoginConfig {
|
|
pub device_code: Option<String>,
|
|
pub user_id: Option<String>,
|
|
pub country_code: Option<String>,
|
|
pub access_token: Option<String>,
|
|
pub refresh_token: Option<String>,
|
|
pub expires_after: Option<u64>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub struct OauthConfig {
|
|
pub client_id: String,
|
|
pub client_secret: String,
|
|
pub base_url: String,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
pub enum AudioQuality {
|
|
Low,
|
|
High,
|
|
Lossless,
|
|
HiRes,
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum ConfigError {
|
|
#[error("failed to write config file")]
|
|
Write,
|
|
}
|