Skip to content

Commit

Permalink
[fix] incorrect client initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
chiyuki0325 committed Sep 19, 2024
1 parent 5b55409 commit 0a83bab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lyric_providers/netease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use serde_json::{
from_str as from_json_str,
};
use std::time::Duration;
use isahc::HttpClient;
use isahc::prelude::Configurable;
use crate::lyric_parser::{
LyricLine,
parse_netease_lyrics,
Expand All @@ -19,7 +21,14 @@ impl NeteaseLyricProvider {
metadata: &Metadata,
config: crate::config::SharedConfig,
) -> (Vec<LyricLine>, bool) {
let ncm_api = ncm_api::MusicApi::new(0);
let client = HttpClient::builder()
.timeout(Duration::from_secs(
config.read().unwrap().online_search_timeout
))
.cookies()
.build()
.expect("初始化网络请求失败!");
let ncm_api = ncm_api::MusicApi::from_client(client);
let title = metadata.title().unwrap_or_default().to_string();
let artist = metadata.artists().unwrap_or_default().get(0).unwrap_or(&"").to_string();
let search_result = ncm_api.search(
Expand Down
1 change: 1 addition & 0 deletions src/lyric_providers/netease_trackid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl NeteaseTrackIDLyricProvider {
let mut success = !config.read().unwrap().online_search_retry;
#[allow(unused_assignments)]
while !success {
println!("Trying to get lyric for track_id: {}", music_id);
let lyric_result = ncm_api.song_lyric(music_id).await;
if let Ok(lyric_result) = lyric_result {
success = true;
Expand Down

0 comments on commit 0a83bab

Please sign in to comment.