Skip to main content

ncm_api_rs/api/
cloud_import.rs

1use super::Query;
2use crate::error::Result;
3/// 云盘导入歌曲
4/// 对应 Node.js module/cloud_import.js
5use crate::request::{ApiClient, ApiResponse, CryptoType};
6use serde_json::json;
7
8impl ApiClient {
9    /// 云盘导入歌曲 - 检查
10    /// 对应 /cloud/import(检查步骤)
11    pub async fn cloud_import_check(&self, query: &Query) -> Result<ApiResponse> {
12        let songs = json!([{
13            "md5": query.get_or("md5", ""),
14            "songId": query.get_or("id", "-2").parse::<i64>().unwrap_or(-2),
15            "bitrate": query.get_or("bitrate", ""),
16            "fileSize": query.get_or("fileSize", "")
17        }]);
18        let data = json!({
19            "uploadType": 0,
20            "songs": songs.to_string()
21        });
22        self.request(
23            "/api/cloud/upload/check/v2",
24            data,
25            query.to_option(CryptoType::default()),
26        )
27        .await
28    }
29
30    /// 云盘导入歌曲 - 导入
31    /// 对应 /cloud/import(导入步骤)
32    pub async fn cloud_import(&self, query: &Query) -> Result<ApiResponse> {
33        let song_name = query.get_or("song", "");
34        let file_type = query.get_or("fileType", "mp3");
35        let songs = json!([{
36            "songId": query.get_or("songId", ""),
37            "bitrate": query.get_or("bitrate", ""),
38            "song": &song_name,
39            "artist": query.get_or("artist", "未知"),
40            "album": query.get_or("album", "未知"),
41            "fileName": format!("{}.{}", song_name, file_type)
42        }]);
43        let data = json!({
44            "uploadType": 0,
45            "songs": songs.to_string()
46        });
47        self.request(
48            "/api/cloud/user/song/import",
49            data,
50            query.to_option(CryptoType::default()),
51        )
52        .await
53    }
54}