Browse Source

first push

hanwenjie 2 years ago
commit
e2398ac6f5
6 changed files with 192 additions and 0 deletions
  1. 30 0
      http.js
  2. 54 0
      main.js
  3. 29 0
      package.json
  4. 10 0
      preload.js
  5. 13 0
      view/index/index.html
  6. 56 0
      view/index/index.js

+ 30 - 0
http.js

@@ -0,0 +1,30 @@
+const axios = require('axios')
+axios.defaults.adapter = require("axios/lib/adapters/http");
+
+const axiosGet = function (url, params) {
+    return new Promise((resolve, reject) => {
+        axios
+            .get(url, {
+                params,
+            })
+            .then(res => {
+                resolve(res);
+            })
+            .catch(err => {
+                reject(err);
+            });
+    });
+}
+
+const axiosPost = function (url, params) {
+    return new Promise((resolve, reject) => {
+        axios
+            .post(url, params)
+            .then(res => {
+                resolve(res);
+            })
+            .catch(err => {
+                reject(err);
+            });
+    });
+}

+ 54 - 0
main.js

@@ -0,0 +1,54 @@
+const { app, BrowserWindow, Menu } = require('electron')
+const path = require('path')
+
+//热加载
+const reloader = require('electron-reloader')
+reloader(module)
+
+/**
+ * 在 Electron 中,只有在 app 模块的 ready 事件被激发后才能创建浏览器窗口。 
+ * 您可以通过使用 app.whenReady() API来监听此事件。 在whenReady()成功后调用createWindow()。
+ */
+app.whenReady().then(() => {
+    createWindow()
+    convertVodie()
+})
+
+/**
+ * 关闭所有窗口时退出应用
+ */
+app.on('window-all-closed', () => {
+    if (process.platform !== 'darwin') {
+        app.quit()
+    }
+})
+
+const createWindow = () => {
+    const win = new BrowserWindow({
+      width: 800,
+      height: 600,
+      webPreferences: {
+        preload: path.join(__dirname, 'preload.js'),
+        //允许运行子线程
+        nodeIntegrationInWorker: true,
+        //开启node支持
+        nodeIntegration: true,
+        enableRemoteModule: true,
+        //关闭安全性验证
+        contextIsolation: false,
+        //允许跨域
+        webSecurity: false
+      }
+    })
+
+    app.on('activate', () => {
+        if (BrowserWindow.getAllWindows().length === 0) {
+            createWindow()
+        }
+    })
+
+    win.webContents.openDevTools();
+
+    win.loadFile('view/index/index.html')
+    // win.loadURL('http://www.baidu.com')
+}

+ 29 - 0
package.json

@@ -0,0 +1,29 @@
+{
+  "name": "dy-tool",
+  "version": "0.0.1",
+  "description": "抖音工具",
+  "main": "main.js",
+  "scripts": {
+    "start": "electron .",
+    "test": "echo \"Error: no test specified\" && exit 1",
+    "make": "electron-forge make"
+  },
+  "dependencies": {
+    "@electron-forge/cli": "^6.0.4",
+    "axios": "^1.2.1",
+    "cheerio": "^1.0.0-rc.12",
+    "electron": "^22.0.0",
+    "electron-reloader": "^1.2.3",
+    "ffmpeg-static": "^5.1.0",
+    "ffprobe-static": "^3.1.0",
+    "fluent-ffmpeg": "^2.1.2",
+    "fs": "^0.0.1-security",
+    "http": "^0.0.1-security",
+    "https": "^1.0.0"
+  },
+  "author": "Andy Han",
+  "devDependencies": {
+    "@electron-forge/cli": "^6.0.4",
+    "electron-reloader": "^1.2.3"
+  }
+}

+ 10 - 0
preload.js

@@ -0,0 +1,10 @@
+window.addEventListener('DOMContentLoaded', () => {
+    const replaceText = (selector, text) => {
+        const element = document.getElementById(selector)
+        if (element) element.innerText = text
+    }
+
+    for (const dependency of ['chrome', 'node', 'electron']) {
+        replaceText(`${dependency}-version`, process.versions[dependency])
+    }
+})

+ 13 - 0
view/index/index.html

@@ -0,0 +1,13 @@
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>test</title>
+</head>
+<body>
+    <div style="margin: 20px;">
+        <button id="ck">转flv</button>
+        <button id="dyGet">抖音抓取</button>
+    </div>
+</body>
+<script src="index.js"></script>
+</html>

+ 56 - 0
view/index/index.js

@@ -0,0 +1,56 @@
+const {  BrowserWindow, dialog, shell } = require('electron')
+const cheerio = require('cheerio')
+const pathToFfmpeg = require('ffmpeg-static')
+const {path} = require('ffprobe-static')
+const Ffmpeg = require('fluent-ffmpeg')
+const axios = require('axios')
+axios.defaults.adapter = require("axios/lib/adapters/http");
+ffmpeg = new Ffmpeg()
+
+const ckBtn = document.getElementById('ck')
+ckBtn.onclick = function (e) {
+    console.log(pathToFfmpeg)
+    var source = '/Users/Andy/Documents/work/tickTock/TikTokDownload/Download/post/Milo大人/2022-10-10 15.06.20广东有了秋天的感觉#生活碎片_#秋天_#粤语_#风里有了秋的味道.mp4';
+    ffmpeg.setFfmpegPath(pathToFfmpeg).addInput(source)
+    .output('output/output.flv')
+    .on('end', function () {
+        console.log('Finished processing');
+    })
+    .run();
+}
+
+const dyGetBtn = document.getElementById('dyGet')
+dyGetBtn.onclick = function (e) {
+    console.log(111)
+    let result = axiosGet('https://v.douyin.com/efrHYf2/')
+    // console.log(result);
+}
+
+
+const axiosGet = function (url, params) {
+    return new Promise((resolve, reject) => {
+        axios
+            .get(url, {
+                params,
+            })
+            .then(res => {
+                resolve(res);
+            })
+            .catch(err => {
+                reject(err);
+            });
+    });
+}
+
+const axiosPost = function (url, params) {
+    return new Promise((resolve, reject) => {
+        axios
+            .post(url, params)
+            .then(res => {
+                resolve(res);
+            })
+            .catch(err => {
+                reject(err);
+            });
+    });
+}