新增下载目录存在同名的文件时跳过下载此任务设置

pull/1094/head
lyswhut 2022-12-30 14:00:49 +08:00
parent 18b6f73008
commit e2a1d7b99d
11 changed files with 80 additions and 39 deletions

View File

@ -14,6 +14,7 @@
- 新增启动软件时自动播放音乐设置,默认关闭,可去设置-播放设置开启
- 新增“蛋雅深藍”、“近墨者黑”皮肤
- 新增下载歌词时是否同时下载歌词翻译、罗马音设置,默认关闭,可以去设置-下载设置开启(#344
- 新增下载时,若目录存在同名的文件时是否跳过下载此任务的设置(默认跳过,可以去设置-下载设置更改)
- 新增界面字体大小设置
- 桌面歌词新增竖排歌词显示功能(#971
- 桌面歌词新增歌词对齐方式、是否不允许歌词换行、歌词颜色、滚动对齐方式、歌词间距设置

View File

@ -53,34 +53,34 @@ export const windowSizeList: WindowSize[] = [
export const navigationUrlWhiteList: RegExp[] = []
// 基础黑白色
export const commonColorNames = [
'--color-000', '--color-050', '--color-100', '--color-200', '--color-300', '--color-400',
'--color-500', '--color-600', '--color-700', '--color-800', '--color-900',
] as const
export const commonLightColorValues = [
'rgb(255, 255, 255)',
'rgb(217,217,217)',
'rgb(184,184,184)',
'rgb(156,156,156)',
'rgb(133,133,133)',
'rgb(113,113,113)',
'rgb(96,96,96)',
'rgb(82,82,82)',
'rgb(70,70,70)',
'rgb(60,60,60)',
'rgb(51,51,51)',
] as const
export const commonDarkColorValues = [
'rgb(11, 11, 11)',
'rgb(60,60,60)',
'rgb(99,99,99)',
'rgb(130,130,130)',
'rgb(155,155,155)',
'rgb(175,175,175)',
'rgb(191,191,191)',
'rgb(204,204,204)',
'rgb(214,214,214)',
'rgb(222,222,222)',
'rgb(229,229,229)',
] as const
// export const commonColorNames = [
// '--color-000', '--color-050', '--color-100', '--color-200', '--color-300', '--color-400',
// '--color-500', '--color-600', '--color-700', '--color-800', '--color-900',
// ] as const
// export const commonLightColorValues = [
// 'rgb(255, 255, 255)',
// 'rgb(217,217,217)',
// 'rgb(184,184,184)',
// 'rgb(156,156,156)',
// 'rgb(133,133,133)',
// 'rgb(113,113,113)',
// 'rgb(96,96,96)',
// 'rgb(82,82,82)',
// 'rgb(70,70,70)',
// 'rgb(60,60,60)',
// 'rgb(51,51,51)',
// ] as const
// export const commonDarkColorValues = [
// 'rgb(11, 11, 11)',
// 'rgb(60,60,60)',
// 'rgb(99,99,99)',
// 'rgb(130,130,130)',
// 'rgb(155,155,155)',
// 'rgb(175,175,175)',
// 'rgb(191,191,191)',
// 'rgb(204,204,204)',
// 'rgb(214,214,214)',
// 'rgb(222,222,222)',
// 'rgb(229,229,229)',
// ] as const

View File

@ -77,6 +77,7 @@ const defaultSetting: LX.AppSetting = {
'download.savePath': join(homedir(), 'Desktop'),
'download.fileName': '歌名 - 歌手',
'download.maxDownloadNum': 3,
'download.skipExistFile': true,
'download.isDownloadLrc': false,
'download.isDownloadTLrc': false,
'download.isDownloadRLrc': false,

View File

@ -349,6 +349,11 @@ declare global {
*/
'download.maxDownloadNum': number
/**
*
*/
'download.skipExistFile': boolean
/**
* lrc
*/

View File

@ -62,6 +62,7 @@
"download__runing": "Downloading",
"download__status": "Status",
"download_status_error_check_path": "There is an error in checking the download path, please check whether the set download directory is normal",
"download_status_error_check_path_exist": "A file with the same name exists, skip download",
"download_status_error_refresh_url": "Link is dead, link is being refreshed",
"download_status_error_url_failed": "Failed to get music link",
"download_status_error_write": "The song save location is occupied or does not have write permission, please try to change the song save directory or restart the software or restart the computer, the error details:",
@ -350,6 +351,7 @@
"setting__download_path_title": "Define the path to downloading",
"setting__download_rlyric": "Also write Roman lyrics to the lyrics file (if any)",
"setting__download_select_save_path": "Select the save path",
"setting__download_skip_exist_file": "Skip downloading this task when there is a file with the same name in the download directory",
"setting__download_tlyric": "Also write the translated lyrics to the lyrics file (if any)",
"setting__download_use_other_source": "Auto source download",
"setting__download_use_other_source_tip": "When the song cannot be downloaded from the original source, try to switch to another source to download. Note: This function does not 100% guarantee that the version of the song after changing the source is consistent with the original version",

View File

@ -62,6 +62,7 @@
"download__runing": "正在下载",
"download__status": "状态",
"download_status_error_check_path": "检查下载路径出错,请检查设置的下载目录是否正常",
"download_status_error_check_path_exist": "存在同名文件,跳过下载",
"download_status_error_refresh_url": "链接失效,正在刷新链接",
"download_status_error_url_failed": "获取音乐链接失败",
"download_status_error_write": "歌曲保存位置被占用或没有写入权限,请尝试更改歌曲保存目录或重启软件或重启电脑,错误详情:",
@ -352,6 +353,7 @@
"setting__download_path_title": "下载歌曲保存的路径",
"setting__download_rlyric": "同时将罗马音歌词写入歌词文件中(如果有)",
"setting__download_select_save_path": "选择歌曲保存路径",
"setting__download_skip_exist_file": "下载目录存在同名的文件时跳过下载此任务",
"setting__download_tlyric": "同时将翻译歌词写入歌词文件中(如果有)",
"setting__download_use_other_source": "自动换源下载",
"setting__download_use_other_source_tip": "当无法从歌曲的原始源下载时尝试切换到其他源下载此功能不100%保证换源后的歌曲版本与原版一致",

View File

@ -62,6 +62,7 @@
"download__runing": "正在下載",
"download__status": "狀態",
"download_status_error_check_path": "檢查下載路徑出錯,請檢查設置的下載目錄是否正常",
"download_status_error_check_path_exist": "存在同名文件,跳過下載",
"download_status_error_refresh_url": "鏈接失效,正在刷新鏈接",
"download_status_error_url_failed": "獲取音樂鏈接失敗",
"download_status_error_write": "歌曲保存位置被佔用或沒有寫入權限,請嘗試更改歌曲保存目錄或重啟軟件或重啟電腦,錯誤詳情:",
@ -351,6 +352,7 @@
"setting__download_path_title": "下載歌曲保存的路徑",
"setting__download_rlyric": "同時將羅馬音歌詞寫入歌詞文件中(如果有)",
"setting__download_select_save_path": "選擇歌曲保存路徑",
"setting__download_skip_exist_file": "下載目錄存在同名的文件時跳過下載此任務",
"setting__download_tlyric": "同時將翻譯歌詞寫入歌詞文件中(如果有)",
"setting__download_use_other_source": "自動換源下載",
"setting__download_use_other_source_tip": "當無法從歌曲的原始源下載時嘗試切換到其他源下載此功能不100%保證換源後的歌曲版本與原版一致",

View File

@ -231,7 +231,7 @@ const handleStartTask = async(downloadInfo: LX.Download.ListItem) => {
setStatusText(downloadInfo, window.i18n.t('download_status_start'))
await window.lx.worker.download.startTask(toRaw(downloadInfo), appSetting['download.savePath'], proxyCallback((event: LX.Download.DownloadTaskActions) => {
await window.lx.worker.download.startTask(toRaw(downloadInfo), appSetting['download.savePath'], appSetting['download.skipExistFile'], proxyCallback((event: LX.Download.DownloadTaskActions) => {
// console.log(event)
switch (event.action) {
case 'start':

View File

@ -1,7 +1,10 @@
<template lang="pug">
dt#download {{$t('setting__download')}}
dd
base-checkbox(id="setting_download_enable" :modelValue="appSetting['download.enable']" @update:modelValue="updateSetting({'download.enable': $event})" :label="$t('setting__download_enable')")
.gap-top
base-checkbox(id="setting_download_enable" :modelValue="appSetting['download.enable']" @update:modelValue="updateSetting({'download.enable': $event})" :label="$t('setting__download_enable')")
.gap-top
base-checkbox(id="setting_download_skip_exist_file" :modelValue="appSetting['download.skipExistFile']" @update:modelValue="updateSetting({'download.skipExistFile': $event})" :label="$t('setting__download_skip_exist_file')")
dd(:aria-label="$t('setting__download_path_title')")
h3#download_path {{$t('setting__download_path')}}
div

View File

@ -8,7 +8,7 @@ import { createDownloadInfo } from './utils'
// assertApiSupport,
// getExt,
// } from '..'
import { checkPath, removeFile } from '@common/utils/nodejs'
import { checkPath, getFileStats, removeFile } from '@common/utils/nodejs'
import { DOWNLOAD_STATUS } from '@common/constants'
// import { download as eventDownloadNames } from '@renderer/event/names'
@ -55,7 +55,7 @@ export const createDownloadTasks = (
// }
}
const createTask = async(downloadInfo: LX.Download.ListItem, savePath: string) => {
const createTask = async(downloadInfo: LX.Download.ListItem, savePath: string, skipExistFile: boolean) => {
// console.log('createTask', downloadInfo, savePath)
// 开始任务
/* commit('onStart', downloadInfo)
@ -71,7 +71,32 @@ const createTask = async(downloadInfo: LX.Download.ListItem, savePath: string) =
}
if (!tasks.has(downloadInfo.id)) return
// TODO check file exists
if (downloadInfo.downloaded == 0) {
if (skipExistFile) {
const stats = await getFileStats(downloadInfo.metadata.filePath)
if (stats && stats.size > 100) {
sendAction(downloadInfo.id, {
action: 'error',
data: {
error: 'download_status_error_check_path_exist',
},
})
return
}
} else if (await checkPath(downloadInfo.metadata.filePath)) {
try {
await removeFile(downloadInfo.metadata.filePath)
} catch (err) {
sendAction(downloadInfo.id, {
action: 'error',
data: {
error: 'download_status_error_check_path',
},
})
return
}
}
}
const downloadOptions: DownloadOptions = {
url: downloadInfo.metadata.url ?? '',
@ -204,7 +229,7 @@ export const updateUrl = (id: string, url: string) => {
})
}
export const startTask = async(downloadInfo: LX.Download.ListItem, savePath: string, callback: (action: LX.Download.DownloadTaskActions) => void) => {
export const startTask = async(downloadInfo: LX.Download.ListItem, savePath: string, skipExistFile: boolean, callback: (action: LX.Download.DownloadTaskActions) => void) => {
await pauseTask(downloadInfo.id)
tasks.set(downloadInfo.id, downloadInfo)
@ -239,7 +264,7 @@ export const startTask = async(downloadInfo: LX.Download.ListItem, savePath: str
// await dispatch('startTask')
}
} else {
await createTask(downloadInfo, savePath)
await createTask(downloadInfo, savePath, skipExistFile)
// await dispatch('handleStartTask', downloadInfo)
}
}

View File

@ -1,6 +1,6 @@
import { DOWNLOAD_STATUS, QUALITYS } from '@common/constants'
import { filterFileName } from '@common/utils/common'
import { joinPath, removeFile } from '@common/utils/nodejs'
import { joinPath } from '@common/utils/nodejs'
import fs from 'fs'
/**
@ -94,7 +94,7 @@ export const createDownloadInfo = (musicInfo: LX.Music.MusicInfoOnline, type: LX
// 删除同路径下的同名文件
// TODO
void removeFile(downloadInfo.metadata.filePath)
// void removeFile(downloadInfo.metadata.filePath)
// .catch(err => {
// if (err.code !== 'ENOENT') {
// return commit('setStatusText', { downloadInfo, text: '文件删除失败' })