新增下载的歌曲按列表名分组的功能(#2145)
This commit is contained in:
@@ -107,6 +107,7 @@ const defaultSetting: LX.AppSetting = {
|
||||
'list.actionButtonsVisible': false,
|
||||
|
||||
'download.enable': false,
|
||||
'download.isSavePathGroupByListName': false,
|
||||
'download.savePath': path.join(os.homedir(), 'Desktop'),
|
||||
'download.fileName': '歌名 - 歌手',
|
||||
'download.maxDownloadNum': 3,
|
||||
|
||||
Vendored
+5
@@ -485,6 +485,11 @@ declare global {
|
||||
*/
|
||||
'download.enable': boolean
|
||||
|
||||
/**
|
||||
* 按列表名分组保存
|
||||
*/
|
||||
'download.isSavePathGroupByListName': boolean
|
||||
|
||||
/**
|
||||
* 下载路径
|
||||
*/
|
||||
|
||||
Vendored
+1
@@ -59,6 +59,7 @@ declare global {
|
||||
ext: FileExt
|
||||
fileName: string
|
||||
filePath: string
|
||||
listId?: string
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,25 @@ export const checkPath = async(path: string): Promise<boolean> => {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查路径并创建目录
|
||||
* @param path
|
||||
* @returns
|
||||
*/
|
||||
export const checkAndCreateDir = async(path: string) => {
|
||||
return fs.promises.access(path, fs.constants.F_OK | fs.constants.W_OK)
|
||||
.catch(async(err: NodeJS.ErrnoException) => {
|
||||
if (err.code != 'ENOENT') throw err as Error
|
||||
return fs.promises.mkdir(path, { recursive: true })
|
||||
})
|
||||
.then(() => true)
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export const getFileStats = async(path: string): Promise<fs.Stats | null> => {
|
||||
return new Promise(resolve => {
|
||||
if (!path) {
|
||||
|
||||
@@ -130,3 +130,21 @@ export const filterMusicList = <T extends LX.Music.MusicInfo>(list: T[]): T[] =>
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const MAX_NAME_LENGTH = 80
|
||||
const MAX_FILE_NAME_LENGTH = 150
|
||||
export 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
|
||||
}
|
||||
export const clipFileNameLength = (name: string) => {
|
||||
return name.length > MAX_FILE_NAME_LENGTH ? name.substring(0, MAX_FILE_NAME_LENGTH) : name
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user