mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Use actual OS and kernel versions
This commit is contained in:
parent
65e48864a5
commit
111c7781d2
4 changed files with 54 additions and 16 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -1430,6 +1430,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"sha1",
|
||||
"shannon",
|
||||
"sysinfo",
|
||||
"thiserror",
|
||||
"time",
|
||||
"tokio",
|
||||
|
@ -1718,6 +1719,15 @@ dependencies = [
|
|||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.4.0"
|
||||
|
@ -2746,6 +2756,20 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sysinfo"
|
||||
version = "0.25.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71eb43e528fdc239f08717ec2a378fdb017dddbc3412de15fff527554591a66c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"ntapi",
|
||||
"once_cell",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "system-deps"
|
||||
version = "6.0.2"
|
||||
|
|
|
@ -47,6 +47,7 @@ serde = { version = "1.0", features = ["derive"] }
|
|||
serde_json = "1.0"
|
||||
sha1 = "0.10"
|
||||
shannon = "0.2"
|
||||
sysinfo = { version = "0.25", default-features = false }
|
||||
thiserror = "1.0"
|
||||
time = "0.3"
|
||||
tokio = { version = "1", features = ["io-util", "macros", "net", "parking_lot", "rt", "sync", "time"] }
|
||||
|
|
|
@ -11,6 +11,7 @@ use hyper::{
|
|||
use hyper_proxy::{Intercept, Proxy, ProxyConnector};
|
||||
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
|
||||
use once_cell::sync::OnceCell;
|
||||
use sysinfo::{System, SystemExt};
|
||||
use thiserror::Error;
|
||||
use url::Url;
|
||||
|
||||
|
@ -82,18 +83,24 @@ pub struct HttpClient {
|
|||
|
||||
impl HttpClient {
|
||||
pub fn new(proxy_url: Option<&Url>) -> Self {
|
||||
let spotify_platform = match OS {
|
||||
"android" => "Android/31",
|
||||
"ios" => "iOS/15.2.1",
|
||||
"macos" => "OSX/0",
|
||||
"windows" => "Win32/0",
|
||||
_ => "Linux/0",
|
||||
let zero_str = String::from("0");
|
||||
let os_version = System::new()
|
||||
.os_version()
|
||||
.unwrap_or_else(|| zero_str.clone());
|
||||
|
||||
let (spotify_platform, os_version) = match OS {
|
||||
"android" => ("Android", os_version),
|
||||
"ios" => ("iOS", os_version),
|
||||
"macos" => ("OSX", zero_str),
|
||||
"windows" => ("Win32", zero_str),
|
||||
_ => ("Linux", zero_str),
|
||||
};
|
||||
|
||||
let user_agent_str = &format!(
|
||||
"Spotify/{} {} ({})",
|
||||
"Spotify/{} {}/{} ({})",
|
||||
spotify_version(),
|
||||
spotify_platform,
|
||||
os_version,
|
||||
VERSION_STRING
|
||||
);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ use hyper::{
|
|||
use protobuf::{Message, ProtobufEnum};
|
||||
use rand::Rng;
|
||||
use sha1::{Digest, Sha1};
|
||||
use sysinfo::{System, SystemExt};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{
|
||||
|
@ -173,8 +174,15 @@ impl SpClient {
|
|||
|
||||
let platform_data = connectivity_data.mut_platform_specific_data();
|
||||
|
||||
let sys = System::new();
|
||||
let os_version = sys.os_version().unwrap_or_else(|| String::from("0"));
|
||||
let kernel_version = sys.kernel_version().unwrap_or_else(|| String::from("0"));
|
||||
|
||||
match std::env::consts::OS {
|
||||
"windows" => {
|
||||
let os_version = os_version.parse::<f32>().unwrap_or(10.) as i32;
|
||||
let kernel_version = kernel_version.parse::<i32>().unwrap_or(21370);
|
||||
|
||||
let (pe, image_file) = match std::env::consts::ARCH {
|
||||
"arm" => (448, 452),
|
||||
"aarch64" => (43620, 452),
|
||||
|
@ -183,8 +191,8 @@ impl SpClient {
|
|||
};
|
||||
|
||||
let windows_data = platform_data.mut_desktop_windows();
|
||||
windows_data.set_os_version(10);
|
||||
windows_data.set_os_build(21370);
|
||||
windows_data.set_os_version(os_version);
|
||||
windows_data.set_os_build(kernel_version);
|
||||
windows_data.set_platform_id(2);
|
||||
windows_data.set_unknown_value_6(9);
|
||||
windows_data.set_image_file_machine(image_file);
|
||||
|
@ -196,11 +204,11 @@ impl SpClient {
|
|||
ios_data.set_user_interface_idiom(0);
|
||||
ios_data.set_target_iphone_simulator(false);
|
||||
ios_data.set_hw_machine("iPhone14,5".to_string());
|
||||
ios_data.set_system_version("15.2.1".to_string());
|
||||
ios_data.set_system_version(os_version);
|
||||
}
|
||||
"android" => {
|
||||
let android_data = platform_data.mut_android();
|
||||
android_data.set_android_version("12.0.0_r26".to_string());
|
||||
android_data.set_android_version(os_version);
|
||||
android_data.set_api_version(31);
|
||||
android_data.set_device_name("Pixel".to_owned());
|
||||
android_data.set_model_str("GF5KQ".to_owned());
|
||||
|
@ -208,17 +216,15 @@ impl SpClient {
|
|||
}
|
||||
"macos" => {
|
||||
let macos_data = platform_data.mut_desktop_macos();
|
||||
macos_data.set_system_version("Darwin Kernel Version 17.7.0: Fri Oct 30 13:34:27 PDT 2020; root:xnu-4570.71.82.8~1/RELEASE_X86_64".to_string());
|
||||
macos_data.set_system_version(os_version);
|
||||
macos_data.set_hw_model("iMac21,1".to_string());
|
||||
macos_data.set_compiled_cpu_type(std::env::consts::ARCH.to_string());
|
||||
}
|
||||
_ => {
|
||||
let linux_data = platform_data.mut_desktop_linux();
|
||||
linux_data.set_system_name("Linux".to_string());
|
||||
linux_data.set_system_release("5.15.0-46-generic".to_string());
|
||||
linux_data.set_system_version(
|
||||
"#49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022".to_string(),
|
||||
);
|
||||
linux_data.set_system_release(kernel_version);
|
||||
linux_data.set_system_version(os_version);
|
||||
linux_data.set_hardware(std::env::consts::ARCH.to_string());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue