From 3110d053244c005bef7a6422ed1acf28c3413892 Mon Sep 17 00:00:00 2001 From: aandrew-me Date: Wed, 3 Aug 2022 20:30:28 +0600 Subject: [PATCH] Small style change --- assets/css/index.css | 4 +-- html/index.html | 2 +- main.js | 3 +-- src/renderer.js | 60 ++++++++++---------------------------------- 4 files changed, 17 insertions(+), 52 deletions(-) diff --git a/assets/css/index.css b/assets/css/index.css index 445ecda..cfbcc0c 100644 --- a/assets/css/index.css +++ b/assets/css/index.css @@ -60,8 +60,8 @@ body { } -h1 { - font-size: 50px; +h2{ + margin-top:0; } input[type="text"] { diff --git a/html/index.html b/html/index.html index 6684453..a155113 100644 --- a/html/index.html +++ b/html/index.html @@ -28,7 +28,7 @@ -

YouTube Downloader

+

YouTube Downloader

diff --git a/main.js b/main.js index 3622b43..e7a7021 100644 --- a/main.js +++ b/main.js @@ -23,13 +23,12 @@ function createWindow() { win.maximize(); win.setMenu(null) win.show(); - win.webContents.openDevTools() + // win.webContents.openDevTools() autoUpdater.checkForUpdatesAndNotify(); } app.whenReady().then(() => { createWindow(); - app.on("activate", () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); diff --git a/src/renderer.js b/src/renderer.js index 345f9fe..8e1d021 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -3,15 +3,14 @@ const ytdl = require("ytdl-core"); const cp = require("child_process"); const os = require("os"); const ffmpeg = require("ffmpeg-static"); -const { BrowserWindow, shell, remote, ipcRenderer } = require("electron"); - - +const path = require("path") +const { shell, ipcRenderer, app } = require("electron"); // Directories const homedir = os.homedir(); -const appdir = homedir + "/.ytDownloader/"; -const tempDir = appdir + "temp/"; -fs.mkdirSync(homedir + "/.ytDownloader/temp", { recursive: true }); +const appdir = path.join(homedir,".ytDownloader"); +const tempDir = path.join(appdir, "temp"); +fs.mkdirSync(path.join(homedir, ".ytDownloader/temp"), { recursive: true }); let config; // Download directory @@ -33,40 +32,6 @@ else{ // Clearing tempDir fs.readdirSync(tempDir).forEach((f) => fs.rmSync(`${tempDir}/${f}`)); -// Handling download location input from user -async function checkPath(path) { - const check = new Promise((resolve, reject) => { - fs.readdir(path, (err) => { - // If directory doesn't exist, try creating it - if (err) { - fs.mkdir(path, (err) => { - if (err) { - reject(err); - } else { - console.log("Successfully created " + path); - resolve(true); - } - }); - } else { - fs.writeFile(path + "/.test", "", (err) => { - // If that location is not accessible - if (err) { - reject(err); - } else { - fs.rm(path + "/.test", (err) => { - if (err) console.log(err); - }); - resolve(true); - } - }); - } - }); - }); - - const result = await check; - return result; -} - // Collecting info from youtube async function getVideoInfo(url) { let info; @@ -291,7 +256,7 @@ function download(type) { resolve("video downloaded"); } }) - .pipe(fs.createWriteStream(tempDir + videoName)); + .pipe(fs.createWriteStream(path.join(tempDir, videoName))); }), new Promise((resolve, reject) => { @@ -310,16 +275,16 @@ function download(type) { resolve("audio downloaded"); } }) - .pipe(fs.createWriteStream(tempDir + audioName)); + .pipe(fs.createWriteStream(path.join(tempDir, audioName))); }), ]; Promise.all([arr[0], arr[1]]) .then((response) => { cp.exec( - `"${ffmpeg}" -i "${tempDir + videoName}" -i "${ - tempDir + audioName - }" -c copy "${downloadDir + "/" + filename}"`, + `"${ffmpeg}" -i "${path.join(tempDir, videoName)}" -i "${ + path.join(tempDir, audioName) + }" -c copy "${path.join(downloadDir, filename)}"`, (error, stdout, stderr) => { if (error) { console.log(error); @@ -353,7 +318,7 @@ function download(type) { afterSave(downloadDir, filename); } }) - .pipe(fs.createWriteStream(downloadDir + "/" + filename)); + .pipe(fs.createWriteStream(path.join(downloadDir, filename))); } }); } @@ -374,7 +339,8 @@ function afterSave(location, filename) { ).innerHTML = `File saved. Click to open ${location}`; getId("savedMsg").addEventListener("click", (e) => { - shell.showItemInFolder(location + "/" + filename); + shell.showItemInFolder(path.join(location, filename)); + log(path.join(location, filename)) }); }