Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
betta-cyber committed Feb 21, 2021
1 parent e55818c commit c3613ac
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "netease_music_tui"
version = "0.1.2"
version = "0.1.3"
authors = ["betta <[email protected]>"]
license = "MIT"
keywords = ["netease", "player", "music", "tui"]
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
12 changes: 6 additions & 6 deletions src/player/fetch.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,9 +14,9 @@ pub async fn fetch_data(url: &str, buffer: NamedTempFile, tx: Sender<String>) ->
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(),
Expand All @@ -28,9 +28,9 @@ pub async fn fetch_data(url: &str, buffer: NamedTempFile, tx: Sender<String>) ->
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);
}
Expand All @@ -39,7 +39,7 @@ pub async fn fetch_data(url: &str, buffer: NamedTempFile, tx: Sender<String>) ->
// bytes
buffer.write(&chunk[..]).unwrap();
}
// debug!("finish downloa");
debug!("finish downloa");
Ok(())
}

Expand Down
15 changes: 9 additions & 6 deletions src/player/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub enum PlayerState {

pub struct Player {
// commands: Option<std::sync::mpsc::Sender<PlayerCommand>>,
endpoint: rodio::Device,
// endpoint: rodio::Device,
pub state: PlayerState,
pub current: Option<Track>,
pub sink: rodio::Sink,
Expand All @@ -48,15 +48,17 @@ impl Player {
// where
// F: FnOnce() -> Box<dyn Sink> + 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,
}
}

Expand All @@ -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::<String>();
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit c3613ac

Please sign in to comment.