From c3613ac8d7bc8042988dc18d0b7709b4c133a451 Mon Sep 17 00:00:00 2001 From: betta Date: Sun, 21 Feb 2021 21:22:59 +0800 Subject: [PATCH] update code --- Cargo.toml | 4 ++-- src/api.rs | 2 +- src/player/fetch.rs | 12 ++++++------ src/player/player.rs | 15 +++++++++------ 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8d912af..6174e89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "netease_music_tui" -version = "0.1.2" +version = "0.1.3" authors = ["betta "] license = "MIT" keywords = ["netease", "player", "music", "tui"] @@ -33,7 +33,7 @@ simple-logging = "2.0.2" log = "0.4" log-panics = "2.0.0" dirs = "2.0.2" -rodio = { version = "0.10.0", features = ["mp3"] } +rodio = { version = "0.13.0", features = ["mp3"] } tempfile = "3.1.0" tokio = { version = "0.2", features = ["macros"] } futures = "0.3.1" diff --git a/src/api.rs b/src/api.rs index 466fde5..0d4ebd9 100644 --- a/src/api.rs +++ b/src/api.rs @@ -151,7 +151,7 @@ impl CloudMusic { .unwrap(), ); headers.insert(HOST, "music.163.com".parse().unwrap()); - headers.insert(ACCEPT_ENCODING, "gzip,deflate,br".parse().unwrap()); + headers.insert(ACCEPT_ENCODING, "gzip,deflate".parse().unwrap()); match method { Method::POST => { diff --git a/src/player/fetch.rs b/src/player/fetch.rs index 2f57f35..a85153f 100644 --- a/src/player/fetch.rs +++ b/src/player/fetch.rs @@ -1,6 +1,6 @@ use std::io::prelude::*; use futures::channel::oneshot::Sender; -use reqwest::header::{CACHE_CONTROL, PRAGMA, HeaderMap, UPGRADE_INSECURE_REQUESTS, ACCEPT, ACCEPT_ENCODING, USER_AGENT}; +use reqwest::header::{HOST, CACHE_CONTROL, PRAGMA, HeaderMap, UPGRADE_INSECURE_REQUESTS, ACCEPT, ACCEPT_ENCODING, USER_AGENT}; use reqwest::Method; use tempfile::NamedTempFile; @@ -14,9 +14,9 @@ pub async fn fetch_data(url: &str, buffer: NamedTempFile, tx: Sender) -> headers.insert(CACHE_CONTROL, "no-cache".parse().unwrap()); headers.insert(PRAGMA, "no-cache".parse().unwrap()); headers.insert(UPGRADE_INSECURE_REQUESTS, "1".parse().unwrap()); - // headers.insert(HOST, "m701.music.126.net".parse().unwrap()); + headers.insert(HOST, "m7.music.126.net".parse().unwrap()); headers.insert(ACCEPT, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3".parse().unwrap()); - headers.insert(ACCEPT_ENCODING, "gzip,deflate,br".parse().unwrap()); + headers.insert(ACCEPT_ENCODING, "gzip,deflate".parse().unwrap()); headers.insert( USER_AGENT, "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0".parse().unwrap(), @@ -28,9 +28,9 @@ pub async fn fetch_data(url: &str, buffer: NamedTempFile, tx: Sender) -> let builder = client.request(Method::GET, url).headers(headers); let mut res = builder.send().await?; - // debug!("start download"); + debug!("start download"); if let Some(chunk) = res.chunk().await? { - // debug!("first chunk"); + debug!("first chunk"); buffer.write(&chunk[..]).unwrap(); send_msg(tx); } @@ -39,7 +39,7 @@ pub async fn fetch_data(url: &str, buffer: NamedTempFile, tx: Sender) -> // bytes buffer.write(&chunk[..]).unwrap(); } - // debug!("finish downloa"); + debug!("finish downloa"); Ok(()) } diff --git a/src/player/player.rs b/src/player/player.rs index 313c618..ab8db80 100644 --- a/src/player/player.rs +++ b/src/player/player.rs @@ -32,7 +32,7 @@ pub enum PlayerState { pub struct Player { // commands: Option>, - endpoint: rodio::Device, + // endpoint: rodio::Device, pub state: PlayerState, pub current: Option, pub sink: rodio::Sink, @@ -48,15 +48,17 @@ impl Player { // where // F: FnOnce() -> Box + Send + 'static, { - let endpoint = - rodio::default_output_device().expect("Failed to find default music endpoint"); - let sink = rodio::Sink::new(&endpoint); + let (stream, stream_handle) = rodio::OutputStream::try_default().unwrap(); + let sink = rodio::Sink::try_new(&stream_handle).unwrap(); + // let endpoint = + // rodio::default_output_device().expect("Failed to find default music endpoint"); + // let sink = rodio::Sink::new(&endpoint); Player { state: PlayerState::Stopped, current: None, sink: sink, - endpoint: endpoint, + // endpoint: endpoint, } } @@ -80,6 +82,7 @@ impl Player { let buffer = NamedTempFile::new().unwrap(); let path = buffer.path().to_string_lossy().to_string(); + debug!("{:#?}", path); let pathbuf = PathBuf::from(path); let (ptx, mut prx) = oneshot::channel::(); @@ -128,7 +131,7 @@ impl Player { pub fn start(&mut self) { let vol = self.sink.volume(); self.sink.stop(); - self.sink = rodio::Sink::new(&self.endpoint); + // self.sink = rodio::Sink::new(&self.endpoint); self.set_volume(vol); }