mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-12-05 15:41:56 +00:00
🎉 feat(music): improve filename generation and implement download progress logging
🐛 fix(music): update getFileExtension to always return 'flac' and remove unnecessary logging
This commit is contained in:
parent
27fed36558
commit
941c5a2cc6
@ -133,7 +133,8 @@ export class CrystelfMusic extends plugin {
|
|||||||
if (type === 'voice' || quality === 1) {
|
if (type === 'voice' || quality === 1) {
|
||||||
await Group.sendGroupRecord(e, e.group_id, `file://${audioFile}`, adapter);
|
await Group.sendGroupRecord(e, e.group_id, `file://${audioFile}`, adapter);
|
||||||
} else {
|
} else {
|
||||||
const filename = `${song.displayTitle} - ${song.displayArtist}.${(this.getFileExtension())}`;
|
const extension = await this.getFileExtension();
|
||||||
|
const filename = `${song.displayTitle} - ${song.displayArtist}.${extension}`;
|
||||||
await Group.sendGroupFile(e, e.group_id, `file://${audioFile}`, filename, adapter);
|
await Group.sendGroupFile(e, e.group_id, `file://${audioFile}`, filename, adapter);
|
||||||
}
|
}
|
||||||
musicSearch.clearUserSelection(e.group_id, e.user_id);
|
musicSearch.clearUserSelection(e.group_id, e.user_id);
|
||||||
@ -150,9 +151,9 @@ export class CrystelfMusic extends plugin {
|
|||||||
*/
|
*/
|
||||||
async getFileExtension() {
|
async getFileExtension() {
|
||||||
const musicConfig =await ConfigControl.get('music');
|
const musicConfig =await ConfigControl.get('music');
|
||||||
if(musicConfig.quality === 3){
|
//if(musicConfig.quality === '3'){
|
||||||
|
//return 'flac'
|
||||||
|
//}
|
||||||
return 'flac'
|
return 'flac'
|
||||||
}
|
}
|
||||||
return 'mp3'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -148,6 +148,10 @@ class AudioProcessor {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startTime = Date.now();
|
||||||
|
let lastProgressTime = startTime;
|
||||||
|
let lastProgressPercent = 0;
|
||||||
|
|
||||||
// download the file
|
// download the file
|
||||||
const response = await axios({
|
const response = await axios({
|
||||||
url,
|
url,
|
||||||
@ -156,6 +160,28 @@ class AudioProcessor {
|
|||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'crystelf-music/1.0'
|
'User-Agent': 'crystelf-music/1.0'
|
||||||
|
},
|
||||||
|
onDownloadProgress: (progressEvent) => {
|
||||||
|
const percentCompleted = Math.round(
|
||||||
|
(progressEvent.loaded * 100) / (progressEvent.total || 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
const currentTime = Date.now();
|
||||||
|
if (percentCompleted - lastProgressPercent >= 10 ||
|
||||||
|
currentTime - lastProgressTime >= 5000) {
|
||||||
|
const loadedSize = this.formatFileSize(progressEvent.loaded);
|
||||||
|
const totalSize = this.formatFileSize(progressEvent.total || 0);
|
||||||
|
const speed = this.formatFileSize(
|
||||||
|
(progressEvent.loaded * 1000) / (currentTime - startTime)
|
||||||
|
);
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`[crystelf-music] 下载进度: ${percentCompleted}% (${loadedSize}/${totalSize}) ` +
|
||||||
|
`速度: ${speed}/s - ${songInfo.displayTitle}`
|
||||||
|
);
|
||||||
|
lastProgressPercent = percentCompleted;
|
||||||
|
lastProgressTime = currentTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -168,7 +194,13 @@ class AudioProcessor {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const stats = fs.statSync(filePath);
|
const stats = fs.statSync(filePath);
|
||||||
logger.info(`[crystelf-music] 音频下载完成: ${filename} (${this.formatFileSize(stats.size)})`);
|
const downloadTime = (Date.now() - startTime) / 1000;
|
||||||
|
const avgSpeed = this.formatFileSize(stats.size / downloadTime);
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
`[crystelf-music] 音频下载完成: ${filename} (${this.formatFileSize(stats.size)}) ` +
|
||||||
|
`耗时: ${downloadTime.toFixed(1)}秒 平均速度: ${avgSpeed}/s`
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@ -105,7 +105,6 @@ class MusicApi {
|
|||||||
const songs = searchResult?.song || [];
|
const songs = searchResult?.song || [];
|
||||||
songs.sort((a, b) => b.score - a.score);
|
songs.sort((a, b) => b.score - a.score);
|
||||||
const topSongs = songs.slice(0, count);
|
const topSongs = songs.slice(0, count);
|
||||||
logger.info(topSongs);
|
|
||||||
return this.enhanceSearchResults(topSongs, query);
|
return this.enhanceSearchResults(topSongs, query);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('[crystelf-music] 搜索失败:', error.message);
|
logger.error('[crystelf-music] 搜索失败:', error.message);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user