新增下载的歌曲按列表名分组的功能(#2145)
This commit is contained in:
@@ -8,7 +8,7 @@ import { createDownloadInfo } from './utils'
|
||||
// assertApiSupport,
|
||||
// getExt,
|
||||
// } from '..'
|
||||
import { checkPath, getFileStats, removeFile } from '@common/utils/nodejs'
|
||||
import { checkAndCreateDir, checkPath, getFileStats, removeFile } from '@common/utils/nodejs'
|
||||
import { DOWNLOAD_STATUS } from '@common/constants'
|
||||
// import { download as eventDownloadNames } from '@renderer/event/names'
|
||||
|
||||
@@ -40,12 +40,12 @@ const sendAction = (id: string, action: LX.Download.DownloadTaskActions) => {
|
||||
export const createDownloadTasks = (
|
||||
list: LX.Music.MusicInfoOnline[],
|
||||
quality: LX.Quality,
|
||||
savePath: string,
|
||||
fileNameFormat: string,
|
||||
qualityList: LX.QualityList,
|
||||
listId?: string,
|
||||
): LX.Download.ListItem[] => {
|
||||
return list.map(musicInfo => {
|
||||
return createDownloadInfo(musicInfo, quality, fileNameFormat, savePath, qualityList)
|
||||
return createDownloadInfo(musicInfo, quality, fileNameFormat, qualityList, listId)
|
||||
}).filter(task => task)
|
||||
// commit('addTasks', { list: taskList, addMusicLocationType: rootState.setting.list.addMusicLocationType })
|
||||
// let result = getStartTask(downloadList, DOWNLOAD_STATUS, rootState.setting.download.maxDownloadNum)
|
||||
@@ -60,7 +60,7 @@ const createTask = async(downloadInfo: LX.Download.ListItem, savePath: string, s
|
||||
// 开始任务
|
||||
/* commit('onStart', downloadInfo)
|
||||
commit('setStatusText', { downloadInfo, text: '任务初始化中' }) */
|
||||
if (!await checkPath(savePath)) {
|
||||
if (!await checkAndCreateDir(savePath)) {
|
||||
sendAction(downloadInfo.id, {
|
||||
action: 'error',
|
||||
data: {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { DOWNLOAD_STATUS, QUALITYS } from '@common/constants'
|
||||
import { filterFileName } from '@common/utils/common'
|
||||
import { joinPath } from '@common/utils/nodejs'
|
||||
import { mergeLyrics } from './lrcTool'
|
||||
import fs from 'fs'
|
||||
import { clipFileNameLength, clipNameLength } from '@common/utils/tools'
|
||||
|
||||
/**
|
||||
* 保存歌词文件
|
||||
@@ -65,22 +65,8 @@ export const getMusicType = (musicInfo: LX.Music.MusicInfoOnline, type: LX.Quali
|
||||
// const checkExistList = (list: LX.Download.ListItem[], musicInfo: LX.Music.MusicInfo, type: LX.Quality, ext: string): boolean => {
|
||||
// return list.some(s => s.id === musicInfo.id && (s.metadata.type === type || s.metadata.ext === ext))
|
||||
// }
|
||||
const MAX_NAME_LENGTH = 80
|
||||
const MAX_FILE_NAME_LENGTH = 150
|
||||
const clipNameLength = (name: string) => {
|
||||
if (name.length <= MAX_NAME_LENGTH || !name.includes('、')) return name
|
||||
const names = name.split('、')
|
||||
let newName = names.shift()!
|
||||
for (const name of names) {
|
||||
if (newName.length + name.length > MAX_NAME_LENGTH) break
|
||||
newName = newName + '、' + name
|
||||
}
|
||||
return newName
|
||||
}
|
||||
const clipFileNameLength = (name: string) => {
|
||||
return name.length > MAX_FILE_NAME_LENGTH ? name.substring(0, MAX_FILE_NAME_LENGTH) : name
|
||||
}
|
||||
export const createDownloadInfo = (musicInfo: LX.Music.MusicInfoOnline, type: LX.Quality, fileName: string, savePath: string, qualityList: LX.QualityList) => {
|
||||
|
||||
export const createDownloadInfo = (musicInfo: LX.Music.MusicInfoOnline, type: LX.Quality, fileName: string, qualityList: LX.QualityList, listId?: string) => {
|
||||
type = getMusicType(musicInfo, type, qualityList)
|
||||
let ext = getExt(type)
|
||||
const key = `${musicInfo.id}_${type}_${ext}`
|
||||
@@ -101,12 +87,13 @@ export const createDownloadInfo = (musicInfo: LX.Music.MusicInfoOnline, type: LX
|
||||
quality: type,
|
||||
ext,
|
||||
filePath: '',
|
||||
listId,
|
||||
fileName: filterFileName(`${clipFileNameLength(fileName
|
||||
.replace('歌名', musicInfo.name)
|
||||
.replace('歌手', clipNameLength(musicInfo.singer)))}.${ext}`),
|
||||
},
|
||||
}
|
||||
downloadInfo.metadata.filePath = joinPath(savePath, downloadInfo.metadata.fileName)
|
||||
// downloadInfo.metadata.filePath = joinPath(savePath, downloadInfo.metadata.fileName)
|
||||
// commit('addTask', downloadInfo)
|
||||
|
||||
// 删除同路径下的同名文件
|
||||
|
||||
@@ -9,7 +9,7 @@ import { createLocalMusicInfo } from '@renderer/utils/music'
|
||||
/**
|
||||
* 过滤列表中已播放的歌曲
|
||||
*/
|
||||
export const filterMusicList = async({ playedList, listId, list, savePath, playerMusicInfo, dislikeInfo, isNext }: {
|
||||
export const filterMusicList = async({ playedList, listId, list, playerMusicInfo, dislikeInfo, isNext }: {
|
||||
/**
|
||||
* 已播放列表
|
||||
*/
|
||||
@@ -25,7 +25,7 @@ export const filterMusicList = async({ playedList, listId, list, savePath, playe
|
||||
/**
|
||||
* 下载目录
|
||||
*/
|
||||
savePath: string
|
||||
// savePath: string
|
||||
/**
|
||||
* 播放器内当前歌曲(`playInfo.playerPlayIndex`指向的歌曲)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user