-
Notifications
You must be signed in to change notification settings - Fork 822
Expand file tree
/
Copy pathconfig.rs
More file actions
129 lines (118 loc) · 3.66 KB
/
config.rs
File metadata and controls
129 lines (118 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use std::path::PathBuf;
use clap::ValueEnum;
use librespot_protocol::devices::DeviceType as ProtoDeviceType;
use serde::{Deserialize, Serialize};
use url::Url;
pub(crate) const KEYMASTER_CLIENT_ID: &str = "65b708073fc0480ea92a077233ca87bd";
pub(crate) const ANDROID_CLIENT_ID: &str = "9a8d2f0ce77a4e248bb71fefcb557637";
pub(crate) const IOS_CLIENT_ID: &str = "58bd3c95768941ea9eb4350aaa033eb3";
// Easily adjust the current platform to mock the behavior on it. If for example
// android or ios needs to be mocked, the `os_version` has to be set to a valid version.
// Otherwise, client-token or login5 requests will fail with a generic invalid-credential error.
/// See [std::env::consts::OS]
pub const OS: &str = std::env::consts::OS;
// valid versions for some os:
// 'android': 30
// 'ios': 17
/// See [sysinfo::System::os_version]
pub fn os_version() -> String {
sysinfo::System::os_version().unwrap_or("0".into())
}
#[derive(Clone, Debug)]
pub struct SessionConfig {
pub client_id: String,
pub device_id: String,
pub proxy: Option<Url>,
pub ap_port: Option<u16>,
pub tmp_dir: PathBuf,
pub autoplay: Option<bool>,
}
impl Default for SessionConfig {
fn default() -> Self {
Self::default_for_os(OS)
}
}
impl SessionConfig {
pub(crate) fn default_for_os(os: &str) -> Self {
let client_id = match os {
"android" => ANDROID_CLIENT_ID,
"ios" => IOS_CLIENT_ID,
_ => KEYMASTER_CLIENT_ID,
}
.to_owned();
let device_id = uuid::Uuid::new_v4().as_hyphenated().to_string();
Self {
client_id,
device_id,
proxy: None,
ap_port: None,
tmp_dir: std::env::temp_dir(),
autoplay: None,
}
}
}
#[derive(
Clone,
Copy,
Debug,
Hash,
PartialOrd,
Ord,
PartialEq,
Eq,
Default,
ValueEnum,
Serialize,
Deserialize,
)]
#[clap(rename_all = "lower")]
pub enum DeviceType {
Unknown = 0,
Computer = 1,
Tablet = 2,
Smartphone = 3,
#[default]
Speaker = 4,
Tv = 5,
Avr = 6,
Stb = 7,
AudioDongle = 8,
GameConsole = 9,
CastAudio = 10,
CastVideo = 11,
Automobile = 12,
Smartwatch = 13,
Chromebook = 14,
UnknownSpotify = 100,
CarThing = 101,
Observer = 102,
}
impl From<DeviceType> for String {
fn from(value: DeviceType) -> Self {
format!("{value:?}")
}
}
impl From<DeviceType> for ProtoDeviceType {
fn from(value: DeviceType) -> Self {
match value {
DeviceType::Unknown => ProtoDeviceType::UNKNOWN,
DeviceType::Computer => ProtoDeviceType::COMPUTER,
DeviceType::Tablet => ProtoDeviceType::TABLET,
DeviceType::Smartphone => ProtoDeviceType::SMARTPHONE,
DeviceType::Speaker => ProtoDeviceType::SPEAKER,
DeviceType::Tv => ProtoDeviceType::TV,
DeviceType::Avr => ProtoDeviceType::AVR,
DeviceType::Stb => ProtoDeviceType::STB,
DeviceType::AudioDongle => ProtoDeviceType::AUDIO_DONGLE,
DeviceType::GameConsole => ProtoDeviceType::GAME_CONSOLE,
DeviceType::CastAudio => ProtoDeviceType::CAST_VIDEO,
DeviceType::CastVideo => ProtoDeviceType::CAST_AUDIO,
DeviceType::Automobile => ProtoDeviceType::AUTOMOBILE,
DeviceType::Smartwatch => ProtoDeviceType::SMARTWATCH,
DeviceType::Chromebook => ProtoDeviceType::CHROMEBOOK,
DeviceType::UnknownSpotify => ProtoDeviceType::UNKNOWN_SPOTIFY,
DeviceType::CarThing => ProtoDeviceType::CAR_THING,
DeviceType::Observer => ProtoDeviceType::OBSERVER,
}
}
}