feat(aria2): 重构 download 函数并添加新功能
- 重构 download 函数,返回通知接收器以支持进度更新 - 新增 search 模块,实现关键词搜索功能 - 更新 single模块,增加音频格式判断- 引入日志模块,优化调试输出 - 新增特殊字符替换函数,用于文件名处理
This commit is contained in:
43
src/search.rs
Normal file
43
src/search.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use crate::utils::create_reqwest_client;
|
||||
use crate::ErrorString;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Search {
|
||||
pub result: SearchResult,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SearchResult {
|
||||
pub songs: Vec<SearchResultSong>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SearchResultSong {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
pub artists: Vec<SearchResultSongArtist>,
|
||||
pub duration: u64,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SearchResultSongArtist {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
pub async fn search(keyword: String) -> Result<Vec<SearchResultSong>, ErrorString> {
|
||||
let client = create_reqwest_client().await?;
|
||||
|
||||
let resp = client
|
||||
.get(format!(
|
||||
"https://163.genshinmc.eu.org/search?keywords={}&limit=20",
|
||||
urlencoding::encode(keyword.as_str())
|
||||
))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| format!("请求错误: {}", e))?;
|
||||
|
||||
let json: Search = resp.json().await.map_err(|e| format!("解析错误: {}", e))?;
|
||||
|
||||
Ok(json.result.songs)
|
||||
}
|
Reference in New Issue
Block a user