Skip to content

Commit

Permalink
fix: some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
blogwy committed Oct 9, 2021
1 parent 613f0c9 commit c087e0d
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 82 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
* [x] 删除下载记录
* [ ] 暂停/恢复下载

## 运行
## 开发

**提前自备梯子,因为electron electron-builder等依赖项需要从GitHub下载**

```bash
git clone https://github.com/blogwy/BilibiliVideoDownload.git
Expand All @@ -52,6 +54,11 @@ yarn electron:build
```
## 版本

v3.1.5 `2021-10-08`

1. 修复无法删除的bug [issues/41](https://github.com/blogwy/BilibiliVideoDownload/issues/41)
2. 新增回车键确认在主页

v3.1.4 `2021-09-24`

1. 修复在升级版本后,可能会导致设置页面无法关闭问题 [issues/39](https://github.com/blogwy/BilibiliVideoDownload/issues/39)
Expand Down Expand Up @@ -119,4 +126,5 @@ Node.js重构,以前的在vuejs分支
* [Vue.js](https://vuejs.org/)
* [Ant Design Vue](https://antdv.com/docs/vue/introduce-cn/)
* [got](https://github.com/sindresorhus/got)
* [bilibili-API-collect](https://github.com/SocialSisterYi/bilibili-API-collect)

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BilibiliVideoDownload",
"version": "3.1.4",
"version": "3.1.5",
"private": true,
"author": "wangyu <wangyu@wangyu.link>",
"description": "欢迎使用BilibiliVideoDownload",
Expand Down
29 changes: 22 additions & 7 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function registerLocalResourceProtocol () {
}

function initSetting () {
console.log('setting info')
const curSetting = store.get('setting')
if (!curSetting) {
store.set('setting', {
Expand All @@ -103,7 +102,6 @@ function initSetting () {

function creatImageServer () {
server.get('/', async (req, res) => {
console.log(req.query.img)
if (req.query.img) {
const { rawBody } = await got(req.query.img)
res.set('Content-Type', 'image/webp')
Expand Down Expand Up @@ -162,7 +160,6 @@ app.on('ready', async () => {
properties: ['openDirectory']
})
.then(res => {
console.log(res)
event.reply('dir-dialog-reply', res)
})
.catch(error => {
Expand All @@ -179,21 +176,39 @@ app.on('ready', async () => {
buttons: ['取消', '关闭']
})
.then(res => {
console.log(res)
if (res.response === 1) {
app.exit()
} else {
console.log('点击取消')
}
})
.catch(error => {
console.log(error)
})
})

// 删除视频
ipcMain.on('open-delete-video-dialog', (event, arg) => {
console.log(arg.title)
dialog.showMessageBox(win, {
type: 'info',
title: '提示',
message: `是否要移除${arg.title}任务吗?`,
checkboxLabel: '同时删除文件',
buttons: ['取消', '删除']
})
.then(res => {
console.log(res)
event.reply('delete-video-dialog-reply', {
result: res,
videoInfo: arg
})
})
.catch(error => {
console.log(error)
})
})

// 打开浏览器
ipcMain.on('open-external', (event, arg) => {
console.log(arg)
shell.openExternal(arg)
})

Expand Down
2 changes: 0 additions & 2 deletions src/components/CheckUpdate/CheckUpdate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default {
created () {},
methods: {
handleOk () {
console.log('handleOk')
window.ipcRenderer.send('open-external', this.htmlUrl)
},
handleCancel () {
Expand All @@ -46,7 +45,6 @@ export default {
}
this.got('https://api.github.com/repos/blogwy/BilibiliVideoDownload/releases/latest', { responseType: 'json' })
.then(res => {
console.log(res.body)
this.newVersion = res.body.tag_name.substr(1)
this.htmlUrl = res.body.html_url
this.updateContent = res.body.body
Expand Down
5 changes: 0 additions & 5 deletions src/components/SettingDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export default {
},
mounted () {
window.ipcRenderer.on('dir-dialog-reply', (event, arg) => {
console.log(arg)
if (!arg.canceled) {
this.form.setFieldsValue({
downloadPath: arg.filePaths[0]
Expand All @@ -105,15 +104,13 @@ export default {
hide () {
this.form.validateFields((error, values) => {
if (!error) {
console.log(values)
this.store.set('setting', values)
this.visible = false
this.form.resetFields()
}
})
},
async show (info) {
console.log(info)
if (info) {
setTimeout(() => {
this.form.setFieldsValue(info)
Expand All @@ -129,13 +126,11 @@ export default {
})
},
openFolder () {
console.log('openFolder')
window.ipcRenderer.send('open-dir-dialog', 'open')
},
logout () {
this.form.validateFields(async (error, values) => {
if (!error) {
console.log(values)
values.SESSDATA = null
this.store.set('setting', values)
const status = await checkLogin()
Expand Down
4 changes: 0 additions & 4 deletions src/components/VideoModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export default {
methods: {
onAllSelectedChange (e) {
this.allSelected = e.target.checked
console.log(e.target.checked)
this.selected = []
if (e.target.checked) {
this.videoInfo.page.forEach(element => {
Expand All @@ -108,7 +107,6 @@ export default {
}
},
async handleOk () {
console.log(this.videoInfo)
if (!this.quality) {
this.$message.info('请选择清晰度')
return
Expand Down Expand Up @@ -143,8 +141,6 @@ export default {
this.$store.commit('addDownloadingTask', allowDownTaskData.length)
}
this.confirmLoading = false
console.log('下载列表')
console.log(taskList)
// 跳转到下载页面
this.$router.push('/download')
},
Expand Down
26 changes: 20 additions & 6 deletions src/core/bilibili.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const got = require('got')
*/
const getDownloadList = async (videoInfo, selected, quality) => {
const SESSDATA = window.remote.getGlobal('store').get('setting.SESSDATA')
const isFolder = window.remote.getGlobal('store').get('setting.isFolder')
const downloadPath = window.remote.getGlobal('store').get('setting.downloadPath')
const bfeId = window.remote.getGlobal('store').get('setting.bfe_id') ? window.remote.getGlobal('store').get('setting.bfe_id') : ''
const config = {
headers: {
Expand Down Expand Up @@ -44,19 +46,31 @@ const getDownloadList = async (videoInfo, selected, quality) => {
videoDuration = videoInfo.duration
videoUrl = videoInfo.url
}
const taskId = `${new Date().getTime()}${randomNum(1000, 9999)}`
let delDir = []
if (isFolder) {
delDir = `${downloadPath}/${videoTitle}-${taskId}/`
} else {
delDir.push(`${downloadPath}/${videoTitle}-${taskId}.mp4`, `${downloadPath}/${videoTitle}-${taskId}.png`, `${downloadPath}/${videoTitle}-${taskId}-video.m4s`, `${downloadPath}/${videoTitle}-${taskId}-audio.m4s`)
}
const videoData = {
...videoInfo,
id: `${new Date().getTime()}${randomNum(1000, 9999)}`,
id: taskId,
title: videoTitle,
quality: quality,
duration: videoDuration,
status: 4,
progress: 0,
size: null,
url: videoUrl,
downloadPath: {
downloadLink: {
video: video.find(item => item.id === quality) ? video.find(item => item.id === quality).baseUrl : video[0].baseUrl,
audio: audio[0].baseUrl
},
fileDir: {
dir: isFolder ? `${downloadPath}/${videoTitle}-${taskId}/` : `${downloadPath}/`,
file: isFolder ? `${videoTitle}` : `${videoTitle}-${taskId}`,
delDir: delDir
}
}
console.log(videoData)
Expand Down Expand Up @@ -96,8 +110,6 @@ const checkLogin = async () => {
},
responseType: 'json'
})
console.log(SESSDATA)
console.log(body)
if (!body.data.isLogin) return 0
if (body.data.isLogin && !body.data.vipStatus) return 1
if (body.data.isLogin && body.data.vipStatus) return 2
Expand Down Expand Up @@ -159,7 +171,8 @@ const parseBV = (html, url) => {
qualityOptions: data.accept_quality.map(item => ({ label: quality[item], value: item })),
page: videoData.pages.map(item => ({ title: item.part, page: item.page, duration: item.duration, cid: item.cid })),
subtitle: videoData.subtitle.list,
downloadPath: {}
downloadLink: {},
fileDir: {}
}
resolve(obj)
} catch (error) {
Expand Down Expand Up @@ -192,7 +205,8 @@ const parseEP = (html, url) => {
qualityOptions: data.accept_quality.map(item => ({ label: quality[item], value: item })),
page: [{ page: 1, cid: epInfo.cid }],
subtitle: [],
downloadPath: {}
downloadLink: {},
fileDir: {}
}
resolve(obj)
} catch (error) {
Expand Down
11 changes: 4 additions & 7 deletions src/core/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@ export default async (videoInfo, event) => {
referer: videoInfo.url
}
}
let fileName = ''
let fileName = `${videoInfo.fileDir.dir}${videoInfo.fileDir.file}`
if (setting.isFolder) {
// 创建文件夹
try {
fs.mkdirSync(`${setting.downloadPath}/${videoInfo.title}-${videoInfo.id}/`)
fileName = `${setting.downloadPath}/${videoInfo.title}-${videoInfo.id}/${videoInfo.title}`
fs.mkdirSync(`${videoInfo.fileDir.dir}`)
} catch (error) {
console.log(`创建文件夹失败:${error}`)
}
} else {
fileName = `${setting.downloadPath}/${videoInfo.title}-${videoInfo.id}`
}
// 下载封面
await pipeline(
Expand All @@ -80,7 +77,7 @@ export default async (videoInfo, event) => {
}
// 下载视频
await pipeline(
got.stream(videoInfo.downloadPath.video, downloadConfig)
got.stream(videoInfo.downloadLink.video, downloadConfig)
.on('downloadProgress', progress => {
let nowTime = +new Date()
clearTimeout(videoTimer)
Expand Down Expand Up @@ -114,7 +111,7 @@ export default async (videoInfo, event) => {
await sleep(500)
// 下载音频
await pipeline(
got.stream(videoInfo.downloadPath.audio, downloadConfig)
got.stream(videoInfo.downloadLink.audio, downloadConfig)
.on('downloadProgress', progress => {
let nowTime = +new Date()
clearTimeout(audioTimer)
Expand Down
8 changes: 8 additions & 0 deletions src/utlis/formatPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default path => {
const pattern = /[\/]/g
if (process.platform === 'win32') {
return path.replace(pattern, '\\')
} else {
return path
}
}

0 comments on commit c087e0d

Please sign in to comment.