(
metadata: SongInfo | undefined,
destPath: string
)
| 1121 | "kugou", |
| 1122 | "migu", |
| 1123 | "netease", |
| 1124 | "ytmusic", |
| 1125 | ]; |
| 1126 | const BASE = "https://music-api.gdstudio.xyz/api.php"; |
| 1127 | |
| 1128 | const hasArtist = !!metadata.artist && metadata.artist !== "Unknown Artist"; |
| 1129 | const query = hasArtist |
| 1130 | ? `${metadata.artist} ${metadata.title}` |
| 1131 | : `${metadata.title}`; |
| 1132 | |
| 1133 | for (const source of COVER_SOURCES) { |
| 1134 | try { |
| 1135 | const searchUrl = `${BASE}?types=search&source=${source}&name=${encodeURIComponent( |
| 1136 | query |
| 1137 | )}&count=10&pages=1`; |
| 1138 | const res = await HttpClient.makeRequest(searchUrl, { method: "GET" }); |
| 1139 | if (res.status !== 200 || !res.data) continue; |
| 1140 | |
| 1141 | let list: any[] = []; |
| 1142 | if (Array.isArray(res.data)) list = res.data; |
| 1143 | else if (Array.isArray(res.data.result)) list = res.data.result; |
| 1144 | else if (Array.isArray(res.data.data)) list = res.data.data; |
| 1145 | if (!list.length) continue; |
| 1146 | |
| 1147 | const lowerTitle = String(metadata.title).toLowerCase(); |
| 1148 | const lowerArtist = String(metadata.artist || "").toLowerCase(); |
| 1149 | let best: any = null; |
| 1150 | if (hasArtist) { |
| 1151 | best = list.find( |
| 1152 | (it: any) => |
| 1153 | String(it?.name || "").toLowerCase().includes(lowerTitle) && |
| 1154 | String(it?.artist || "").toLowerCase().includes(lowerArtist) |
| 1155 | ); |
| 1156 | } else { |
| 1157 | best = list.find((it: any) => |
| 1158 | String(it?.name || "").toLowerCase().includes(lowerTitle) |
| 1159 | ); |
| 1160 | } |
| 1161 | best = best || list[0]; |
| 1162 | const picId = String(best?.pic_id || ""); |
| 1163 | if (!picId) continue; |
| 1164 | |
| 1165 | // 获取封面URL |
| 1166 | const picUrlApi = `${BASE}?types=pic&source=${encodeURIComponent( |
| 1167 | source |
| 1168 | )}&id=${encodeURIComponent(picId)}&size=500`; |
| 1169 | const picRes = await HttpClient.makeRequest(picUrlApi, { method: "GET" }); |
| 1170 | if (picRes.status !== 200 || !picRes.data) continue; |
| 1171 | let picUrl = ""; |
| 1172 | if (typeof picRes.data === "string") { |
| 1173 | picUrl = picRes.data; |
| 1174 | } else if ( |
| 1175 | picRes.data && |
| 1176 | (picRes.data.url || picRes.data.pic || picRes.data.image) |
| 1177 | ) { |
| 1178 | picUrl = picRes.data.url || picRes.data.pic || picRes.data.image; |
| 1179 | } |
| 1180 | if (!picUrl) continue; |
no test coverage detected