Files
netease-downloader/src/search.rs
GenshinMinecraft 0cec957b34 feat(aria2): 重构 download 函数并添加新功能
- 重构 download 函数,返回通知接收器以支持进度更新
- 新增 search 模块,实现关键词搜索功能
- 更新 single模块,增加音频格式判断- 引入日志模块,优化调试输出
- 新增特殊字符替换函数,用于文件名处理
2025-08-19 10:06:04 +08:00

44 lines
1.1 KiB
Rust

use crate::ErrorString;
use crate::utils::create_reqwest_client;
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)
}