From 55f0fdb959cfb442d67ad1277ef71909fcd086ae Mon Sep 17 00:00:00 2001 From: 7red4 Date: Fri, 3 Sep 2021 17:37:04 +0800 Subject: [PATCH] support Netscape HTTP Cookie File --- package-lock.json | 19 +++++++++++++++++++ package.json | 1 + src/background.js | 20 +++++++++++++++++++- src/components/SettingDialog.vue | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 47f1dc5..d0ec161 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4494,6 +4494,15 @@ "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=", "dev": true }, + "cookiefile": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/cookiefile/-/cookiefile-1.0.10.tgz", + "integrity": "sha1-zijhtcEfViAqqcHbWpl0HqDl0yg=", + "requires": { + "file-exists": "^2.0.0", + "isnumeric": "^0.3.1" + } + }, "copy-concurrently": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz", @@ -6781,6 +6790,11 @@ "flat-cache": "^2.0.1" } }, + "file-exists": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/file-exists/-/file-exists-2.0.0.tgz", + "integrity": "sha1-okFQZlFQ5i1VvFRJKB2I0rCBDco=" + }, "file-loader": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/file-loader/-/file-loader-4.3.0.tgz", @@ -8601,6 +8615,11 @@ "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, + "isnumeric": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/isnumeric/-/isnumeric-0.3.3.tgz", + "integrity": "sha512-GTxMCA0SsHdQWdsb6CDavRbeq4mQ2pryJUqwpcRHfKNnvdnNnI+3zT8K2zR/o9zZxTM6HKW7GRRetObb8E7p9Q==" + }, "isobject": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", diff --git a/package.json b/package.json index 1cec9d3..0d8f9e3 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "main": "background.js", "dependencies": { "app-root-dir": "^1.0.2", + "cookiefile": "^1.0.10", "core-js": "^3.6.5", "filenamify": "^4.3.0", "lowdb": "^1.0.0", diff --git a/src/background.js b/src/background.js index 0e4316f..4d72768 100644 --- a/src/background.js +++ b/src/background.js @@ -8,6 +8,7 @@ import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'; import { getInfo } from './controller/ytdl.js'; import Que from './classes/Que.js'; import consola from 'consola'; +import { CookieMap } from 'cookiefile'; const isDevelopment = process.env.NODE_ENV !== 'production'; const queMap = new Map(); @@ -244,7 +245,7 @@ ipcMain.on('pick-playlist-export-path', async (event, title) => { try { const path = dialog.showSaveDialogSync({ defaultPath: title, - filters: [{ name: 'Json', extensions: ['.json'] }] + filters: [{ name: 'Json', extensions: ['json'] }] }); event.reply('pick-playlist-export-path-reply', path); } catch (error) { @@ -265,3 +266,20 @@ ipcMain.on('export-list', async (event, { exporting, path }) => { ipcMain.on('show-item-in-folder', (event, path) => { shell.openPath(path); }); + +ipcMain.on('choose-cookie-file', (event) => { + try { + const path = dialog.showOpenDialogSync({ + filters: [{ name: 'Text', extensions: ['txt'] }] + }); + const cookieFile = new CookieMap(path[0]); + let cookieString = ''; + cookieFile.forEach(({ value }, key) => { + if (value) cookieString += `${key}=${value};`; + }); + + event.reply('choose-cookie-file-reply', cookieString); + } catch (error) { + consola.error(error); + } +}); diff --git a/src/components/SettingDialog.vue b/src/components/SettingDialog.vue index f320bbe..d62f6fe 100644 --- a/src/components/SettingDialog.vue +++ b/src/components/SettingDialog.vue @@ -15,9 +15,16 @@ +
+ + 選擇檔案 + + 刪除 cookie +
@@ -33,6 +40,7 @@