Skip to content

Commit

Permalink
support Netscape HTTP Cookie File
Browse files Browse the repository at this point in the history
  • Loading branch information
7Red4 committed Sep 3, 2021
1 parent ab7cefe commit 55f0fdb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 19 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
});
18 changes: 18 additions & 0 deletions src/components/SettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
</v-card-title>

<v-card-text class="pt-4">
<div class="mb-4">
<v-btn color="primary" @click="pickCookieFile" class="mr-3">
選擇檔案
</v-btn>
<v-btn color="error" text @click="cookie = ''">刪除 cookie</v-btn>
</div>
<v-textarea
label="Cookie"
v-model="cookie"
readonly
auto-grow
outlined
></v-textarea>
Expand All @@ -33,6 +40,7 @@
</template>

<script>
import { ipcRenderer } from 'electron';
const schema = {
cookie: ''
};
Expand All @@ -50,6 +58,12 @@ export default {
}
},
created() {
ipcRenderer.on('choose-cookie-file-reply', (event, cookie) => {
this.cookie = cookie;
});
},
methods: {
init() {
const cookie = this.$db.get('cookie').value();
Expand All @@ -60,9 +74,13 @@ export default {
this[key] = schema[key];
});
},
pickCookieFile() {
ipcRenderer.send('choose-cookie-file');
},
submit() {
this.$db.set('cookie', this.cookie).write();
this.$emit('input', false);
}
}
};
Expand Down

0 comments on commit 55f0fdb

Please sign in to comment.