mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-03-21 11:03:15 +00:00
feat(cloud): 添加音频元数据解析功能
- 集成 jsmediatags 库用于解析音频文件的 ID3 标签 - 实现 parseMediaTags 函数提取歌曲标题、艺术家和专辑信息 - 在上传前添加音频元数据解析步骤 - 将解析的元数据传递给 completeUpload 函数 - 使用元数据中的标题作为歌曲名称,提高准确性 - 添加默认值处理以防止解析失败 - 更新 completeUpload 函数接收文件对象和媒体标签参数 - 移除模块中不再使用的文件扩展名提取逻辑
This commit is contained in:
parent
83c527af01
commit
872bae1b43
@ -23,7 +23,6 @@ module.exports = async (query, request) => {
|
||||
}
|
||||
|
||||
const songName = song || filename.replace(/\.[^.]+$/, '')
|
||||
const ext = filename.includes('.') ? filename.split('.').pop() : 'mp3'
|
||||
|
||||
const res2 = await request(
|
||||
`/api/upload/cloud/info/v2`,
|
||||
|
||||
@ -276,6 +276,7 @@
|
||||
|
||||
<script src="https://fastly.jsdelivr.net/npm/axios@0.26.1/dist/axios.min.js"></script>
|
||||
<script src="https://fastly.jsdelivr.net/npm/vue@3"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsmediatags/3.9.5/jsmediatags.min.js"></script>
|
||||
<script>
|
||||
const app = Vue.createApp({
|
||||
data() {
|
||||
@ -454,6 +455,23 @@
|
||||
})
|
||||
}
|
||||
|
||||
async function parseMediaTags(file) {
|
||||
return new Promise((resolve) => {
|
||||
jsmediatags.read(file, {
|
||||
onSuccess: function(tag) {
|
||||
resolve({
|
||||
title: tag.tags.title || null,
|
||||
artist: tag.tags.artist || null,
|
||||
album: tag.tags.album || null,
|
||||
})
|
||||
},
|
||||
onError: function() {
|
||||
resolve({ title: null, artist: null, album: null })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function uploadFileDirect(file, index, total) {
|
||||
createProgressItem(file, index, total)
|
||||
|
||||
@ -464,6 +482,10 @@
|
||||
const fileSize = file.size
|
||||
const filename = file.name
|
||||
|
||||
updateProgress(index, '解析音频元数据...', 8)
|
||||
|
||||
const mediaTags = await parseMediaTags(file)
|
||||
|
||||
updateProgress(index, '获取上传凭证...', 10)
|
||||
|
||||
const tokenRes = await axios({
|
||||
@ -484,7 +506,7 @@
|
||||
|
||||
if (!tokenData.needUpload) {
|
||||
updateProgress(index, '文件已存在,直接导入云盘...', 80)
|
||||
await completeUpload(tokenData, file.name)
|
||||
await completeUpload(tokenData, file, mediaTags)
|
||||
updateProgress(index, '上传完成!', 100)
|
||||
return
|
||||
}
|
||||
@ -512,7 +534,7 @@
|
||||
|
||||
updateProgress(index, '上传完成,正在导入云盘...', 90)
|
||||
|
||||
await completeUpload(tokenData, file.name)
|
||||
await completeUpload(tokenData, file, mediaTags)
|
||||
|
||||
updateProgress(index, '上传完成!', 100)
|
||||
|
||||
@ -523,8 +545,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function completeUpload(tokenData, filename) {
|
||||
const songName = filename.replace(/\.[^.]+$/, '')
|
||||
async function completeUpload(tokenData, file, mediaTags = {}) {
|
||||
const songName = mediaTags.title || file.name.replace(/\.[^.]+$/, '')
|
||||
const artist = mediaTags.artist || '未知艺术家'
|
||||
const album = mediaTags.album || '未知专辑'
|
||||
|
||||
const completeRes = await axios({
|
||||
method: 'post',
|
||||
@ -533,10 +557,10 @@
|
||||
songId: tokenData.songId,
|
||||
resourceId: tokenData.resourceId,
|
||||
md5: tokenData.md5,
|
||||
filename: filename,
|
||||
filename: file.name,
|
||||
song: songName,
|
||||
artist: '未知艺术家',
|
||||
album: '未知专辑',
|
||||
artist: artist,
|
||||
album: album,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user