Compare commits
344 Commits
v2.0.0-beta.2
...
v2.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 62ae0e5075 | |||
| 7513fe2882 | |||
| c945dc8360 | |||
| de7e0da045 | |||
| a706429395 | |||
| f26c9761c3 | |||
| 9424dd4c0e | |||
| 271294a8e7 | |||
| 6b2786292f | |||
| c36247b5e1 | |||
| c182afff2c | |||
| 1129d70dca | |||
| bde71d13f9 | |||
| 67b513d380 | |||
| 8d8d1ee238 | |||
| 7c10715607 | |||
| a939f06fcd | |||
| c50625b0c8 | |||
| bfa2d88935 | |||
| b04ea61e83 | |||
| 2a42a02f3d | |||
| 1e80278a1d | |||
| f38d9156c5 | |||
| 0f32864079 | |||
| f8fbecebc9 | |||
| 40c5656080 | |||
| ddf36a7091 | |||
| 258c67554d | |||
| 007ff31200 | |||
| ff75e3d94b | |||
| aaa18e0048 | |||
| 5c6f89a067 | |||
| c4efc4c293 | |||
| 2d955257e6 | |||
| 3cf84a2992 | |||
| 94a795fe69 | |||
| cc10ae8b2e | |||
| 63ed7cdaca | |||
| 064919e0a2 | |||
| 31b2652c9b | |||
| d080d709d1 | |||
| 0c301c79f2 | |||
| a1dbb6234f | |||
| 30248194af | |||
| 8f54ebeb3a | |||
| d8ef0b9eee | |||
| 6a3bfd071a | |||
| 849df04c05 | |||
| a40ae5ef82 | |||
| 00c535665f | |||
| 8b4a4d8ff8 | |||
| f9fecd541c | |||
| 93b1028498 | |||
| a0a3dba188 | |||
| 92ded00495 | |||
| bcbe258f60 | |||
| 660f9c7c9b | |||
| 8c5ef29894 | |||
| 612fc4c533 | |||
| 635377d227 | |||
| dc86ab8f4c | |||
| 36b63ad916 | |||
| e1b378811d | |||
| 37fb9bba75 | |||
| 848253c678 | |||
| b64e779ed1 | |||
| 046a62cde3 | |||
| 1a9e6efb90 | |||
| fd422c15ba | |||
| c338f76f8d | |||
| 4285b3f4f7 | |||
| d0109869a6 | |||
| d29ad44c54 | |||
| be61b07fea | |||
| e5e171fb6f | |||
| 805d97c3ca | |||
| 040222f259 | |||
| 09ed55eba4 | |||
| a6d4f8cf98 | |||
| d19b2394e8 | |||
| 036a99d84d | |||
| b022335af7 | |||
| a66c20c9d5 | |||
| f9fc135647 | |||
| fbbee9c114 | |||
| a65fbcbaf8 | |||
| 39b68b71d4 | |||
| 4d12a0a937 | |||
| 960973302e | |||
| 1a68b00bdd | |||
| dba73fc473 | |||
| 211f7314ce | |||
| 64d719a63a | |||
| 0304e6b569 | |||
| 190447a0bd | |||
| 497d1265f0 | |||
| 6d459e0692 | |||
| 45cde40cea | |||
| e9deb4c7f7 | |||
| 1abfc763dc | |||
| b84ddcc88d | |||
| 33f7951901 | |||
| d3354f9109 | |||
| d252816cc3 | |||
| 6e31904e95 | |||
| 2825d1f4c7 | |||
| fcb10c6137 | |||
| f564739578 | |||
| 40faf4b383 | |||
| affff353bd | |||
| f410fabff7 | |||
| 7d4b201b6e | |||
| a9ac0aa16b | |||
| 5419970080 | |||
| 506a573180 | |||
| 17b2450b43 | |||
| 2942e65a54 | |||
| 913a7bd9e5 | |||
| c5f2edd9de | |||
| 24d511e6b6 | |||
| 47f3336f9a | |||
| e0e6e5dbed | |||
| aa7f3e7bf7 | |||
| 065a6c45f7 | |||
| b13174dda1 | |||
| 9e6a931a41 | |||
| cdabdfd2f8 | |||
| b4cdbd7547 | |||
| 75fe603919 | |||
| 16ef9ae642 | |||
| 7db3162748 | |||
| 3f0e6d9856 | |||
| d87fc4a400 | |||
| ec6241b79e | |||
| 9b37398e9f | |||
| 3fca8694ee | |||
| 78efffa29b | |||
| 737ecbdadd | |||
| fa6ce22ea7 | |||
| 315c55c844 | |||
| d9ba60e1a5 | |||
| 7503322d01 | |||
| 2e5f2dc687 | |||
| e4afd27908 | |||
| 6fe5d5523e | |||
| 7335946ec2 | |||
| eb4576de9b | |||
| 1e41a9ee99 | |||
| dd5226ab47 | |||
| 989e5535eb | |||
| 65efeed692 | |||
| fcddb2d382 | |||
| bbc892ec81 | |||
| ca1c2821a7 | |||
| c8d4f763fd | |||
| a3d587af44 | |||
| ce2146cc89 | |||
| 8455f17517 | |||
| c075bdd4f9 | |||
| 65d88d0896 | |||
| 1c62640301 | |||
| dd6684c550 | |||
| 2e1a753583 | |||
| cbf6e4ecfb | |||
| 5af471fe1a | |||
| 0deb205faa | |||
| 73eaf0ecaa | |||
| 4791defbdd | |||
| 926249184b | |||
| 659b2755ef | |||
| e9d36edaa4 | |||
| fdcdbf27eb | |||
| 2f5cc2eb80 | |||
| c087fa4956 | |||
| ed33ec6532 | |||
| 2d96c2730c | |||
| 5bcec10be3 | |||
| 207bd15b14 | |||
| 00f0bfc84b | |||
| 7bc3f83c88 | |||
| 1af2803c22 | |||
| fd6a81abfd | |||
| a383093914 | |||
| 13656429af | |||
| bc34881b38 | |||
| e3b11cb087 | |||
| 8df78ca377 | |||
| f12919c6bc | |||
| 00df324ae7 | |||
| f14f9ffc1b | |||
| a388b725bc | |||
| e64eaeefef | |||
| 6830d69b62 | |||
| 8f609a8e93 | |||
| 99c23f47c5 | |||
| 95f9e20f39 | |||
| df1e664bc9 | |||
| fec30a6453 | |||
| a048211486 | |||
| 465e9b2988 | |||
| af1ff19cb2 | |||
| eae470f2ec | |||
| 1933799e32 | |||
| c7977bf7b4 | |||
| ce8407ce46 | |||
| 5d313df190 | |||
| c560a09904 | |||
| df66a92989 | |||
| 52c9611e49 | |||
| 4018112a1d | |||
| 633a257e65 | |||
| 0666d41226 | |||
| c2cfe55e24 | |||
| cb7fbddd7a | |||
| 135d9fed1b | |||
| 267aedc594 | |||
| 325d0da930 | |||
| 615bc74d15 | |||
| 1ca6935d36 | |||
| 3bfb7139d3 | |||
| 14d44765e5 | |||
| 807dd2d920 | |||
| c9a0a7f7c2 | |||
| a3eea6d501 | |||
| 4ce7dcac1b | |||
| 096762f24c | |||
| baf358d223 | |||
| e72973346b | |||
| 41258ecee8 | |||
| b6a5be152a | |||
| d5d45c4935 | |||
| 81eb4ecf09 | |||
| 5a4cc8c449 | |||
| e7ab664310 | |||
| 3cb2fa27b9 | |||
| e29e41aa4c | |||
| cc62613640 | |||
| 2720bcc685 | |||
| c8ac4182fc | |||
| 55b70d3e6d | |||
| a19765b0d3 | |||
| 5c7b65385a | |||
| b6b84269a3 | |||
| e44cb249d0 | |||
| 8bea071865 | |||
| a782652fca | |||
| 3a02803d3c | |||
| 263a08ab4c | |||
| ecdbd985ce | |||
| dd403564cc | |||
| 69d741b39a | |||
| 4c9c2e2d68 | |||
| 8660701340 | |||
| 341c5570af | |||
| ee12753818 | |||
| 055638278c | |||
| bf06ff6482 | |||
| 459a5bc5b7 | |||
| a93f18037c | |||
| 67b5218002 | |||
| d3c745dda4 | |||
| e694818f8f | |||
| 729d7645e1 | |||
| 795e21df9c | |||
| bdc15e6c50 | |||
| c3398ec572 | |||
| 6b38b348fc | |||
| d650529842 | |||
| 2094408f52 | |||
| 89cb8b3a3a | |||
| 7a2d546972 | |||
| 69e801ba2b | |||
| 14edc27ed1 | |||
| 6f7fa7f067 | |||
| a5a1c02e10 | |||
| ce08cbce4b | |||
| e03a5d38bb | |||
| 720db5a476 | |||
| e97783b08e | |||
| 12566f8668 | |||
| d686819417 | |||
| ea7b4a77af | |||
| 6427a06879 | |||
| f2f7a50e95 | |||
| fbc57ebfca | |||
| 26a5681dab | |||
| 4640ff51e8 | |||
| b3b58680e0 | |||
| d1b75df87d | |||
| 4b4e1b9f54 | |||
| 8ebb550270 | |||
| 6b93954246 | |||
| 550d7ebd4b | |||
| 3f331e5d3d | |||
| 020f921af8 | |||
| efa72ce12b | |||
| 38ead633a5 | |||
| 3eb1d0ae99 | |||
| 7bed4ed335 | |||
| b357d41f23 | |||
| 3834603b0a | |||
| f38ba108a3 | |||
| 7ceda3d73f | |||
| aee57b6f98 | |||
| f9d49bd55f | |||
| 3bb082473a | |||
| 31b6726fe5 | |||
| 348b41b0dd | |||
| d4bbfa0516 | |||
| b2af9b3d25 | |||
| ded93a4f0b | |||
| d43f57565b | |||
| 34cf661fb2 | |||
| 91cfb883b6 | |||
| 1cb7deb376 | |||
| 70933c63bb | |||
| 5723b9edd0 | |||
| 65f37a9c66 | |||
| 57516793ab | |||
| afecc5ac12 | |||
| 3331564155 | |||
| 19ce7b9906 | |||
| 40f39340f0 | |||
| f085bcacf7 | |||
| dbd4e73b6e | |||
| b35e6b3315 | |||
| 3c603a67dd | |||
| 8ff5abf5d8 | |||
| 0fdbd39393 | |||
| df93770128 | |||
| b61a935068 | |||
| 95e96b1057 | |||
| 3dd325a280 | |||
| bbe922df74 | |||
| e31eddfd2e | |||
| bbb9f5798b | |||
| b634cf056d | |||
| 2ede22b50a | |||
| a4efd83f7a | |||
| c3ebced763 | |||
| 6cb6621df1 | |||
| 4e5febba8b | |||
| 1fb787d4ea | |||
| f24ddaa55e |
@@ -0,0 +1,40 @@
|
||||
acodec
|
||||
adblocker
|
||||
ahooks
|
||||
antd
|
||||
behaviour
|
||||
bili
|
||||
bilibili
|
||||
bodys
|
||||
cancle
|
||||
cliqz
|
||||
commitlint
|
||||
Conpty
|
||||
consola
|
||||
conventionalcommits
|
||||
datetime
|
||||
DDTHH
|
||||
execa
|
||||
immer
|
||||
inversify
|
||||
KHTML
|
||||
languagedetector
|
||||
localforage
|
||||
mediago
|
||||
metas
|
||||
nocheck
|
||||
optimizelegibility
|
||||
pinia
|
||||
redownload
|
||||
Redownload
|
||||
reduxjs
|
||||
Sider
|
||||
stylelint
|
||||
svgz
|
||||
TDAPP
|
||||
tiptap
|
||||
typeorm
|
||||
vuedraggable
|
||||
vuejs
|
||||
watting
|
||||
Watting
|
||||
@@ -0,0 +1,4 @@
|
||||
APP_NAME=mediago
|
||||
APP_ID=mediago.ziying.site
|
||||
APP_COPYRIGHT=caorushizi
|
||||
APP_VERSION=2.2.2
|
||||
@@ -1,8 +1,6 @@
|
||||
APP_NAME=media-downloader
|
||||
APP_ID=mediago.ziying.site
|
||||
APP_COPYRIGHT=caorushizi
|
||||
APP_VERSION=2.0.0
|
||||
APP_TD_APPID=
|
||||
APP_CLARITY_APPID=
|
||||
|
||||
DOWNLOAD_DEBUG=true
|
||||
GH_TOKEN=
|
||||
LOAD_DEVTOOLS=
|
||||
DEBUG_PLUGINS=true
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
APP_NAME=media-downloader
|
||||
APP_ID=mediago.ziying.site
|
||||
APP_COPYRIGHT=caorushizi
|
||||
APP_VERSION=2.0.0
|
||||
APP_TD_APPID=
|
||||
APP_CLARITY_APPID=
|
||||
|
||||
DOWNLOAD_DEBUG=false
|
||||
GH_TOKEN=
|
||||
DEBUG_PLUGINS=false
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "" # See documentation for possible values
|
||||
- package-ecosystem: "npm" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
# build.yml
|
||||
|
||||
# Workflow's name
|
||||
name: Build Downloader App.
|
||||
|
||||
# Workflow's trigger
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
# Workflow's jobs
|
||||
jobs:
|
||||
# job's id
|
||||
release:
|
||||
# job's name
|
||||
name: build and release electron app
|
||||
|
||||
# the type of machine to run the job on
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
# create a build matrix for jobs
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest, macos-latest, ubuntu-latest]
|
||||
|
||||
# create steps
|
||||
steps:
|
||||
# step1: check out repository
|
||||
- name: Check out git repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# step2: install node env
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
# step4: install python env
|
||||
- name: Install Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.10"
|
||||
|
||||
# step5: install pnpm env
|
||||
- uses: pnpm/action-setup@v3
|
||||
with:
|
||||
version: latest
|
||||
run_install: true
|
||||
standalone: true
|
||||
|
||||
- name: Build & release app
|
||||
run: pnpm run release
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
APP_TD_APPID: ${{ secrets.APP_TD_APPID }}
|
||||
APP_CLARITY_APPID: ${{ secrets.APP_CLARITY_APPID}}
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: mediago-${{ matrix.os }}
|
||||
path: packages/main/release/mediago-setup-*
|
||||
@@ -0,0 +1,52 @@
|
||||
name: Deploy Downloader Docs.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["master"]
|
||||
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: false
|
||||
|
||||
env:
|
||||
BUCKET: downloader-docs
|
||||
ENDPOINT: oss-cn-beijing.aliyuncs.com
|
||||
ACCESS_KEY: LTAI5tLckcUrBtj7bCiUYwWz
|
||||
ACCESS_KEY_SECRET: ${{ secrets.ACCESS_KEY_SECRET }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- uses: pnpm/action-setup@v3
|
||||
with:
|
||||
version: latest
|
||||
run_install: true
|
||||
|
||||
- name: Build with Vitepress
|
||||
run: pnpm run docs:build
|
||||
|
||||
- name: Install Alibaba Cloud OSSUTIL
|
||||
run: wget http://gosspublic.alicdn.com/ossutil/1.6.10/ossutil64 && chmod +x ossutil64
|
||||
|
||||
- name: Configure Alibaba Cloud OSSUTIL
|
||||
run: ./ossutil64 config -i ${ACCESS_KEY} -k ${ACCESS_KEY_SECRET} -e ${ENDPOINT} -c .ossutilconfig
|
||||
|
||||
- name: Upload the web folder to the chosen OSS bucket
|
||||
run: ./ossutil64 --config-file .ossutilconfig cp ${{ github.workspace }}/docs/.vitepress/dist oss://${BUCKET} -r -f
|
||||
@@ -1,4 +1,6 @@
|
||||
node_modules
|
||||
.vscode
|
||||
*.local
|
||||
.idea
|
||||
.parcel-cache
|
||||
.vitepress
|
||||
*.tsno.mjs
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npx --no -- commitlint --edit ${1}
|
||||
npm run commitlint ${1}
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx tsx ./scripts/pre-commit.ts
|
||||
@@ -1,2 +1,3 @@
|
||||
registry=https://registry.npmmirror.com/
|
||||
electron_mirror=https://npm.taobao.org/mirrors/electron/
|
||||
registry=https://registry.npmmirror.com
|
||||
electron_mirror=https://npmmirror.com/mirrors/electron/
|
||||
package-manager=pnpm
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Ignore artifacts:
|
||||
build
|
||||
coverage
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch dev",
|
||||
"runtimeExecutable": "npm",
|
||||
"runtimeArgs": ["run-script", "dev"],
|
||||
"skipFiles": ["<node_internals>/**"]
|
||||
},
|
||||
{
|
||||
"name": "Attach to Electron",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"address": "localhost",
|
||||
"restart": true,
|
||||
"timeout": 10000,
|
||||
"localRoot": "${workspaceFolder}",
|
||||
"remoteRoot": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,38 +1,91 @@
|
||||
# media-downloader
|
||||
<img src="https://socialify.git.ci/caorushizi/mediago/image?font=Inter&forks=1&issues=1&language=1&name=1&owner=1&pattern=Circuit%20Board&pulls=1&stargazers=1&theme=Auto" alt="MediaDownloader"/>
|
||||
|
||||
m3u8 视频在线提取工具 流媒体下载 m3u8下载 桌面客户端 windows mac。
|
||||
可以直接在线获取 m3u8 链接地址,无需使用使用网络抓包,无需安装浏览器插件,可以直接带出请求标头……
|
||||
<div align="center">
|
||||
<h1>MediaGo</h1>
|
||||
<a href="https://downloader.caorushizi.cn/guides.html?form=github">快速开始</a>
|
||||
<span> • </span>
|
||||
<a href="https://downloader.caorushizi.cn?form=github">官网</a>
|
||||
<span> • </span>
|
||||
<a href="https://downloader.caorushizi.cn/documents.html?form=github">文档</a>
|
||||
<span> • </span>
|
||||
<a href="https://github.com/caorushizi/mediago/discussions">Discussions</a>
|
||||
<br>
|
||||
<br>
|
||||
|
||||
模板: <https://github.com/caorushizi/electron-template>
|
||||
<img alt="GitHub Downloads (all assets, all releases)" src="https://img.shields.io/github/downloads/caorushizi/mediago/total">
|
||||
<img alt="GitHub Downloads (all assets, latest release)" src="https://img.shields.io/github/downloads/caorushizi/mediago/latest/total">
|
||||
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/caorushizi/mediago">
|
||||
<img alt="GitHub forks" src="https://img.shields.io/github/forks/caorushizi/mediago">
|
||||
|
||||
## 上手指南
|
||||
<hr />
|
||||
</div>
|
||||
|
||||
以下指南将帮助你在本地机器上安装和运行该项目,进行开发和测试。关于如何将该项目部署到在线环境,请参考部署小节。
|
||||
## Intro
|
||||
|
||||
## 安装要求
|
||||
本项目支持 m3u8 视频在线提取工具 流媒体下载 m3u8 下载。
|
||||
|
||||
运行代码需要 node 和 pnpm,node需要在官网下载安装,pnpm 可以通过`npm i -g pnpm`安装。
|
||||
- **✅ 无需抓包**: 使用软件自带浏览器可以轻松嗅探网页中的视频资源,通过嗅探到的资源列表选择自己想要下载的资源,简单快速。
|
||||
- **📱 移动播放**: 可以轻松无缝的在 PC 和移动设备之前切换,下载完成后即可使用手机观看视频。
|
||||
- **⚡️ 批量下载**: 支持同时下载多个视频和直播资源,高速带宽不闲置。
|
||||
|
||||
## Quickstart
|
||||
|
||||
运行代码需要 node 和 pnpm,node 需要在官网下载安装,pnpm 可以通过`npm i -g pnpm`安装。
|
||||
|
||||
## 运行代码
|
||||
|
||||
安装依赖 `pnpm i`
|
||||
```shell
|
||||
# 代码下载
|
||||
git clone https://github.com/caorushizi/mediago.git
|
||||
|
||||
开发环境 `pnpm run dev`
|
||||
# 安装依赖
|
||||
pnpm i
|
||||
|
||||
打包运行 `pnpm run release`
|
||||
# 开发环境
|
||||
pnpm dev
|
||||
|
||||
## 下载链接
|
||||
# 打包运行
|
||||
pnpm release
|
||||
```
|
||||
|
||||
- [v1.1.3 windows](https://github.com/caorushizi/m3u8-downloader/releases/download/1.1.3/media-downloader-setup-1.1.3.exe)
|
||||
- [v1.0.3 windows](http://static.ziying.site/media-downloader-1.0.3%20Setup.exe)
|
||||
## Releases
|
||||
|
||||
**v2.2.0 (2024.5.22 发布)**
|
||||
|
||||
- [windows mediago v2.2.0](https://github.com/caorushizi/mediago/releases/download/v2.2.0/mediago-setup-2.2.0.exe)
|
||||
- [macos mediago v2.2.0](https://github.com/caorushizi/mediago/releases/download/v2.2.0/mediago-setup-2.2.0.dmg)
|
||||
|
||||
**更新日志**
|
||||
|
||||
- 支持下载直播流
|
||||
- 支持哔哩哔哩视频下载
|
||||
- 优化沉浸式嗅探流程
|
||||
- 支持下载控制台输出
|
||||
- 修复了一些 bug
|
||||
|
||||
**v2.0.2(2023.7.9 发布)**
|
||||
|
||||
- [windows mediago v2.0.2](https://github.com/caorushizi/mediago/releases/download/v2.0.2/media-downloader-setup-2.0.2.exe)
|
||||
- [macos mediago v2.0.2](https://github.com/caorushizi/mediago/releases/download/v2.0.2/media-downloader-setup-2.0.2.dmg)
|
||||
|
||||
**更新日志**
|
||||
|
||||
- 暗黑模式
|
||||
- 更多下载配置
|
||||
- 支持请求标头自动带入
|
||||
- 支持开启广告过滤
|
||||
- 支持开启沉浸式嗅探
|
||||
- 支持切换手机和 PC 模式
|
||||
- 支持修改同时下载数量
|
||||
- 修复了一些 bug
|
||||
|
||||
## 软件截图
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
## 技术栈
|
||||
|
||||
@@ -42,6 +95,4 @@ m3u8 视频在线提取工具 流媒体下载 m3u8下载 桌面客户端 windows
|
||||
|
||||
## 鸣谢
|
||||
|
||||
N_m3u8DL-CLI 来自于 <https://github.com/nilaoda/N_m3u8DL-CLI>
|
||||
|
||||
mediago 来自于 <https://github.com/caorushizi/mediago>
|
||||
N_m3u8DL-RE 来自于 <https://github.com/nilaoda/N_m3u8DL-RE>
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
export default {
|
||||
extends: ["@commitlint/config-conventional"], // extends can be nested
|
||||
parserPreset: "conventional-changelog-conventionalcommits",
|
||||
prompt: {
|
||||
settings: {},
|
||||
messages: {
|
||||
skip: ":skip",
|
||||
max: "upper %d chars",
|
||||
min: "%d chars at least",
|
||||
emptyWarning: "can not be empty",
|
||||
upperLimitWarning: "over limit",
|
||||
lowerLimitWarning: "below limit",
|
||||
},
|
||||
types: [
|
||||
{ value: "feat", name: "feat: ✨ A new feature", emoji: "✨ " },
|
||||
{ value: "fix", name: "fix: 🐛 A bug fix", emoji: "🐛 " },
|
||||
{
|
||||
value: "docs",
|
||||
name: "docs: 📝 Documentation only changes",
|
||||
emoji: "📝 ",
|
||||
},
|
||||
{
|
||||
value: "style",
|
||||
name: "style: 💄 Changes that do not affect the meaning of the code",
|
||||
emoji: "💄 ",
|
||||
},
|
||||
{
|
||||
value: "refactor",
|
||||
name: "refactor: 📦️ A code change that neither fixes a bug nor adds a feature",
|
||||
emoji: "📦️ ",
|
||||
},
|
||||
{
|
||||
value: "perf",
|
||||
name: "perf: 🚀 A code change that improves performance",
|
||||
emoji: "🚀 ",
|
||||
},
|
||||
{
|
||||
value: "test",
|
||||
name: "test: 🚨 Adding missing tests or correcting existing tests",
|
||||
emoji: "🚨 ",
|
||||
},
|
||||
{
|
||||
value: "build",
|
||||
name: "build: 🛠 Changes that affect the build system or external dependencies",
|
||||
emoji: "🛠 ",
|
||||
},
|
||||
{
|
||||
value: "ci",
|
||||
name: "ci: 🎡 Changes to our CI configuration files and scripts",
|
||||
emoji: "🎡 ",
|
||||
},
|
||||
{
|
||||
value: "chore",
|
||||
name: "chore: 🔨 Other changes that don't modify src or test files",
|
||||
emoji: "🔨 ",
|
||||
},
|
||||
{
|
||||
value: "revert",
|
||||
name: "revert: ⏪️ Reverts a previous commit",
|
||||
emoji: ":rewind:",
|
||||
},
|
||||
],
|
||||
useEmoji: true,
|
||||
confirmColorize: true,
|
||||
emojiAlign: "center",
|
||||
questions: {
|
||||
scope: {
|
||||
description:
|
||||
"What is the scope of this change (e.g. component or file name)",
|
||||
},
|
||||
subject: {
|
||||
description:
|
||||
"Write a short, imperative tense description of the change",
|
||||
},
|
||||
body: {
|
||||
description: "Provide a longer description of the change",
|
||||
},
|
||||
isBreaking: {
|
||||
description: "Are there any breaking changes?",
|
||||
},
|
||||
breakingBody: {
|
||||
description:
|
||||
"A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself",
|
||||
},
|
||||
breaking: {
|
||||
description: "Describe the breaking changes",
|
||||
},
|
||||
isIssueAffected: {
|
||||
description: "Does this change affect any open issues?",
|
||||
},
|
||||
issuesBody: {
|
||||
description:
|
||||
"If issues are closed, the commit requires a body. Please enter a longer description of the commit itself",
|
||||
},
|
||||
issues: {
|
||||
description: 'Add issue references (e.g. "fix #123", "re #123".)',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"import": [
|
||||
"@cspell/dict-lorem-ipsum/cspell-ext.json"
|
||||
],
|
||||
"caseSensitive": false,
|
||||
"dictionaries": [
|
||||
"custom-words"
|
||||
],
|
||||
"dictionaryDefinitions": [
|
||||
{
|
||||
"name": "custom-words",
|
||||
"path": "./.cspell/custom-words.txt",
|
||||
"addWords": true
|
||||
}
|
||||
],
|
||||
"ignorePaths": [
|
||||
"**/node_modules/**",
|
||||
"**/dist/**",
|
||||
"**/lib/**",
|
||||
"**/docs/**",
|
||||
"**/stats.html"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
.vitepress/dist
|
||||
.vitepress/cache
|
||||
@@ -0,0 +1,62 @@
|
||||
import { HeadConfig, defineConfig } from "vitepress";
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development";
|
||||
|
||||
const head: HeadConfig[] = [
|
||||
["link", { rel: "shortcut icon", href: "/favicon.svg" }],
|
||||
];
|
||||
if (!isDev) {
|
||||
head.push([
|
||||
"script",
|
||||
{},
|
||||
`var _hmt = _hmt || [];
|
||||
(function() {
|
||||
var hm = document.createElement("script");
|
||||
hm.src = "https://hm.baidu.com/hm.js?eefcbd14f0323044aa0ca678cd278381";
|
||||
var s = document.getElementsByTagName("script")[0];
|
||||
s.parentNode.insertBefore(hm, s);
|
||||
})();`,
|
||||
]);
|
||||
}
|
||||
|
||||
// https://vitepress.dev/reference/site-config
|
||||
export default defineConfig({
|
||||
title: "MediaGo",
|
||||
description: "简单易用,快速下载",
|
||||
lastUpdated: true,
|
||||
head,
|
||||
themeConfig: {
|
||||
// https://vitepress.dev/reference/default-theme-config
|
||||
nav: [
|
||||
{ text: "Home", link: "/" },
|
||||
{ text: "教程", link: "/guides" },
|
||||
],
|
||||
|
||||
sidebar: [
|
||||
{
|
||||
text: "开始",
|
||||
items: [
|
||||
{ text: "快速开始", link: "/guides" },
|
||||
{ text: "使用说明", link: "/documents" },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: "其他",
|
||||
items: [
|
||||
{ text: "旧版本", link: "/history" },
|
||||
{ text: "意见收集", link: "/proposal" },
|
||||
{ text: "支持列表", link: "/list" },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
socialLinks: [
|
||||
{ icon: "github", link: "https://github.com/caorushizi/m3u8-downloader" },
|
||||
],
|
||||
|
||||
footer: {
|
||||
message: '<a href="https://beian.miit.gov.cn">豫ICP备20012967号-2</a>',
|
||||
copyright: "Copyright © 2021-present caorushizi",
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, watch, ref, watchEffect } from "vue";
|
||||
import { init, WalineInstance } from "@waline/client";
|
||||
import "@waline/client/waline.css";
|
||||
import { useData, useRoute } from "vitepress";
|
||||
|
||||
const route = useRoute();
|
||||
const { isDark } = useData();
|
||||
|
||||
const commentsRef = ref<WalineInstance | null>(null);
|
||||
|
||||
watchEffect(() => {
|
||||
commentsRef.value?.update({
|
||||
dark: isDark.value,
|
||||
});
|
||||
});
|
||||
|
||||
watch(
|
||||
() => route.path,
|
||||
() => {
|
||||
commentsRef.value?.destroy();
|
||||
initWaline();
|
||||
}
|
||||
);
|
||||
|
||||
function initWaline() {
|
||||
commentsRef.value = init({
|
||||
el: "#waline",
|
||||
serverURL: "https://comments.ziying.site",
|
||||
dark: isDark.value,
|
||||
lang: "zh-CN",
|
||||
pageview: true,
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
initWaline();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div id="waline">hello world</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
#waline {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { h } from "vue";
|
||||
import Theme from "vitepress/theme";
|
||||
import "./style/var.css";
|
||||
import Comments from "./components/Comments.vue";
|
||||
|
||||
export default {
|
||||
...Theme,
|
||||
Layout() {
|
||||
return h(Theme.Layout, null, {
|
||||
"doc-after": () => h(Comments),
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
:root {
|
||||
/* 标题 */
|
||||
--vp-home-hero-name-color: transparent;
|
||||
--vp-home-hero-name-background: linear-gradient(
|
||||
135deg,
|
||||
#5e9ef3 10%,
|
||||
#2a82f6 100%
|
||||
);
|
||||
|
||||
/* 图标背景 */
|
||||
--vp-home-hero-image-background-image: linear-gradient(
|
||||
135deg,
|
||||
#5e9ef3 10%,
|
||||
#2a82f6 100%
|
||||
);
|
||||
--vp-home-hero-image-filter: blur(150px);
|
||||
|
||||
/* brand按钮 */
|
||||
--vp-button-brand-border: #5e9ef3;
|
||||
--vp-button-brand-text: #f2f7fd;
|
||||
--vp-button-brand-bg: #2a82f6;
|
||||
|
||||
--vp-button-brand-active-border: #5e9ef3;
|
||||
--vp-button-brand-active-text: #fff;
|
||||
--vp-button-brand-active-bg: #409eff;
|
||||
|
||||
--vp-button-brand-hover-border: #5e9ef3;
|
||||
--vp-button-brand-hover-text: #fff;
|
||||
--vp-button-brand-hover-bg: #2a82f6;
|
||||
|
||||
--vp-c-brand: #2a82f6;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
---
|
||||
layout: doc
|
||||
outline: deep
|
||||
---
|
||||
|
||||
# 使用说明
|
||||
|
||||
这个页面主要讲解的是设置页面的参数的含义
|
||||
|
||||

|
||||
|
||||
## 基础设置
|
||||
|
||||
::: tip
|
||||
下载器全局设置
|
||||
:::
|
||||
|
||||
1. 选择文件夹: 视频下载的路径
|
||||
|
||||
2. 下载器主题: 支持浅色和深色模式
|
||||
|
||||
3. 在新窗口中打开浏览器: 开启了之后浏览器页面会独立出一个窗口。
|
||||
|
||||

|
||||
|
||||
4. 下载完成提示: 开启之后下载完成会出现系统提示
|
||||
|
||||
## 浏览器设置
|
||||
|
||||
::: tip
|
||||
浏览器窗口相关的设置
|
||||
:::
|
||||
|
||||
1. 代理设置: 填写自己的代理地址
|
||||
|
||||
2. 代理开关: 打开开关后浏览器默认会走填写的代理地址,如果代理地址这个开关是打不开的
|
||||
|
||||
3. 开启广告过滤: 打开开关后会过滤页面中的广告
|
||||
|
||||
4. 以手机模式进入: 打开后会将浏览器伪装成手机浏览器,请求移动端的站点(左侧是开启手机模式的截图)
|
||||
|
||||

|
||||
|
||||
5. 使用浏览器插件
|
||||
|
||||
- 打开状态: 从浏览器中嗅探到的资源不会自动添加到下载列表,需要手动点击页面下方的下载的链接来添加视频到下载列表 **(后面会有很强大的功能哦)**
|
||||
|
||||

|
||||
|
||||
- 关闭状态: 浏览器中嗅探到的资源会自动添加到下载列表
|
||||
|
||||
## 下载设置
|
||||
|
||||
::: tip
|
||||
和下载相关的设置
|
||||
:::
|
||||
|
||||
1. 下载完成删除分片: 开启后下载完成后会将分片文件删除
|
||||
2. 最大同时下载数量: 最多同时可以下载多少视频文件,目前最大是 10,最小是 1
|
||||
3. 更多操作
|
||||
- 配置文件目录: 软件数据库路径、日志等等路径
|
||||
- 可执行文件目录: 下载器二进制文件的路径
|
||||
- 本地存储路径: 下载视频的本地路径
|
||||
4. 当前版本: 当前软件版本信息
|
||||
|
||||
## 其他问题
|
||||
|
||||
**Q: 关于直播视频的下载**
|
||||
|
||||
A: 软件支持直播下载,软件目前没有好的办法区分直播流,所以将所有的下载控制台开启。用户自行分辨下载数据源
|
||||
|
||||
**Q: 关于 MacOS 版本**
|
||||
|
||||
A: 目前 MacOS 版本属于非稳定版本,2023 年 5 月发布。需要在 Mac 的安全设置中打开来自身份不明开发者的 Mac App
|
||||

|
||||
|
||||
**Q: 关于旧版本**
|
||||
|
||||
A: 1.1.5 版本确实发布了很长时间,经过大量用户的验证,比较稳定。所以想要使用旧版软件的话请访问[此链接](/history.html)
|
||||
|
||||
**Q: 关于 Win7 用户**
|
||||
|
||||
A: v2.0.0 之后的版本已经放弃不支持 Win7 如果需要在 win7 上面使用同样需要下载 1.1.5 版本
|
||||
@@ -0,0 +1,109 @@
|
||||
---
|
||||
layout: doc
|
||||
outline: deep
|
||||
---
|
||||
|
||||
# 快速开始
|
||||
|
||||
这篇文章是软件的简单说明,可以快速上手使用本本软件。
|
||||
|
||||
::: tip
|
||||
我建了一个 QQ 群,方便大家一起沟通交流: 574209001
|
||||
:::
|
||||
|
||||
## 下载安装
|
||||
|
||||
**v2.2.0 (2024.5.22 发布)**
|
||||
|
||||
- [windows mediago v2.2.0](https://github.com/caorushizi/mediago/releases/download/v2.2.0/mediago-setup-2.2.0.exe)
|
||||
- [macos mediago v2.2.0](https://github.com/caorushizi/mediago/releases/download/v2.2.0/mediago-setup-2.2.0.dmg)
|
||||
|
||||
**更新日志**
|
||||
|
||||
- 支持下载直播流
|
||||
- 支持哔哩哔哩视频下载
|
||||
- 优化沉浸式嗅探流程
|
||||
- 支持下载控制台输出
|
||||
- 修复了一些 bug
|
||||
|
||||
**v2.0.1(2023.7.1 发布)**
|
||||
|
||||
- [windows mediago v2.0.1](https://github.com/caorushizi/mediago/releases/download/v2.0.1/media-downloader-setup-2.0.1.exe)
|
||||
- [macos mediago v2.0.1](https://github.com/caorushizi/mediago/releases/download/v2.0.1/media-downloader-setup-2.0.1.dmg)
|
||||
|
||||
**更新日志**
|
||||
|
||||
- 暗黑模式
|
||||
- 更多下载配置
|
||||
- 支持请求标头自动带入
|
||||
- 支持开启广告过滤
|
||||
- 支持开启沉浸式嗅探
|
||||
- 支持切换手机和 PC 模式
|
||||
- 支持修改同时下载数量
|
||||
- 修复了一些 bug
|
||||
|
||||
**v1.1.5(2022.2.5 发布)**
|
||||
|
||||
- [windows mediago v1.1.5](https://github.com/caorushizi/mediago/releases/download/1.1.5/media-downloader-setup-1.1.4.exe)
|
||||
|
||||
**更新日志**
|
||||
|
||||
- 支持视频下载
|
||||
|
||||
## 操作说明
|
||||
|
||||
### 视频自动嗅探
|
||||
|
||||
1. 选择【资源提取】
|
||||
|
||||

|
||||
|
||||
2. 进入视频的网址
|
||||
|
||||

|
||||
|
||||
3. 开始下载,即可下载视频
|
||||
|
||||

|
||||
|
||||
### 手动下载
|
||||
|
||||
1. 点击页面右上角的【新建下载】
|
||||
|
||||

|
||||
|
||||
2. 在新建下载弹窗中填入【视频名称】和【m3u8 地址】即可
|
||||
|
||||

|
||||
|
||||
3. 在列表中点击下载,即可下载视频
|
||||
|
||||

|
||||
|
||||
## 附加功能
|
||||
|
||||
1. 下载完成后可以在下载列表中点击转换音频按钮将视频转换为音频
|
||||
|
||||

|
||||
|
||||
2. 下载完成后播放视频
|
||||
|
||||
- PC 播放
|
||||
|
||||

|
||||
|
||||
- 移动端播放
|
||||
|
||||

|
||||
|
||||
3. 批量下载
|
||||
|
||||

|
||||
|
||||
## 开始你的视频下载吧
|
||||
|
||||
是不是很简单,快去下载你的视频吧
|
||||
|
||||
::: warning
|
||||
本软件仅可用于学习交流
|
||||
:::
|
||||
@@ -0,0 +1,21 @@
|
||||
---
|
||||
layout: doc
|
||||
outline: deep
|
||||
---
|
||||
|
||||
# 旧版本
|
||||
|
||||
::: info
|
||||
这里是旧版本的永久链接,如果有需求的话,可以在这里下载
|
||||
|
||||
**这个链接的软件不会自动升级, 可放心使用**
|
||||
:::
|
||||
|
||||
**v1.1.5(2022.2.5 发布)**
|
||||
|
||||
- [windows mediago v1.1.5](https://github.com/caorushizi/mediago/releases/download/1.1.5/media-downloader-setup-1.1.4.exe)
|
||||
- ~~macos mediago v1.1.5 无~~
|
||||
|
||||
**更新日志**
|
||||
|
||||
- 支持视频下载
|
||||
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 311 KiB |
|
After Width: | Height: | Size: 129 KiB |
|
After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,30 @@
|
||||
---
|
||||
# https://vitepress.dev/reference/default-theme-home-page
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: "在线视频下载"
|
||||
text: "简单易用,快速下载"
|
||||
tagline: 简单易学,无需抓包,不需要安装插件
|
||||
image:
|
||||
src: /home.png
|
||||
alt: home
|
||||
actions:
|
||||
- theme: brand
|
||||
text: 快速开始
|
||||
link: /guides
|
||||
- theme: alt
|
||||
text: 使用说明
|
||||
link: /documents
|
||||
|
||||
features:
|
||||
- icon: ⏩
|
||||
title: 无需抓包
|
||||
details: 使用软件自带浏览器可以轻松嗅探网页中的视频资源,通过嗅探到的资源列表选择自己想要下载的资源,简单快速。
|
||||
- icon: 📱
|
||||
title: 移动播放
|
||||
details: 可以轻松无缝的在PC和移动设备之前切换,下载完成后即可使用手机观看视频。
|
||||
- icon: ⚡️
|
||||
title: 支持批量下载
|
||||
details: 支持同时下载多个视频和直播资源,高速带宽不闲置。
|
||||
---
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
layout: doc
|
||||
outline: deep
|
||||
---
|
||||
|
||||
# 支持列表
|
||||
|
||||
::: tip
|
||||
大家有什么网站想要支持的在这里提
|
||||
:::
|
||||
|
||||
**模板**
|
||||
|
||||
---
|
||||
|
||||
- 网站首页: xxx
|
||||
- 视频(直播)列表页: xxx
|
||||
- 视频(直播)页: xxx
|
||||
|
||||
---
|
||||
|
||||
支持完成后我会在评论区回复
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
layout: doc
|
||||
outline: deep
|
||||
---
|
||||
|
||||
# 意见收集
|
||||
|
||||
::: info
|
||||
这里手机大家使用软件的问题,或者意见建议
|
||||
:::
|
||||
|
||||
如果软件报错,需要描述清楚在什么网站下载什么视频的时候报错
|
||||
|
||||
如果是建议请描述清楚你的需求
|
||||
|
||||
如果是意见请尽量提出来,我会尽量满足大家的需求
|
||||
@@ -0,0 +1,40 @@
|
||||
<svg t="1686326276609" class="icon" viewBox="0 0 1024 1024" version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg" p-id="6962" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
width="200" height="200">
|
||||
<path
|
||||
d="M110.933333 42.666667h716.8A68.266667 68.266667 0 0 1 896 110.933333v802.133334a68.266667 68.266667 0 0 1-68.266667 68.266666H110.933333A68.266667 68.266667 0 0 1 42.666667 913.066667V110.933333A68.266667 68.266667 0 0 1 110.933333 42.666667z"
|
||||
fill="#111314" fill-opacity=".72" p-id="6963"></path>
|
||||
<path
|
||||
d="M853.333333 42.666667h85.333334a68.266667 68.266667 0 0 1 68.266666 68.266666v802.133334A68.266667 68.266667 0 0 1 938.666667 981.333333h-85.333334a68.266667 68.266667 0 0 0 68.266667-68.266666V110.933333A68.266667 68.266667 0 0 0 853.333333 42.666667z"
|
||||
fill="#CACBCC" p-id="6964"></path>
|
||||
<path
|
||||
d="M162.133333 128h614.4a34.133333 34.133333 0 0 1 34.133334 34.133333v699.733334a34.133333 34.133333 0 0 1-34.133334 34.133333H162.133333a34.133333 34.133333 0 0 1-34.133333-34.133333V162.133333a34.133333 34.133333 0 0 1 34.133333-34.133333z"
|
||||
fill="#FFFFFF" p-id="6965"></path>
|
||||
<path
|
||||
d="M187.733333 170.666667h563.2c9.386667 0 17.066667 7.68 17.066667 17.066666v221.866667a17.066667 17.066667 0 0 1-17.066667 17.066667H187.733333a17.066667 17.066667 0 0 1-17.066666-17.066667V187.733333c0-9.386667 7.68-17.066667 17.066666-17.066666z"
|
||||
fill="#EDEEF0" p-id="6966"></path>
|
||||
<path
|
||||
d="M256 298.666667m17.066667 0l136.533333 0q17.066667 0 17.066667 17.066666l0 136.533334q0 17.066667-17.066667 17.066666l-136.533333 0q-17.066667 0-17.066667-17.066666l0-136.533334q0-17.066667 17.066667-17.066666Z"
|
||||
fill="#FFC13C" p-id="6967"></path>
|
||||
<path
|
||||
d="M341.333333 392.533333a34.133333 34.133333 0 1 1 0-68.266666 34.133333 34.133333 0 0 1 0 68.266666z m65.109334 56.192H276.224C276.224 426.666667 276.224 401.066667 341.333333 401.066667s65.109333 25.6 65.109334 47.658666z"
|
||||
fill="#FFFFFF" p-id="6968"></path>
|
||||
<path
|
||||
d="M469.333333 341.333333m17.066667 0l136.533333 0q17.066667 0 17.066667 17.066667l0 8.533333q0 17.066667-17.066667 17.066667l-136.533333 0q-17.066667 0-17.066667-17.066667l0-8.533333q0-17.066667 17.066667-17.066667Z"
|
||||
fill="#5BADFF" p-id="6969"></path>
|
||||
<path
|
||||
d="M512 554.666667m17.066667 0l179.2 0q17.066667 0 17.066666 17.066666l0 51.2q0 17.066667-17.066666 17.066667l-179.2 0q-17.066667 0-17.066667-17.066667l0-51.2q0-17.066667 17.066667-17.066666Z"
|
||||
fill="#EDEEF0" p-id="6970"></path>
|
||||
<path
|
||||
d="M512 682.666667m17.066667 0l179.2 0q17.066667 0 17.066666 17.066666l0 51.2q0 17.066667-17.066666 17.066667l-179.2 0q-17.066667 0-17.066667-17.066667l0-51.2q0-17.066667 17.066667-17.066666Z"
|
||||
fill="#EDEEF0" p-id="6971"></path>
|
||||
<path
|
||||
d="M213.333333 554.666667m17.066667 0l221.866667 0q17.066667 0 17.066666 17.066666l0 8.533334q0 17.066667-17.066666 17.066666l-221.866667 0q-17.066667 0-17.066667-17.066666l0-8.533334q0-17.066667 17.066667-17.066666Z"
|
||||
fill="#EDEEF0" p-id="6972"></path>
|
||||
<path
|
||||
d="M213.333333 640m17.066667 0l221.866667 0q17.066667 0 17.066666 17.066667l0 8.533333q0 17.066667-17.066666 17.066667l-221.866667 0q-17.066667 0-17.066667-17.066667l0-8.533333q0-17.066667 17.066667-17.066667Z"
|
||||
fill="#EDEEF0" p-id="6973"></path>
|
||||
<path
|
||||
d="M213.333333 725.333333m17.066667 0l221.866667 0q17.066667 0 17.066666 17.066667l0 8.533333q0 17.066667-17.066666 17.066667l-221.866667 0q-17.066667 0-17.066667-17.066667l0-8.533333q0-17.066667 17.066667-17.066667Z"
|
||||
fill="#EDEEF0" p-id="6974"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 120 KiB |
@@ -0,0 +1,14 @@
|
||||
import globals from "globals";
|
||||
import pluginJs from "@eslint/js";
|
||||
import tseslint from "typescript-eslint";
|
||||
|
||||
export default [
|
||||
{ languageOptions: { globals: globals.browser } },
|
||||
pluginJs.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
{
|
||||
rules: {
|
||||
"@typescript-eslint/no-explicit-any": "warn",
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -1,15 +1,61 @@
|
||||
{
|
||||
"name": "electron-template",
|
||||
"name": "mediago",
|
||||
"version": "0.1.0",
|
||||
"description": "electron-template",
|
||||
"main": "index.js",
|
||||
"description": "mediago",
|
||||
"author": "caorushizi",
|
||||
"homepage": "https://downloader.caorushizi.cn/",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "pnpm -r --parallel -F main -F renderer run dev",
|
||||
"build": "pnpm -r --parallel -F main -F renderer run build",
|
||||
"pack": "pnpm -F main run pack",
|
||||
"release": "pnpm run build && pnpm -F main run release"
|
||||
"dev": "tsx scripts/dev.ts && pnpm --parallel -F \"./packages/*\" run dev",
|
||||
"build": "tsx scripts/build.ts",
|
||||
"build:plugin": "pnpm -F plugin run build",
|
||||
"build:main": "pnpm -F main run build",
|
||||
"build:renderer": "pnpm -F renderer run build",
|
||||
"beta": "pnpm run build && pnpm -F mediago run pack",
|
||||
"release": "pnpm run build && pnpm -F main run release",
|
||||
"docs:dev": "vitepress dev docs",
|
||||
"docs:build": "vitepress build docs",
|
||||
"docs:preview": "vitepress preview docs",
|
||||
"types": "pnpm -F main run types",
|
||||
"types:watch": "pnpm -F main run types:watch",
|
||||
"prepare": "husky",
|
||||
"commit": "git-cz",
|
||||
"commitlint": "commitlint --edit",
|
||||
"spellcheck": "cspell \"packages/**/src/**/*.{ts,tsx}\"",
|
||||
"lint-staged": "pnpm --recursive -F \"./packages/*\" run lint-staged"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "node_modules/cz-git"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^19.3.0",
|
||||
"@commitlint/config-conventional": "^19.2.2",
|
||||
"@commitlint/core": "^19.3.0",
|
||||
"@commitlint/cz-commitlint": "^19.2.0",
|
||||
"@commitlint/format": "^19.3.0",
|
||||
"@eslint/js": "^9.3.0",
|
||||
"@waline/client": "^3.2.0",
|
||||
"commitizen": "^4.3.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"cspell": "^8.8.3",
|
||||
"cz-git": "^1.9.2",
|
||||
"eslint": "^9.3.0",
|
||||
"globals": "^15.3.0",
|
||||
"husky": "^9.0.11",
|
||||
"tsx": "^4.11.0",
|
||||
"typescript-eslint": "^7.10.0",
|
||||
"vitepress": "1.2.2",
|
||||
"vue": "^3.4.27",
|
||||
"zx": "^8.1.1"
|
||||
},
|
||||
"pnpm": {
|
||||
"patchedDependencies": {
|
||||
"@cliqz/adblocker@1.27.3": "patches/@cliqz__adblocker@1.27.3.patch"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
node: true,
|
||||
es2021: true,
|
||||
},
|
||||
extends: [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"prettier",
|
||||
],
|
||||
overrides: [],
|
||||
parser: "@typescript-eslint/parser",
|
||||
parserOptions: {
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
},
|
||||
plugins: ["@typescript-eslint", "prettier"],
|
||||
rules: {
|
||||
"prettier/prettier": "warn",
|
||||
},
|
||||
};
|
||||
@@ -3,3 +3,5 @@ node_modules
|
||||
build
|
||||
dist
|
||||
bin/Logs
|
||||
release
|
||||
types
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
types/
|
||||
@@ -1 +1 @@
|
||||
{}
|
||||
{}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
output
|
||||
bin
|
||||
mobile
|
||||
plugin
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "mediago",
|
||||
"version": "2.2.2",
|
||||
"description": "在线视频下载器",
|
||||
"main": "main/index.js",
|
||||
"author": "caorushizi",
|
||||
"homepage": "https://downloader.caorushizi.cn/",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cliqz/adblocker-electron": "^1.27.3",
|
||||
"@cliqz/adblocker-electron-preload": "^1.27.3",
|
||||
"node-pty": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "30.0.8"
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 22 KiB |
@@ -0,0 +1,16 @@
|
||||
import globals from "globals";
|
||||
import pluginJs from "@eslint/js";
|
||||
import tseslint from "typescript-eslint";
|
||||
|
||||
export default [
|
||||
{
|
||||
languageOptions: { globals: globals.node },
|
||||
},
|
||||
pluginJs.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
{
|
||||
rules: {
|
||||
"@typescript-eslint/no-explicit-any": "warn",
|
||||
},
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1 @@
|
||||
export { dev, build, release } from "./scripts";
|
||||
@@ -1,55 +1,75 @@
|
||||
{
|
||||
"name": "main",
|
||||
"version": "2.0.0-beta.2",
|
||||
"description": "electron-template main",
|
||||
"version": "0.1.0",
|
||||
"description": "在线视频下载器",
|
||||
"type": "module",
|
||||
"main": "main/index.js",
|
||||
"scripts": {
|
||||
"rebuild": "electron-rebuild -f -w better-sqlite3",
|
||||
"dev": "cross-env NODE_ENV=development node script/dev.mjs",
|
||||
"build": "cross-env NODE_ENV=production node script/build.mjs",
|
||||
"pack": "cross-env NODE_ENV=development node script/release.mjs",
|
||||
"release": "cross-env NODE_ENV=production node script/release.mjs"
|
||||
"postinstall": "electron-rebuild -f -w",
|
||||
"dev": "cross-env NODE_ENV=development gulp dev",
|
||||
"pack": "cross-env NODE_ENV=development gulp release",
|
||||
"build": "cross-env NODE_ENV=production gulp build",
|
||||
"release": "cross-env NODE_ENV=production gulp release",
|
||||
"types": "tsc",
|
||||
"types:watch": "tsc -w",
|
||||
"lint-staged": "lint-staged"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,jsx,ts,tsx}": "eslint"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
"@rushstack/eslint-patch": "^1.2.0",
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"@types/node": "^18.11.18",
|
||||
"@typescript-eslint/eslint-plugin": "5.50.0",
|
||||
"@typescript-eslint/parser": "5.50.0",
|
||||
"chokidar": "^3.5.3",
|
||||
"@electron/rebuild": "^3.6.0",
|
||||
"@eslint/js": "^9.3.0",
|
||||
"@types/electron-devtools-installer": "^2.2.5",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/glob": "^8.1.0",
|
||||
"@types/gulp": "^4.0.17",
|
||||
"@types/lodash": "^4.17.4",
|
||||
"@types/mime-types": "^2.1.4",
|
||||
"@types/node": "^20.12.12",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"@types/semver": "^7.5.8",
|
||||
"consola": "^3.2.3",
|
||||
"cross-env": "^7.0.3",
|
||||
"dotenv": "^16.0.3",
|
||||
"electron": "^23.1.1",
|
||||
"electron-builder": "^23.6.0",
|
||||
"electron-updater": "^5.3.0",
|
||||
"esbuild": "^0.17.10",
|
||||
"eslint": "^8.33.0",
|
||||
"eslint-config-prettier": "^8.6.0",
|
||||
"eslint-config-standard-with-typescript": "^24.0.0",
|
||||
"eslint-plugin-import": "2.25.2",
|
||||
"eslint-plugin-n": "15.0.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-promise": "6.0.0",
|
||||
"prebuild-install": "^7.1.1",
|
||||
"prettier": "2.8.3",
|
||||
"semver": "^7.3.8",
|
||||
"typescript": "^4.9.3"
|
||||
"del": "^7.1.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"electron": "30.0.8",
|
||||
"electron-builder": "^24.13.3",
|
||||
"electron-updater": "^6.1.8",
|
||||
"esbuild": "^0.21.4",
|
||||
"esbuild-register": "^3.5.0",
|
||||
"eslint": "^9.3.0",
|
||||
"glob": "^10.4.1",
|
||||
"globals": "^15.3.0",
|
||||
"gulp": "^5.0.0",
|
||||
"prebuild-install": "^7.1.2",
|
||||
"semver": "^7.6.2",
|
||||
"typescript": "^5.4.5",
|
||||
"typescript-eslint": "^7.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.3.4",
|
||||
"better-sqlite3": "^8.2.0",
|
||||
"dayjs": "^1.11.7",
|
||||
"@cliqz/adblocker-electron": "^1.27.3",
|
||||
"@cliqz/adblocker-electron-preload": "^1.27.3",
|
||||
"axios": "^1.7.2",
|
||||
"better-sqlite3": "^10.0.0",
|
||||
"cheerio": "1.0.0-rc.12",
|
||||
"dayjs": "^1.11.11",
|
||||
"electron-devtools-installer": "^3.2.0",
|
||||
"electron-is-dev": "^2.0.0",
|
||||
"electron-log": "^4.3.2",
|
||||
"electron-store": "^7.0.2",
|
||||
"fs-extra": "^11.1.0",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"inversify": "^6.0.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"typeorm": "^0.3.12"
|
||||
"electron-is-dev": "^3.0.1",
|
||||
"electron-log": "^5.1.5",
|
||||
"electron-store": "^9.0.0",
|
||||
"execa": "^9.1.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"inversify": "^6.0.2",
|
||||
"lint-staged": "^15.2.5",
|
||||
"lodash": "^4.17.21",
|
||||
"mime-types": "^2.1.35",
|
||||
"node-fetch": "^3.3.2",
|
||||
"node-pty": "^1.0.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"strip-ansi": "^7.1.0",
|
||||
"typeorm": "0.3.20"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import * as esbuild from "esbuild";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { existsSync, rmSync } from "node:fs";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const mainResolve = (r) => resolve(__dirname, "..", r);
|
||||
const rootResolve = (r) => resolve(__dirname, "../../..", r);
|
||||
|
||||
const nodeEnv = process.env.NODE_ENV;
|
||||
console.log("当前的环境是: ", nodeEnv);
|
||||
|
||||
const env = existsSync(rootResolve(`.env.${nodeEnv}.local`))
|
||||
? rootResolve(`.env.${nodeEnv}.local`)
|
||||
: rootResolve(`.env.${nodeEnv}`);
|
||||
const { parsed } = dotenv.config({ path: env });
|
||||
|
||||
const mainDefined = Object.keys(parsed || {}).reduce((prev, cur) => {
|
||||
prev[`process.env.${[cur]}`] = JSON.stringify(parsed[cur]);
|
||||
return prev;
|
||||
}, {});
|
||||
|
||||
rmSync(mainResolve("build/main"), { recursive: true, force: true });
|
||||
rmSync(mainResolve("build/Release"), { recursive: true, force: true });
|
||||
|
||||
esbuild.build({
|
||||
entryPoints: [mainResolve("src/index.ts"), mainResolve("src/preload.ts")],
|
||||
bundle: true,
|
||||
platform: "node",
|
||||
sourcemap: false,
|
||||
target: ["node16.13"],
|
||||
external: ["electron", "nock", "aws-sdk", "mock-aws-s3"],
|
||||
define: {
|
||||
...mainDefined,
|
||||
},
|
||||
outdir: mainResolve("build/main"),
|
||||
loader: { ".png": "file" },
|
||||
minify: true,
|
||||
});
|
||||
@@ -1,91 +0,0 @@
|
||||
import { spawn } from "child_process";
|
||||
import { cpSync, existsSync } from "node:fs";
|
||||
import electron from "electron";
|
||||
import * as esbuild from "esbuild";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import chokidar from "chokidar";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const mainResolve = (r) => resolve(__dirname, "..", r);
|
||||
const rootResolve = (r) => resolve(__dirname, "../../..", r);
|
||||
|
||||
let electronProcess = null;
|
||||
|
||||
const nodeEnv = process.env.NODE_ENV;
|
||||
console.log("当前的环境是: ", nodeEnv);
|
||||
|
||||
const env = existsSync(rootResolve(`.env.${nodeEnv}.local`))
|
||||
? rootResolve(`.env.${nodeEnv}.local`)
|
||||
: rootResolve(`.env.${nodeEnv}`);
|
||||
dotenv.config({ path: env });
|
||||
|
||||
async function copySource() {
|
||||
const oldSqlite3Path = mainResolve(
|
||||
"node_modules/better-sqlite3/build/Release"
|
||||
);
|
||||
const newSqlite3Path = mainResolve("build/Release");
|
||||
|
||||
cpSync(oldSqlite3Path, newSqlite3Path, {
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
const oldBinPath = mainResolve("bin");
|
||||
const newBinPath = mainResolve("build/bin");
|
||||
|
||||
cpSync(oldBinPath, newBinPath, {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
|
||||
const ctx = await esbuild.context({
|
||||
entryPoints: [mainResolve("src/index.ts"), mainResolve("src/preload.ts")],
|
||||
bundle: true,
|
||||
platform: "node",
|
||||
sourcemap: true,
|
||||
target: ["node16.13"],
|
||||
external: ["electron", "mock-aws-s3", "aws-sdk", "nock"],
|
||||
define: {
|
||||
// 开发环境中二进制可执行文件的路径
|
||||
__bin__: `"${mainResolve("bin").replace(/\\/g, "\\\\")}"`,
|
||||
},
|
||||
plugins: [],
|
||||
outdir: mainResolve("build/main"),
|
||||
loader: { ".png": "file" },
|
||||
});
|
||||
|
||||
const watcher = chokidar.watch("./src");
|
||||
|
||||
watcher.on("change", async () => {
|
||||
await ctx.rebuild();
|
||||
console.log("watch build succeed.");
|
||||
if (electronProcess && electronProcess.kill) {
|
||||
process.kill(electronProcess.pid);
|
||||
electronProcess = null;
|
||||
startElectron();
|
||||
}
|
||||
});
|
||||
|
||||
function startElectron() {
|
||||
const args = ["--inspect=5858", mainResolve("build/main/index.js")];
|
||||
|
||||
electronProcess = spawn(String(electron), args);
|
||||
|
||||
electronProcess.stdout.on("data", (data) => {
|
||||
console.log(String(data));
|
||||
});
|
||||
|
||||
electronProcess.stderr.on("data", (data) => {
|
||||
console.log(String(data));
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.rebuild();
|
||||
await copySource();
|
||||
await startElectron();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exit();
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
import builder from "electron-builder";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import dotenv from "dotenv";
|
||||
import semver from "semver";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const mainResolve = (r) => resolve(__dirname, "..", r);
|
||||
const rootResolve = (r) => resolve(__dirname, "../../..", r);
|
||||
|
||||
const packageJson = JSON.parse(readFileSync(mainResolve("./package.json")));
|
||||
const nodeEnv = process.env.NODE_ENV;
|
||||
console.log("当前的环境是: ", nodeEnv);
|
||||
|
||||
const env = existsSync(rootResolve(`.env.${nodeEnv}.local`))
|
||||
? rootResolve(`.env.${nodeEnv}.local`)
|
||||
: rootResolve(`.env.${nodeEnv}`);
|
||||
dotenv.config({ path: env });
|
||||
|
||||
if (semver.neq(process.env.APP_VERSION, packageJson.version)) {
|
||||
console.log("请先同步构建版本和发布版本");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Let's get that intellisense working
|
||||
/**
|
||||
* @type {import('electron-builder').Configuration}
|
||||
* @see https://www.electron.build/configuration/configuration
|
||||
*/
|
||||
const options = {
|
||||
productName: process.env.APP_NAME,
|
||||
buildVersion: process.env.APP_VERSION,
|
||||
appId: process.env.APP_ID,
|
||||
copyright: process.env.APP_COPYRIGHT,
|
||||
artifactName: "${productName}-setup-${buildVersion}.${ext}",
|
||||
directories: {
|
||||
output: "./dist",
|
||||
},
|
||||
files: [
|
||||
{
|
||||
from: "./build",
|
||||
to: "./",
|
||||
filter: ["**/*"],
|
||||
},
|
||||
"./package.json",
|
||||
{
|
||||
from: "./node_modules/better-sqlite3/build/Release",
|
||||
to: "./build/Release",
|
||||
},
|
||||
],
|
||||
extraResources: ["bin/**/*"],
|
||||
win: {
|
||||
icon: "../assets/icon.ico",
|
||||
target: [
|
||||
{
|
||||
target: "nsis",
|
||||
},
|
||||
],
|
||||
},
|
||||
dmg: {
|
||||
contents: [],
|
||||
},
|
||||
mac: {
|
||||
icon: "../icons/icon.icns",
|
||||
target: {
|
||||
target: "default",
|
||||
arch: ["x64", "arm64"],
|
||||
},
|
||||
},
|
||||
linux: {
|
||||
icon: "../build/icons",
|
||||
},
|
||||
nsis: {
|
||||
oneClick: false,
|
||||
allowElevation: true,
|
||||
allowToChangeInstallationDirectory: true,
|
||||
installerIcon: "",
|
||||
uninstallerIcon: "",
|
||||
installerHeaderIcon: "",
|
||||
createDesktopShortcut: true,
|
||||
createStartMenuShortcut: true,
|
||||
shortcutName: "",
|
||||
include: "",
|
||||
script: "",
|
||||
},
|
||||
publish: {
|
||||
provider: "github",
|
||||
repo: "m3u8-downloader",
|
||||
owner: "caorushizi",
|
||||
releaseType: "prerelease",
|
||||
},
|
||||
};
|
||||
|
||||
const target =
|
||||
process.env.NODE_ENV === "development"
|
||||
? builder.DIR_TARGET
|
||||
: builder.DEFAULT_TARGET;
|
||||
try {
|
||||
await builder.build({
|
||||
targets: builder.Platform.WINDOWS.createTarget(target),
|
||||
config: options,
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import { Configuration } from "electron-builder";
|
||||
import { Env, isDev, mainResolve } from "./utils";
|
||||
import esbuild from "esbuild";
|
||||
|
||||
const external = [
|
||||
"electron",
|
||||
"nock",
|
||||
"aws-sdk",
|
||||
"mock-aws-s3",
|
||||
"@cliqz/adblocker-electron-preload",
|
||||
"node-pty",
|
||||
];
|
||||
|
||||
function getConfig(): esbuild.BuildOptions {
|
||||
const getDefine = (): Record<string, string> => {
|
||||
if (isDev) {
|
||||
return {
|
||||
__bin__: `"${mainResolve("app/bin").replace(/\\/g, "\\\\")}"`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...Env.getInstance().loadDotEnvDefined(),
|
||||
"process.env.NODE_ENV": '"production"',
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
bundle: true,
|
||||
sourcemap: process.env.NODE_ENV === "development",
|
||||
external,
|
||||
define: getDefine(),
|
||||
outdir: mainResolve("app/build/main"),
|
||||
loader: { ".png": "file" },
|
||||
minify: process.env.NODE_ENV === "production",
|
||||
};
|
||||
}
|
||||
|
||||
function buildOptions(
|
||||
entry: string,
|
||||
platform: esbuild.Platform,
|
||||
target: string,
|
||||
): esbuild.BuildOptions {
|
||||
return {
|
||||
...getConfig(),
|
||||
entryPoints: [mainResolve(entry)],
|
||||
platform: platform,
|
||||
target: [target],
|
||||
};
|
||||
}
|
||||
|
||||
export function browserOptions(entry: string): esbuild.BuildOptions {
|
||||
return buildOptions(entry, "browser", "chrome89");
|
||||
}
|
||||
|
||||
export function nodeOptions(entry: string): esbuild.BuildOptions {
|
||||
return buildOptions(entry, "node", "node16.13");
|
||||
}
|
||||
|
||||
export function getReleaseConfig(): Configuration {
|
||||
return {
|
||||
productName: process.env.APP_NAME,
|
||||
buildVersion: process.env.APP_VERSION,
|
||||
appId: process.env.APP_ID,
|
||||
copyright: process.env.APP_COPYRIGHT,
|
||||
artifactName: "${productName}-setup-${arch}-${buildVersion}.${ext}",
|
||||
npmRebuild: true,
|
||||
directories: {
|
||||
output: "./release",
|
||||
},
|
||||
files: [
|
||||
{
|
||||
from: "./build",
|
||||
to: "./",
|
||||
},
|
||||
"./package.json",
|
||||
],
|
||||
extraResources: [
|
||||
{
|
||||
from: "./app/plugin",
|
||||
to: "plugin",
|
||||
},
|
||||
{
|
||||
from: "./app/bin/",
|
||||
to: "bin",
|
||||
},
|
||||
],
|
||||
win: {
|
||||
icon: "../assets/icon.ico",
|
||||
target: [
|
||||
{
|
||||
target: "nsis",
|
||||
arch: ["x64"],
|
||||
},
|
||||
],
|
||||
},
|
||||
dmg: {
|
||||
contents: [
|
||||
{
|
||||
x: 410,
|
||||
y: 150,
|
||||
type: "link",
|
||||
path: "/Applications",
|
||||
},
|
||||
{
|
||||
x: 130,
|
||||
y: 150,
|
||||
type: "file",
|
||||
},
|
||||
],
|
||||
},
|
||||
mac: {
|
||||
icon: "../assets/icon.icns",
|
||||
target: {
|
||||
target: "dmg",
|
||||
arch: ["x64"],
|
||||
},
|
||||
},
|
||||
linux: {
|
||||
category: "Utility",
|
||||
icon: "../assets/icon.icns",
|
||||
maintainer: "caorushizi <84996057@qq.com>",
|
||||
target: {
|
||||
target: "deb",
|
||||
arch: ["x64"],
|
||||
},
|
||||
},
|
||||
nsis: {
|
||||
oneClick: true,
|
||||
allowElevation: true,
|
||||
allowToChangeInstallationDirectory: false,
|
||||
installerIcon: "",
|
||||
uninstallerIcon: "",
|
||||
installerHeaderIcon: "",
|
||||
createDesktopShortcut: true,
|
||||
createStartMenuShortcut: true,
|
||||
shortcutName: "",
|
||||
include: "",
|
||||
script: "",
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { deleteSync } from "del";
|
||||
import { ElectronApp, mainResolve, Env, isWin } from "./utils";
|
||||
import gulp from "gulp";
|
||||
import * as esbuild from "esbuild";
|
||||
import consola from "consola";
|
||||
import { browserOptions, nodeOptions, getReleaseConfig } from "./config";
|
||||
import semver from "semver";
|
||||
import pkg from "../app/package.json";
|
||||
import * as builder from "electron-builder";
|
||||
import { globSync } from "glob";
|
||||
import fs from "fs";
|
||||
|
||||
const env = Env.getInstance();
|
||||
env.loadDotEnvRuntime();
|
||||
|
||||
async function clean() {
|
||||
return deleteSync([
|
||||
mainResolve("app/build"),
|
||||
mainResolve("app/bin"),
|
||||
mainResolve("release"),
|
||||
]);
|
||||
}
|
||||
|
||||
async function copySqlite() {
|
||||
const path = "build/Release/better_sqlite3.node";
|
||||
const source = mainResolve("node_modules/better-sqlite3", path);
|
||||
const target = mainResolve("app", path);
|
||||
fs.cpSync(source, target, { recursive: true });
|
||||
}
|
||||
|
||||
async function copyBin() {
|
||||
const source = mainResolve("bin", process.platform);
|
||||
const target = mainResolve("app/bin");
|
||||
fs.cpSync(source, target, { recursive: true });
|
||||
}
|
||||
|
||||
async function chmodBin() {
|
||||
// 遍历文件夹下的所有文件,将文件的权限设置为 777
|
||||
if (isWin) return;
|
||||
|
||||
const files = globSync(mainResolve("app/bin/*"));
|
||||
for (const file of files) {
|
||||
fs.chmodSync(file, 0o777);
|
||||
}
|
||||
}
|
||||
|
||||
const copy = gulp.parallel(copyBin, copySqlite);
|
||||
|
||||
async function watchTask() {
|
||||
const app = new ElectronApp();
|
||||
const main = await esbuild.context(nodeOptions("src/index.ts"));
|
||||
const preload = await esbuild.context(browserOptions("src/preload.ts"));
|
||||
|
||||
const watcher = gulp.watch(["./src"]);
|
||||
watcher
|
||||
.on("ready", async () => {
|
||||
await main.rebuild();
|
||||
await preload.rebuild();
|
||||
app.start();
|
||||
})
|
||||
.on("change", async () => {
|
||||
await main.rebuild();
|
||||
await preload.rebuild();
|
||||
app.restart();
|
||||
})
|
||||
.on("error", (error) => {
|
||||
consola.error(error);
|
||||
});
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
async function buildTask() {
|
||||
await esbuild.build(nodeOptions("src/index.ts"));
|
||||
await esbuild.build(browserOptions("src/preload.ts"));
|
||||
}
|
||||
|
||||
async function pack() {
|
||||
if (semver.neq(process.env.APP_VERSION || "", pkg.version)) {
|
||||
throw new Error("请先同步构建版本和发布版本");
|
||||
}
|
||||
const config = getReleaseConfig();
|
||||
if (process.env.GH_TOKEN) {
|
||||
config.publish = {
|
||||
provider: "github",
|
||||
repo: "mediago",
|
||||
owner: "caorushizi",
|
||||
releaseType: "release",
|
||||
};
|
||||
}
|
||||
await builder.build({ config });
|
||||
}
|
||||
|
||||
// 开发环境
|
||||
export const dev = gulp.series(clean, copy, chmodBin, watchTask);
|
||||
// 构建打包
|
||||
export const build = gulp.series(clean, copy, chmodBin, buildTask);
|
||||
// release
|
||||
export const release = gulp.series(pack);
|
||||
@@ -0,0 +1,108 @@
|
||||
import { ChildProcessWithoutNullStreams, spawn } from "child_process";
|
||||
import dotenv from "dotenv";
|
||||
import { resolve } from "path";
|
||||
import consola from "consola";
|
||||
import fs from "fs-extra";
|
||||
import electron from "electron";
|
||||
|
||||
const baseResolve = (...r) => resolve(__dirname, ...r);
|
||||
export const mainResolve = (...r: string[]) => baseResolve("..", ...r);
|
||||
export const rootResolve = (...r: string[]) => baseResolve("../../..", ...r);
|
||||
|
||||
export const isDev = process.env.NODE_ENV === "development";
|
||||
|
||||
export const isLinux = process.platform === "linux";
|
||||
export const isMac = process.platform === "darwin";
|
||||
export const isWin = process.platform === "win32";
|
||||
|
||||
export class ElectronApp {
|
||||
process: ChildProcessWithoutNullStreams | null = null;
|
||||
|
||||
start() {
|
||||
const args = ["--inspect=5858", mainResolve("app/build/main/index.js")];
|
||||
|
||||
this.process = spawn(String(electron), args);
|
||||
|
||||
this.process.stdout.on("data", (data) => {
|
||||
consola.log(String(data));
|
||||
});
|
||||
|
||||
this.process.stderr.on("data", (data) => {
|
||||
consola.log(String(data));
|
||||
});
|
||||
}
|
||||
|
||||
restart() {
|
||||
this.kill();
|
||||
this.start();
|
||||
}
|
||||
|
||||
kill() {
|
||||
if (this.process && this.process.pid) {
|
||||
if (isMac) {
|
||||
spawn("kill", ["-9", String(this.process.pid)]);
|
||||
} else {
|
||||
process.kill(this.process.pid);
|
||||
}
|
||||
this.process = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Env {
|
||||
env: Record<string, string> = {};
|
||||
nodeEnv = "";
|
||||
static instance: Env;
|
||||
|
||||
private constructor(nodeEnv = process.env.NODE_ENV) {
|
||||
const env = this.parseEnv(rootResolve(".env"));
|
||||
const modeEnv = this.parseEnv(rootResolve(`.env.${nodeEnv}`));
|
||||
const localEnv = this.parseEnv(rootResolve(`.env.${nodeEnv}.local`));
|
||||
|
||||
this.nodeEnv = nodeEnv || "development";
|
||||
this.env = { ...env, ...modeEnv, ...localEnv };
|
||||
}
|
||||
|
||||
static getInstance() {
|
||||
if (!Env.instance) {
|
||||
Env.instance = new Env();
|
||||
}
|
||||
|
||||
return Env.instance;
|
||||
}
|
||||
|
||||
private parseEnv(path: string) {
|
||||
if (!fs.existsSync(path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parsed = dotenv.parse(fs.readFileSync(path));
|
||||
if (!parsed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Object.keys(parsed).reduce((prev, curr) => {
|
||||
prev[curr] = parsed[curr];
|
||||
return prev;
|
||||
}, {});
|
||||
}
|
||||
|
||||
loadDotEnvRuntime() {
|
||||
Object.keys(this.env).forEach((key) => {
|
||||
if (process.env[key] != null || !this.env[key]) return;
|
||||
process.env[key] = this.env[key];
|
||||
});
|
||||
}
|
||||
|
||||
loadDotEnvDefined() {
|
||||
return Object.keys(this.env).reduce<Record<string, string>>((prev, cur) => {
|
||||
if (!cur.startsWith("APP_")) return prev;
|
||||
prev[`process.env.${[cur]}`] = JSON.stringify(this.env[cur]);
|
||||
return prev;
|
||||
}, {});
|
||||
}
|
||||
|
||||
get isDev() {
|
||||
return this.nodeEnv === "development";
|
||||
}
|
||||
}
|
||||
@@ -1,82 +1,100 @@
|
||||
import { app } from "electron";
|
||||
import { inject, injectable } from "inversify";
|
||||
import {
|
||||
BrowserWindowService,
|
||||
DatabaseService,
|
||||
DownloadStatus,
|
||||
IpcHandlerService,
|
||||
LoggerService,
|
||||
MainWindowService,
|
||||
ProtocolService,
|
||||
StoreService,
|
||||
UpdateService,
|
||||
VideoRepository,
|
||||
WebviewService,
|
||||
type App,
|
||||
} from "./interfaces";
|
||||
import { TYPES } from "./types";
|
||||
import installExtension, {
|
||||
REDUX_DEVTOOLS,
|
||||
REACT_DEVELOPER_TOOLS,
|
||||
} from "electron-devtools-installer";
|
||||
import isDev from "electron-is-dev";
|
||||
import { DownloadStatus } from "./interfaces.ts";
|
||||
import { TYPES } from "./types.ts";
|
||||
import { Menu, Tray, app, nativeImage, nativeTheme } from "electron";
|
||||
import TrayIcon from "./tray-icon.png";
|
||||
import path from "path";
|
||||
import MainWindow from "./windows/MainWindow.ts";
|
||||
import WebviewService from "./services/WebviewService.ts";
|
||||
import VideoRepository from "./repository/VideoRepository.ts";
|
||||
import ElectronDevtools from "./vendor/ElectronDevtools.ts";
|
||||
import ElectronStore from "./vendor/ElectronStore.ts";
|
||||
import ElectronUpdater from "./vendor/ElectronUpdater.ts";
|
||||
import TypeORM from "./vendor/TypeORM.ts";
|
||||
import ProtocolService from "./core/protocol.ts";
|
||||
import IpcHandlerService from "./core/ipc.ts";
|
||||
|
||||
@injectable()
|
||||
export default class ElectronApp implements App {
|
||||
export default class ElectronApp {
|
||||
constructor(
|
||||
@inject(TYPES.MainWindowService)
|
||||
private readonly mainWindow: MainWindowService,
|
||||
@inject(TYPES.MainWindow)
|
||||
private readonly mainWindow: MainWindow,
|
||||
@inject(TYPES.ProtocolService)
|
||||
private readonly protocolService: ProtocolService,
|
||||
@inject(TYPES.UpdateService)
|
||||
private readonly updateService: UpdateService,
|
||||
private readonly protocol: ProtocolService,
|
||||
@inject(TYPES.ElectronUpdater)
|
||||
private readonly updater: ElectronUpdater,
|
||||
@inject(TYPES.IpcHandlerService)
|
||||
private readonly ipcHandler: IpcHandlerService,
|
||||
@inject(TYPES.DatabaseService)
|
||||
private readonly dataService: DatabaseService,
|
||||
private readonly ipc: IpcHandlerService,
|
||||
@inject(TYPES.TypeORM)
|
||||
private readonly db: TypeORM,
|
||||
@inject(TYPES.WebviewService)
|
||||
private readonly webview: WebviewService,
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
@inject(TYPES.StoreService)
|
||||
private readonly storeService: StoreService,
|
||||
@inject(TYPES.VideoRepository)
|
||||
private readonly videoRepository: VideoRepository,
|
||||
@inject(TYPES.BrowserWindowService)
|
||||
private readonly browserWindow: BrowserWindowService
|
||||
@inject(TYPES.ElectronDevtools)
|
||||
private readonly devTools: ElectronDevtools,
|
||||
@inject(TYPES.ElectronStore)
|
||||
private readonly store: ElectronStore,
|
||||
) {}
|
||||
|
||||
private async serviceInit(): Promise<void> {
|
||||
this.mainWindow.init();
|
||||
this.webview.init();
|
||||
}
|
||||
|
||||
private async vendorInit() {
|
||||
await this.db.init();
|
||||
this.updater.init();
|
||||
this.devTools.init();
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
this.protocol.create();
|
||||
this.ipc.init();
|
||||
|
||||
// vendor
|
||||
await this.vendorInit();
|
||||
// service
|
||||
await this.serviceInit();
|
||||
|
||||
app.on("activate", () => {
|
||||
this.mainWindow.init();
|
||||
});
|
||||
|
||||
this.protocolService.create();
|
||||
this.mainWindow.init();
|
||||
this.browserWindow.init();
|
||||
this.ipcHandler.init();
|
||||
this.updateService.init();
|
||||
await this.dataService.init();
|
||||
this.webview.init();
|
||||
this.storeService.init();
|
||||
this.initAppTheme();
|
||||
this.resetDownloadStatus();
|
||||
|
||||
this.initTray();
|
||||
}
|
||||
|
||||
initAppTheme(): void {
|
||||
const theme = this.store.get("theme");
|
||||
nativeTheme.themeSource = theme;
|
||||
}
|
||||
|
||||
initTray() {
|
||||
const iconPath = path.resolve(__dirname, TrayIcon);
|
||||
const icon = nativeImage.createFromPath(iconPath);
|
||||
const tray = new Tray(icon);
|
||||
tray.setToolTip("在线视频下载");
|
||||
tray.addListener("click", () => {
|
||||
this.mainWindow.init();
|
||||
});
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{ label: "显示主窗口", click: () => this.mainWindow.init() },
|
||||
{ label: "退出 app", role: "quit" },
|
||||
]);
|
||||
tray.setContextMenu(contextMenu);
|
||||
}
|
||||
|
||||
// 如果重启后还有正在下载的视频,就将状态改成下载失败
|
||||
async resetDownloadStatus(): Promise<void> {
|
||||
// 重启后如果还有 downloading 状态的数据, 全部重置为失败
|
||||
const videos = await this.videoRepository.findWattingAndDownloadingVideos();
|
||||
const videoIds = videos.map((video) => video.id);
|
||||
await this.videoRepository.changeVideoStatus(
|
||||
videoIds,
|
||||
DownloadStatus.Failed
|
||||
DownloadStatus.Failed,
|
||||
);
|
||||
|
||||
if (isDev) {
|
||||
try {
|
||||
await installExtension([REDUX_DEVTOOLS, REACT_DEVELOPER_TOOLS]);
|
||||
this.logger.info("devtools installed");
|
||||
} catch (err) {
|
||||
this.logger.error("devtools install error", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { inject, injectable } from "inversify";
|
||||
import { ConversionPagination, type Controller } from "../interfaces.ts";
|
||||
import { TYPES } from "../types.ts";
|
||||
import ConversionRepository from "../repository/ConversionRepository.ts";
|
||||
import { handle } from "../helper/decorator.ts";
|
||||
import { Conversion } from "../entity/Conversion.ts";
|
||||
import { IpcMainEvent } from "electron/main";
|
||||
|
||||
@injectable()
|
||||
export default class ConversionController implements Controller {
|
||||
constructor(
|
||||
@inject(TYPES.ConversionRepository)
|
||||
private readonly conversionRepository: ConversionRepository
|
||||
) {}
|
||||
|
||||
@handle("get-conversions")
|
||||
async getConversions(e: IpcMainEvent, pagination: ConversionPagination) {
|
||||
return await this.conversionRepository.getConversions(pagination);
|
||||
}
|
||||
|
||||
@handle("add-conversion")
|
||||
async addConversion(e: IpcMainEvent, conversion: Conversion) {
|
||||
return await this.conversionRepository.addConversion(conversion);
|
||||
}
|
||||
|
||||
@handle("delete-conversion")
|
||||
async deleteConversion(e: IpcMainEvent, id: number) {
|
||||
return await this.conversionRepository.deleteConversion(id);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,76 @@
|
||||
import { IpcMainEvent } from "electron/main";
|
||||
import { inject, injectable } from "inversify";
|
||||
import { handle } from "../helper/decorator";
|
||||
import { handle } from "../helper/index.ts";
|
||||
import {
|
||||
StoreService,
|
||||
LoggerService,
|
||||
type Controller,
|
||||
VideoRepository,
|
||||
DownloadItem,
|
||||
DownloadItemPagination,
|
||||
DownloadService,
|
||||
Task,
|
||||
DownloadStatus,
|
||||
} from "../interfaces";
|
||||
import { TYPES } from "../types";
|
||||
import { spawnDownload } from "helper";
|
||||
import MainWindowServiceImpl from "services/MainWindowServiceImpl";
|
||||
} from "../interfaces.ts";
|
||||
import { TYPES } from "../types.ts";
|
||||
import MainWindow from "../windows/MainWindow.ts";
|
||||
import ElectronStore from "../vendor/ElectronStore.ts";
|
||||
import DownloadService from "../services/DownloadService.ts";
|
||||
import VideoRepository from "../repository/VideoRepository.ts";
|
||||
import WebviewService from "../services/WebviewService.ts";
|
||||
|
||||
@injectable()
|
||||
export default class DownloadController implements Controller {
|
||||
constructor(
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
@inject(TYPES.StoreService)
|
||||
private readonly storeService: StoreService,
|
||||
@inject(TYPES.ElectronStore)
|
||||
private readonly store: ElectronStore,
|
||||
@inject(TYPES.VideoRepository)
|
||||
private readonly videoRepository: VideoRepository,
|
||||
@inject(TYPES.DownloadService)
|
||||
private readonly downloadService: DownloadService,
|
||||
@inject(TYPES.MainWindowService)
|
||||
private readonly mainWindow: MainWindowServiceImpl
|
||||
@inject(TYPES.MainWindow)
|
||||
private readonly mainWindow: MainWindow,
|
||||
@inject(TYPES.WebviewService)
|
||||
private readonly webviewService: WebviewService
|
||||
) {}
|
||||
|
||||
@handle("show-download-dialog")
|
||||
async showDownloadDialog(e: IpcMainEvent, data: DownloadItem) {
|
||||
const image = await this.webviewService.captureView();
|
||||
this.webviewService.sendToWindow(
|
||||
"show-download-dialog",
|
||||
data,
|
||||
image.toDataURL()
|
||||
);
|
||||
}
|
||||
|
||||
@handle("add-download-item")
|
||||
async addDownloadItem(e: IpcMainEvent, video: DownloadItem) {
|
||||
async addDownloadItem(e: IpcMainEvent, video: Omit<DownloadItem, "id">) {
|
||||
const item = await this.videoRepository.addVideo(video);
|
||||
// 这里向页面发送消息,通知页面更新
|
||||
this.mainWindow.webContents.send("download-item-notifier", item);
|
||||
this.mainWindow.send("download-item-notifier", item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@handle("add-download-items")
|
||||
async addDownloadItems(e: IpcMainEvent, videos: Omit<DownloadItem, "id">[]) {
|
||||
const items = await this.videoRepository.addVideos(videos);
|
||||
// 这里向页面发送消息,通知页面更新
|
||||
this.mainWindow.send("download-item-notifier", items);
|
||||
return items;
|
||||
}
|
||||
|
||||
@handle("edit-download-item")
|
||||
async editDownloadItem(e: IpcMainEvent, video: DownloadItem) {
|
||||
const item = await this.videoRepository.editVideo(video);
|
||||
return item;
|
||||
}
|
||||
|
||||
@handle("edit-download-now")
|
||||
async editDownloadNow(e: IpcMainEvent, video: DownloadItem) {
|
||||
const item = await this.editDownloadItem(e, video);
|
||||
await this.startDownload(e, item.id);
|
||||
return item;
|
||||
}
|
||||
|
||||
@handle("download-now")
|
||||
async downloadNow(e: IpcMainEvent, video: DownloadItem) {
|
||||
async downloadNow(e: IpcMainEvent, video: Omit<DownloadItem, "id">) {
|
||||
// 添加下载项
|
||||
const item = await this.addDownloadItem(e, video);
|
||||
// 开始下载
|
||||
@@ -48,33 +78,41 @@ export default class DownloadController implements Controller {
|
||||
return item;
|
||||
}
|
||||
|
||||
@handle("download-items-now")
|
||||
async downloadItemsNow(e: IpcMainEvent, videos: Omit<DownloadItem, "id">[]) {
|
||||
// 添加下载项
|
||||
const items = await this.addDownloadItems(e, videos);
|
||||
// 开始下载
|
||||
items.forEach((item) => this.startDownload(e, item.id));
|
||||
return items;
|
||||
}
|
||||
|
||||
@handle("get-download-items")
|
||||
async getDownloadItems(e: IpcMainEvent, pagination: DownloadItemPagination) {
|
||||
return await this.videoRepository.findVideos(pagination);
|
||||
const videos = await this.videoRepository.findVideos(pagination);
|
||||
return videos;
|
||||
}
|
||||
|
||||
@handle("start-download")
|
||||
async startDownload(e: IpcMainEvent, vid: number) {
|
||||
// 查找将要下载的视频
|
||||
const video = await this.videoRepository.findVideo(vid);
|
||||
if (!video) {
|
||||
return Promise.reject("没有找到该视频");
|
||||
}
|
||||
const { name, url } = video;
|
||||
const local = this.storeService.get("local");
|
||||
const { name, url, headers, type } = video;
|
||||
const local = this.store.get("local");
|
||||
|
||||
// 从配置中添加参数
|
||||
const deleteSegments = this.storeService.get("deleteSegments");
|
||||
const deleteSegments = this.store.get("deleteSegments");
|
||||
|
||||
const task: Task = {
|
||||
id: vid,
|
||||
params: {
|
||||
url,
|
||||
type,
|
||||
local,
|
||||
name,
|
||||
headers,
|
||||
deleteSegments,
|
||||
},
|
||||
process: spawnDownload,
|
||||
};
|
||||
await this.videoRepository.changeVideoStatus(vid, DownloadStatus.Watting);
|
||||
this.downloadService.addTask(task);
|
||||
|
||||
@@ -4,42 +4,46 @@ import {
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemConstructorOptions,
|
||||
nativeTheme,
|
||||
shell,
|
||||
clipboard,
|
||||
} from "electron";
|
||||
import { Favorite } from "entity/Favorite";
|
||||
import { convertToAudio } from "helper";
|
||||
import { db, workspace } from "helper/variables";
|
||||
import { Favorite } from "../entity/Favorite.ts";
|
||||
import { convertToAudio, db, workspace } from "../helper/index.ts";
|
||||
import { inject, injectable } from "inversify";
|
||||
import { AppStore, EnvPath } from "main";
|
||||
import { AppStore, EnvPath } from "../main.ts";
|
||||
import path from "path";
|
||||
import { handle } from "../helper/decorator";
|
||||
import {
|
||||
StoreService,
|
||||
LoggerService,
|
||||
type Controller,
|
||||
FavoriteRepository,
|
||||
MainWindowService,
|
||||
VideoRepository,
|
||||
BrowserWindowService,
|
||||
} from "../interfaces";
|
||||
import { TYPES } from "../types";
|
||||
import { handle, getLocalIP } from "../helper/index.ts";
|
||||
import { type Controller } from "../interfaces.ts";
|
||||
import { TYPES } from "../types.ts";
|
||||
import fs from "fs-extra";
|
||||
import MainWindow from "../windows/MainWindow.ts";
|
||||
import BrowserWindow from "../windows/BrowserWindow.ts";
|
||||
import ElectronStore from "../vendor/ElectronStore.ts";
|
||||
import WebviewService from "../services/WebviewService.ts";
|
||||
import FavoriteRepository from "../repository/FavoriteRepository.ts";
|
||||
import VideoRepository from "../repository/VideoRepository.ts";
|
||||
import ConversionRepository from "../repository/ConversionRepository.ts";
|
||||
|
||||
@injectable()
|
||||
export default class HomeController implements Controller {
|
||||
private sharedState: Record<string, unknown> = {};
|
||||
|
||||
constructor(
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
@inject(TYPES.StoreService)
|
||||
private readonly storeService: StoreService,
|
||||
@inject(TYPES.ElectronStore)
|
||||
private readonly store: ElectronStore,
|
||||
@inject(TYPES.FavoriteRepository)
|
||||
private readonly favoriteRepository: FavoriteRepository,
|
||||
@inject(TYPES.MainWindowService)
|
||||
private readonly mainWindow: MainWindowService,
|
||||
@inject(TYPES.MainWindow)
|
||||
private readonly mainWindow: MainWindow,
|
||||
@inject(TYPES.VideoRepository)
|
||||
private readonly videoRepository: VideoRepository,
|
||||
@inject(TYPES.BrowserWindowService)
|
||||
private readonly browserWindow: BrowserWindowService
|
||||
@inject(TYPES.BrowserWindow)
|
||||
private readonly browserWindow: BrowserWindow,
|
||||
@inject(TYPES.WebviewService)
|
||||
private readonly webviewService: WebviewService,
|
||||
@inject(TYPES.ConversionRepository)
|
||||
private readonly conversionRepository: ConversionRepository
|
||||
) {}
|
||||
|
||||
@handle("get-env-path")
|
||||
@@ -49,7 +53,7 @@ export default class HomeController implements Controller {
|
||||
dbPath: db,
|
||||
workspace: workspace,
|
||||
platform: process.platform,
|
||||
local: this.storeService.get("local"),
|
||||
local: this.store.get("local"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -70,13 +74,13 @@ export default class HomeController implements Controller {
|
||||
|
||||
@handle("get-app-store")
|
||||
getAppStore() {
|
||||
return this.storeService.store;
|
||||
return this.store.store;
|
||||
}
|
||||
|
||||
@handle("on-favorite-item-context-menu")
|
||||
async onFavoriteItemContextMenu(e: IpcMainEvent, id: number) {
|
||||
const send = (action: string) => {
|
||||
this.mainWindow.webContents.send("favorite-item-event", {
|
||||
this.mainWindow.send("favorite-item-event", {
|
||||
action,
|
||||
payload: id,
|
||||
});
|
||||
@@ -103,13 +107,16 @@ export default class HomeController implements Controller {
|
||||
|
||||
@handle("select-download-dir")
|
||||
async selectDownloadDir(): Promise<string> {
|
||||
const result = await dialog.showOpenDialog(this.mainWindow, {
|
||||
const window = this.mainWindow.window;
|
||||
if (!window) return Promise.reject("未找到主窗口");
|
||||
|
||||
const result = await dialog.showOpenDialog(window, {
|
||||
properties: ["openDirectory"],
|
||||
});
|
||||
|
||||
if (!result.canceled) {
|
||||
const dir = result.filePaths[0];
|
||||
this.storeService.set("local", dir);
|
||||
this.store.set("local", dir);
|
||||
return dir;
|
||||
}
|
||||
return "";
|
||||
@@ -117,16 +124,30 @@ export default class HomeController implements Controller {
|
||||
|
||||
@handle("set-app-store")
|
||||
async setAppStore(e: IpcMainEvent, key: keyof AppStore, val: any) {
|
||||
// useProxy
|
||||
if (key === "useProxy") {
|
||||
const proxy = this.storeService.get("proxy");
|
||||
await this.storeService.setProxy(val, proxy);
|
||||
} else if (key === "proxy") {
|
||||
if (this.storeService.get("useProxy")) {
|
||||
this.storeService.setProxy(true, val);
|
||||
}
|
||||
const proxy = this.store.get("proxy");
|
||||
this.webviewService.setProxy(val, proxy);
|
||||
}
|
||||
// proxy
|
||||
if (key === "proxy") {
|
||||
const useProxy = this.store.get("useProxy");
|
||||
useProxy && this.webviewService.setProxy(true, val);
|
||||
}
|
||||
// block
|
||||
if (key === "blockAds") {
|
||||
this.webviewService.setBlocking(val);
|
||||
}
|
||||
// theme
|
||||
if (key === "theme") {
|
||||
nativeTheme.themeSource = val;
|
||||
}
|
||||
// isMobile
|
||||
if (key === "isMobile") {
|
||||
this.webviewService.setUserAgent(val);
|
||||
}
|
||||
|
||||
this.storeService.set(key, val);
|
||||
this.store.set(key, val);
|
||||
}
|
||||
|
||||
@handle("open-dir")
|
||||
@@ -142,12 +163,19 @@ export default class HomeController implements Controller {
|
||||
@handle("on-download-list-context-menu")
|
||||
async downloadListContextMenu(e: IpcMainEvent, id: number) {
|
||||
const send = (action: string) => {
|
||||
this.mainWindow.webContents.send("download-item-event", {
|
||||
this.mainWindow.send("download-item-event", {
|
||||
action,
|
||||
payload: id,
|
||||
});
|
||||
};
|
||||
const item = await this.videoRepository.findVideo(id);
|
||||
const template: Array<MenuItemConstructorOptions | MenuItem> = [
|
||||
{
|
||||
label: "拷贝链接地址",
|
||||
click: () => {
|
||||
clipboard.writeText(item.url || "");
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "选择",
|
||||
click: () => {
|
||||
@@ -181,10 +209,11 @@ export default class HomeController implements Controller {
|
||||
|
||||
@handle("convert-to-audio")
|
||||
async convertToAudio(e: IpcMainEvent, id: number) {
|
||||
const video = await this.videoRepository.findVideo(id);
|
||||
const local = this.storeService.get("local");
|
||||
const input = path.join(local, `${video?.name}.mp4`);
|
||||
const output = path.join(local, `${video?.name}.mp3`);
|
||||
const conversion = await this.conversionRepository.findConversion(id);
|
||||
const local = this.store.get("local");
|
||||
const input = conversion.path;
|
||||
const outName = `${path.basename(input, path.extname(input))}.mp3`;
|
||||
const output = path.join(local, outName);
|
||||
|
||||
const exist = await fs.exists(input);
|
||||
if (exist) {
|
||||
@@ -204,6 +233,42 @@ export default class HomeController implements Controller {
|
||||
// 关闭浏览器窗口
|
||||
this.browserWindow.hideWindow();
|
||||
// 修改设置中的属性
|
||||
this.storeService.set("openInNewWindow", false);
|
||||
this.store.set("openInNewWindow", false);
|
||||
}
|
||||
|
||||
@handle("get-local-ip")
|
||||
async getLocalIp() {
|
||||
return getLocalIP();
|
||||
}
|
||||
|
||||
@handle("get-shared-state")
|
||||
async getSharedState() {
|
||||
return this.sharedState;
|
||||
}
|
||||
|
||||
@handle("set-shared-state")
|
||||
async setSharedState(event: IpcMainEvent, state: any) {
|
||||
this.sharedState = state;
|
||||
}
|
||||
|
||||
@handle("get-download-log")
|
||||
async getDownloadLog(event: IpcMainEvent, id: number) {
|
||||
const video = await this.videoRepository.findVideo(id);
|
||||
return video.log || "";
|
||||
}
|
||||
|
||||
@handle("select-file")
|
||||
async selectFile() {
|
||||
const window = this.mainWindow.window;
|
||||
if (!window) return Promise.reject("未找到主窗口");
|
||||
|
||||
const result = await dialog.showOpenDialog(window, {
|
||||
properties: ["openFile"],
|
||||
});
|
||||
|
||||
if (!result.canceled) {
|
||||
return result.filePaths[0];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
import { IpcMainEvent } from "electron";
|
||||
import {
|
||||
IpcMainEvent,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemConstructorOptions,
|
||||
} from "electron";
|
||||
import { inject, injectable } from "inversify";
|
||||
import { handle } from "../helper/decorator";
|
||||
import { LoggerService, type Controller, WebviewService } from "../interfaces";
|
||||
import { TYPES } from "../types";
|
||||
import { handle } from "../helper/index.ts";
|
||||
import { type Controller } from "../interfaces.ts";
|
||||
import { TYPES } from "../types.ts";
|
||||
import WebviewService from "../services/WebviewService.ts";
|
||||
import ElectronStore from "../vendor/ElectronStore.ts";
|
||||
import { SniffingHelper } from "../services/SniffingHelperService.ts";
|
||||
|
||||
@injectable()
|
||||
export default class WebviewController implements Controller {
|
||||
constructor(
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
@inject(TYPES.WebviewService)
|
||||
private readonly webview: WebviewService
|
||||
private readonly webview: WebviewService,
|
||||
@inject(TYPES.ElectronStore)
|
||||
private readonly store: ElectronStore,
|
||||
@inject(TYPES.SniffingHelper)
|
||||
private readonly sniffingHelper: SniffingHelper,
|
||||
) {}
|
||||
|
||||
@handle("set-webview-bounds")
|
||||
@@ -23,6 +33,23 @@ export default class WebviewController implements Controller {
|
||||
await this.webview.loadURL(url);
|
||||
}
|
||||
|
||||
@handle("webview-url-contextmenu")
|
||||
async webviewUrlContextMenu() {
|
||||
const template: Array<MenuItemConstructorOptions | MenuItem> = [
|
||||
{
|
||||
label: "复制",
|
||||
role: "copy",
|
||||
},
|
||||
{
|
||||
label: "粘贴",
|
||||
role: "paste",
|
||||
},
|
||||
];
|
||||
|
||||
const menu = Menu.buildFromTemplate(template);
|
||||
menu.popup();
|
||||
}
|
||||
|
||||
@handle("webview-go-back")
|
||||
async webviewGoBack(): Promise<boolean> {
|
||||
return this.webview.goBack();
|
||||
@@ -47,4 +74,15 @@ export default class WebviewController implements Controller {
|
||||
async webviewGoHome() {
|
||||
await this.webview.goHome();
|
||||
}
|
||||
|
||||
@handle("webview-change-user-agent")
|
||||
async webviewChangeUserAgent(e: IpcMainEvent, isMobile: boolean) {
|
||||
this.webview.setUserAgent(isMobile);
|
||||
this.store.set("isMobile", isMobile);
|
||||
}
|
||||
|
||||
@handle("plugin-ready")
|
||||
async pluginReady() {
|
||||
this.sniffingHelper.pluginReady();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { ipcMain } from "electron";
|
||||
import { inject, injectable, multiInject } from "inversify";
|
||||
import { Controller } from "../interfaces.ts";
|
||||
import { TYPES } from "../types.ts";
|
||||
import ElectronLogger from "../vendor/ElectronLogger.ts";
|
||||
import { error, success } from "../helper/utils.ts";
|
||||
|
||||
@injectable()
|
||||
export default class IpcHandlerService {
|
||||
constructor(
|
||||
@multiInject(TYPES.Controller)
|
||||
private readonly controllers: Controller[],
|
||||
@inject(TYPES.ElectronLogger)
|
||||
private readonly logger: ElectronLogger,
|
||||
) {}
|
||||
|
||||
private registerIpc(
|
||||
controller: Controller,
|
||||
propertyKey: string | symbol,
|
||||
): void {
|
||||
const property = controller[propertyKey];
|
||||
if (typeof property !== "function") return;
|
||||
|
||||
const channel: string = Reflect.getMetadata(
|
||||
"ipc-channel",
|
||||
controller,
|
||||
propertyKey,
|
||||
);
|
||||
if (!channel) return;
|
||||
|
||||
const ipcMethod: "on" | "handle" = Reflect.getMetadata(
|
||||
"ipc-method",
|
||||
controller,
|
||||
propertyKey,
|
||||
);
|
||||
if (!ipcMethod) return;
|
||||
|
||||
ipcMain[ipcMethod](channel, async (...args: unknown[]) => {
|
||||
try {
|
||||
let res = property.call(controller, ...args);
|
||||
if (res.then) {
|
||||
res = await res;
|
||||
}
|
||||
return success(res);
|
||||
} catch (e: unknown) {
|
||||
this.logger.error(`处理 ipc [${channel}] 事件时异常: `, e);
|
||||
if (e instanceof Error) {
|
||||
return error(e.message);
|
||||
} else {
|
||||
return error(String(e));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
init(): void {
|
||||
for (const controller of this.controllers) {
|
||||
const Class = Object.getPrototypeOf(controller);
|
||||
Object.getOwnPropertyNames(Class).forEach((propertyKey) =>
|
||||
this.registerIpc(controller, propertyKey),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { protocol } from "electron";
|
||||
import isDev from "electron-is-dev";
|
||||
import { pathExists, readFile } from "fs-extra";
|
||||
import { injectable } from "inversify";
|
||||
import { join } from "path";
|
||||
import { URL } from "url";
|
||||
import { defaultScheme } from "../helper/index.ts";
|
||||
import mime from "mime-types";
|
||||
|
||||
@injectable()
|
||||
export default class ProtocolService {
|
||||
create(): void {
|
||||
if (isDev) return;
|
||||
|
||||
protocol.handle(defaultScheme, async (req) => {
|
||||
const pathName = new URL(req.url).pathname;
|
||||
let filePath = join(__dirname, "../renderer", pathName);
|
||||
const fileExist = await pathExists(filePath);
|
||||
if (!fileExist) {
|
||||
// 如果没有找到文件,直接返回 index.html , react history 模式
|
||||
filePath = join(__dirname, "../renderer/index.html");
|
||||
}
|
||||
const mimeType = mime.lookup(filePath);
|
||||
const data = await readFile(filePath);
|
||||
return new Response(data, {
|
||||
headers: { "Content-Type": mimeType || "text/html" },
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface Vendor {
|
||||
init(): Promise<void>;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { BrowserWindow, BrowserWindowConstructorOptions } from "electron";
|
||||
import isDev from "electron-is-dev";
|
||||
|
||||
export default class Window {
|
||||
window: BrowserWindow | null = null;
|
||||
options: BrowserWindowConstructorOptions;
|
||||
url: string;
|
||||
|
||||
constructor(options: BrowserWindowConstructorOptions) {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
create() {
|
||||
if (!this.url) {
|
||||
throw new Error("url is required");
|
||||
}
|
||||
|
||||
const window = new BrowserWindow(this.options);
|
||||
void window.loadURL(this.url);
|
||||
|
||||
window.once("ready-to-show", this.readyToShow);
|
||||
window.on("close", this.windowClose);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
readyToShow = () => {
|
||||
if (!this.window) return;
|
||||
|
||||
this.window.show();
|
||||
isDev && this.window.webContents.openDevTools();
|
||||
};
|
||||
|
||||
windowClose = () => {
|
||||
if (!this.window) return;
|
||||
|
||||
// 防止 webview 同时被销毁
|
||||
this.window.setBrowserView(null);
|
||||
|
||||
// 销毁窗口
|
||||
this.window = null;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from "typeorm";
|
||||
|
||||
@Entity({
|
||||
name: "conversion",
|
||||
})
|
||||
export class Conversion {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({
|
||||
type: "text",
|
||||
nullable: true,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
type: "text",
|
||||
nullable: false,
|
||||
default: "",
|
||||
})
|
||||
path: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdDate?: Date;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedDate?: Date;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DownloadStatus } from "interfaces";
|
||||
import { DownloadStatus, DownloadType } from "../interfaces.ts";
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
@@ -17,15 +17,36 @@ export class Video {
|
||||
@Column({
|
||||
type: "text",
|
||||
nullable: true,
|
||||
unique: true,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
type: "text",
|
||||
nullable: false,
|
||||
default: DownloadType.m3u8,
|
||||
})
|
||||
type: DownloadType;
|
||||
|
||||
@Column({
|
||||
type: "text",
|
||||
nullable: false,
|
||||
})
|
||||
url: string;
|
||||
|
||||
@Column({
|
||||
type: "text",
|
||||
nullable: true,
|
||||
})
|
||||
headers: string;
|
||||
|
||||
@Column({
|
||||
type: "boolean",
|
||||
default: false,
|
||||
nullable: false,
|
||||
})
|
||||
isLive: boolean;
|
||||
|
||||
@Column({
|
||||
type: "text",
|
||||
nullable: false,
|
||||
@@ -33,6 +54,12 @@ export class Video {
|
||||
})
|
||||
status: DownloadStatus;
|
||||
|
||||
@Column({
|
||||
type: "text",
|
||||
default: "",
|
||||
})
|
||||
log: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdDate: Date;
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
import { spawn } from "child_process";
|
||||
import { downloaderPath } from "./variables";
|
||||
import iconv from "iconv-lite";
|
||||
import { event } from "./utils";
|
||||
import { DownloadParams, DownloadProgress } from "interfaces";
|
||||
|
||||
const progressReg = /Progress:\s(\d+)\/(\d+)\s\(.+?\).+?\((.+?\/s).*?\)/g;
|
||||
|
||||
export const spawnDownload = (params: DownloadParams): Promise<void> => {
|
||||
const { id, abortSignal, url, local, name, deleteSegments } = params;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// const downloader = spawn(downloaderPath, [
|
||||
// url,
|
||||
// "--save-dir",
|
||||
// local,
|
||||
// "--save-name",
|
||||
// name,
|
||||
// ]);
|
||||
|
||||
const spawnParams = [url, "--workDir", local, "--saveName", name];
|
||||
|
||||
if (deleteSegments) {
|
||||
spawnParams.push("--enableDelAfterDone");
|
||||
}
|
||||
|
||||
const downloader = spawn(downloaderPath, spawnParams, {
|
||||
signal: abortSignal.signal,
|
||||
});
|
||||
|
||||
downloader.stdout.on("data", (data) => {
|
||||
const str = iconv.decode(Buffer.from(data), "gbk");
|
||||
str.split("\n").forEach((item) => {
|
||||
if (item.trim() == "") {
|
||||
return;
|
||||
}
|
||||
const result = progressReg.exec(item);
|
||||
if (result) {
|
||||
const [, cur, total, speed] = result;
|
||||
const progress: DownloadProgress = { id, cur, total, speed };
|
||||
event.emit("download-progress", progress);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
downloader.on("error", (err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
downloader.on("close", (code) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error("未知错误"));
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
import { spawn } from "child_process";
|
||||
import { ffmpegPath } from "./variables";
|
||||
import { ffmpegPath } from "./variables.ts";
|
||||
|
||||
export const convertToAudio = async (
|
||||
input: string,
|
||||
output: string
|
||||
output: string,
|
||||
): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ffmpeg = spawn(ffmpegPath, [
|
||||
|
||||
@@ -1,5 +1,41 @@
|
||||
export { sleep } from "./utils";
|
||||
export * from "./variables";
|
||||
export { on, handle } from "./decorator";
|
||||
export { spawnDownload } from "./download";
|
||||
export { convertToAudio } from "./ffmpeg";
|
||||
import os from "os";
|
||||
import fetch from "node-fetch";
|
||||
import https from "https";
|
||||
|
||||
export function getLocalIP() {
|
||||
const interfaces = os.networkInterfaces();
|
||||
let localIP = "";
|
||||
|
||||
// 遍历网络接口
|
||||
for (const key in interfaces) {
|
||||
const iface = interfaces[key];
|
||||
if (!iface) continue;
|
||||
|
||||
// 过滤出 IPv4 地址且非回环地址
|
||||
const filteredIface = iface.filter(
|
||||
(details) => details.family === "IPv4" && !details.internal,
|
||||
);
|
||||
|
||||
if (filteredIface.length > 0) {
|
||||
localIP = filteredIface[0].address;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return localIP;
|
||||
}
|
||||
|
||||
function fetchWrapper(url: string) {
|
||||
const options = {
|
||||
agent: new https.Agent({
|
||||
rejectUnauthorized: false,
|
||||
}),
|
||||
};
|
||||
return fetch(url, options);
|
||||
}
|
||||
|
||||
export { sleep, formatHeaders } from "./utils.ts";
|
||||
export * from "./variables.ts";
|
||||
export { on, handle } from "./decorator.ts";
|
||||
export { convertToAudio } from "./ffmpeg.ts";
|
||||
export { fetchWrapper as fetch };
|
||||
|
||||
@@ -4,4 +4,34 @@ export async function sleep(second = 1): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, second * 1000));
|
||||
}
|
||||
|
||||
export function formatHeaders(headers: Record<string, string>): string {
|
||||
if (!headers) return "";
|
||||
const formatted = Object.entries(headers)
|
||||
.map(([key, value]) => `${key}:${value}`)
|
||||
.join("\n");
|
||||
return formatted;
|
||||
}
|
||||
|
||||
export const event = new EventEmitter();
|
||||
|
||||
export interface IpcResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
data: Record<string, any> | null;
|
||||
}
|
||||
|
||||
export function success(data: Record<string, any>): IpcResponse {
|
||||
return {
|
||||
code: 0,
|
||||
message: "success",
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function error(message = "fail"): IpcResponse {
|
||||
return {
|
||||
code: -1,
|
||||
message,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,19 +1,53 @@
|
||||
import { app } from "electron";
|
||||
import isDev from "electron-is-dev";
|
||||
import path from "path";
|
||||
import { resolve } from "path";
|
||||
|
||||
if (!isDev) {
|
||||
global.__bin__ = path.resolve(app.getAppPath(), "../bin");
|
||||
const appPath = app.getAppPath();
|
||||
export const appData = app.getPath("appData");
|
||||
export const download = app.getPath("downloads");
|
||||
|
||||
export enum Platform {
|
||||
Windows = "win32",
|
||||
MacOS = "darwin",
|
||||
Linux = "linux",
|
||||
}
|
||||
|
||||
export const appData = app.getPath("appData");
|
||||
export const appName = process.env.APP_NAME || "electron-template";
|
||||
export const workspace = path.resolve(appData, appName);
|
||||
export const isMac = process.platform === Platform.MacOS;
|
||||
export const isWin = process.platform === Platform.Windows;
|
||||
export const isLinux = process.platform === Platform.Linux;
|
||||
|
||||
if (!isDev) {
|
||||
global.__bin__ = resolve(appPath, "../bin");
|
||||
}
|
||||
|
||||
export function resolveStatic(path: string) {
|
||||
const relativePath = isDev ? "../.." : "..";
|
||||
return resolve(appPath, relativePath, path);
|
||||
}
|
||||
export function resolveBin(path: string) {
|
||||
if (isWin) {
|
||||
path += ".exe";
|
||||
}
|
||||
return resolve(__bin__, path);
|
||||
}
|
||||
|
||||
export const appName = process.env.APP_NAME || "mediago";
|
||||
export const workspace = resolve(appData, appName);
|
||||
export const defaultScheme = "mediago";
|
||||
export const download = app.getPath("downloads");
|
||||
export const PERSIST_MEDIAGO = "persist:mediago";
|
||||
export const PERSIST_WEBVIEW = "persist:webview";
|
||||
export const db = path.resolve(workspace, "app.db");
|
||||
// export const downloaderPath = path.resolve(__bin__, "N_m3u8DL-RE.exe");
|
||||
export const downloaderPath = path.resolve(__bin__, "N_m3u8DL-CLI_v3.0.2.exe");
|
||||
export const ffmpegPath = path.resolve(__bin__, "ffmpeg.exe");
|
||||
export const db = resolve(workspace, "app.db");
|
||||
|
||||
// bin path
|
||||
export const ffmpegPath = resolveBin("ffmpeg");
|
||||
export const biliDownloaderBin = resolveBin("BBDown");
|
||||
export const m3u8DownloaderBin = resolveBin("N_m3u8DL-RE");
|
||||
|
||||
// plugin path
|
||||
export const pluginPath = resolveStatic("plugin/index.js");
|
||||
|
||||
// user agent
|
||||
export const pcUA =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
|
||||
export const mobileUA =
|
||||
"Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36";
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
declare module "*.svg";
|
||||
declare module "*.png";
|
||||
declare module "*.jpg";
|
||||
declare module "*.jpeg";
|
||||
declare module "*.gif";
|
||||
declare module "*.bmp";
|
||||
declare module "*.tiff";
|
||||
@@ -1,11 +1,16 @@
|
||||
import "reflect-metadata";
|
||||
import { app, protocol } from "electron";
|
||||
import { defaultScheme } from "./helper/variables";
|
||||
import { type App } from "./interfaces";
|
||||
import { container } from "./inversify.config";
|
||||
import { TYPES } from "./types";
|
||||
import { defaultScheme } from "./helper/index.ts";
|
||||
import { container } from "./inversify.config.ts";
|
||||
import { TYPES } from "./types.ts";
|
||||
import ElectronApp from "./app.ts";
|
||||
|
||||
const gotTheLock = app.requestSingleInstanceLock();
|
||||
const start = async (): Promise<void> => {
|
||||
if (!gotTheLock) {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{
|
||||
scheme: defaultScheme,
|
||||
@@ -16,8 +21,12 @@ const start = async (): Promise<void> => {
|
||||
},
|
||||
]);
|
||||
await app.whenReady();
|
||||
const mediago = container.get<App>(TYPES.App);
|
||||
const mediago = container.get<ElectronApp>(TYPES.ElectronApp);
|
||||
mediago.init();
|
||||
|
||||
app.on("window-all-closed", () => {
|
||||
// empty
|
||||
});
|
||||
};
|
||||
|
||||
void start();
|
||||
|
||||
@@ -1,66 +1,15 @@
|
||||
import { type BrowserWindow } from "electron";
|
||||
import { ElectronLog } from "electron-log";
|
||||
import Store from "electron-store";
|
||||
import { Favorite } from "entity/Favorite";
|
||||
import { Video } from "entity/Video";
|
||||
import EventEmitter from "events";
|
||||
import { AppStore } from "main";
|
||||
import { DataSource, EntityManager, UpdateResult, DeleteResult } from "typeorm";
|
||||
|
||||
export interface MainWindowService extends BrowserWindow {
|
||||
init: () => void;
|
||||
}
|
||||
|
||||
export interface BrowserWindowService extends BrowserWindow {
|
||||
init: () => void;
|
||||
showWindow: () => void;
|
||||
hideWindow: () => void;
|
||||
}
|
||||
|
||||
export interface App {
|
||||
init: () => void;
|
||||
}
|
||||
|
||||
export interface IpcHandlerService {
|
||||
init: () => void;
|
||||
}
|
||||
|
||||
export interface ProtocolService {
|
||||
create: () => void;
|
||||
}
|
||||
|
||||
export interface UpdateService {
|
||||
init: () => void;
|
||||
}
|
||||
|
||||
export interface DatabaseService {
|
||||
manager: EntityManager;
|
||||
appDataSource: DataSource;
|
||||
init: () => void;
|
||||
}
|
||||
import { Conversion } from "./entity/Conversion.ts";
|
||||
|
||||
export type Controller = Record<string | symbol, any>;
|
||||
|
||||
export interface LoggerService {
|
||||
logger: ElectronLog;
|
||||
info: (...args: any[]) => void;
|
||||
error: (...args: any[]) => void;
|
||||
warn: (...args: any[]) => void;
|
||||
debug: (...args: any[]) => void;
|
||||
}
|
||||
|
||||
export interface StoreService extends Store<AppStore> {
|
||||
init: () => void;
|
||||
setProxy: (
|
||||
useProxy: boolean,
|
||||
proxy: string,
|
||||
isInit?: boolean
|
||||
) => Promise<void>;
|
||||
}
|
||||
|
||||
export interface DownloadItem {
|
||||
id: number;
|
||||
type: DownloadType;
|
||||
name: string;
|
||||
url: string;
|
||||
headers?: string;
|
||||
status?: DownloadStatus;
|
||||
isLive?: boolean;
|
||||
}
|
||||
|
||||
export enum DownloadFilter {
|
||||
@@ -74,42 +23,19 @@ export interface DownloadItemPagination {
|
||||
filter?: DownloadFilter;
|
||||
}
|
||||
|
||||
export interface ConversionPagination {
|
||||
current?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
export interface VideoResponse {
|
||||
total: number;
|
||||
list: DownloadItem[];
|
||||
}
|
||||
|
||||
export interface VideoRepository {
|
||||
addVideo: (video: DownloadItem) => Promise<Video>;
|
||||
findVideos: (pagiantion: DownloadItemPagination) => Promise<VideoResponse>;
|
||||
findVideo: (id: number) => Promise<Video | null>;
|
||||
changeVideoStatus: (
|
||||
id: number | number[],
|
||||
status: DownloadStatus
|
||||
) => Promise<UpdateResult>;
|
||||
findWattingAndDownloadingVideos: () => Promise<Video[]>;
|
||||
deleteDownloadItem: (id: number) => Promise<DeleteResult>;
|
||||
}
|
||||
|
||||
export interface FavoriteRepository {
|
||||
findFavorites: () => Promise<Favorite[]>;
|
||||
addFavorite: (favorite: Favorite) => Promise<Favorite>;
|
||||
removeFavorite: (id: number) => Promise<void>;
|
||||
}
|
||||
|
||||
export interface WebviewService {
|
||||
webContents: Electron.WebContents;
|
||||
init: () => void;
|
||||
getBounds: () => Electron.Rectangle;
|
||||
setAutoResize: (options: Electron.AutoResizeOptions) => void;
|
||||
setBackgroundColor: (color: string) => void;
|
||||
setBounds: (bounds: Electron.Rectangle) => void;
|
||||
loadURL: (url?: string) => void;
|
||||
goBack: () => Promise<boolean>;
|
||||
reload: () => Promise<void>;
|
||||
goHome: () => Promise<void>;
|
||||
hide: () => void;
|
||||
show: () => void;
|
||||
export interface ConversionResponse {
|
||||
total: number;
|
||||
list: Conversion[];
|
||||
}
|
||||
|
||||
export enum DownloadStatus {
|
||||
@@ -121,29 +47,32 @@ export enum DownloadStatus {
|
||||
Failed = "failed",
|
||||
}
|
||||
|
||||
export interface DownloadService extends EventEmitter {
|
||||
addTask: (task: Task) => Promise<void>;
|
||||
stopTask: (id: number) => Promise<void>;
|
||||
}
|
||||
|
||||
export type Task = {
|
||||
id: number;
|
||||
params: Omit<DownloadParams, "id" | "abortSignal">;
|
||||
process: (params: DownloadParams) => Promise<void>;
|
||||
params: Omit<DownloadParams, "id" | "abortSignal" | "callback">;
|
||||
};
|
||||
|
||||
export interface DownloadProgress {
|
||||
id: number;
|
||||
cur: string;
|
||||
total: string;
|
||||
type: string;
|
||||
percent: string;
|
||||
speed: string;
|
||||
isLive: boolean;
|
||||
}
|
||||
|
||||
export enum DownloadType {
|
||||
m3u8 = "m3u8",
|
||||
bilibili = "bilibili",
|
||||
}
|
||||
export interface DownloadParams {
|
||||
id: number;
|
||||
type: DownloadType;
|
||||
url: string;
|
||||
local: string;
|
||||
name: string;
|
||||
headers?: string;
|
||||
abortSignal: AbortController;
|
||||
proxy?: string;
|
||||
deleteSegments?: boolean;
|
||||
callback: (progress: DownloadProgress) => void;
|
||||
}
|
||||
|
||||
@@ -1,71 +1,68 @@
|
||||
import DownloadController from "controller/DownloadController";
|
||||
import HomeController from "controller/HomeController";
|
||||
import WebviewController from "controller/WebviewController";
|
||||
import DownloadController from "./controller/DownloadController.ts";
|
||||
import HomeController from "./controller/HomeController.ts";
|
||||
import WebviewController from "./controller/WebviewController.ts";
|
||||
import { Container } from "inversify";
|
||||
import FavoriteRepositoryImpl from "repository/favoriteRepositoryImpl";
|
||||
import VideoRepositoryImpl from "repository/videoRepositoryImpl";
|
||||
import BrowserWindowServiceImpl from "services/BrowserWindowServiceImpl";
|
||||
import DatabaseServiceImpl from "services/DatabaseServiceImpl";
|
||||
import DownloadServiceImpl from "services/DownloadServiceImpl";
|
||||
import StoreServiceImpl from "services/StoreServiceImpl";
|
||||
import WebviewServiceImpl from "services/WebviewServiceImpl";
|
||||
import ElectronApp from "./app";
|
||||
import {
|
||||
App,
|
||||
StoreService,
|
||||
Controller,
|
||||
IpcHandlerService,
|
||||
LoggerService,
|
||||
MainWindowService,
|
||||
ProtocolService,
|
||||
UpdateService,
|
||||
VideoRepository,
|
||||
DatabaseService,
|
||||
FavoriteRepository,
|
||||
WebviewService,
|
||||
BrowserWindowService,
|
||||
} from "./interfaces";
|
||||
import IpcHandlerServiceImpl from "./services/IpcHandlerServiceImpl";
|
||||
import LoggerServiceImpl from "./services/LoggerServiceImpl";
|
||||
import MainWindowServiceImpl from "./services/MainWindowServiceImpl";
|
||||
import ProtocolServiceImpl from "./services/ProtocolServiceImpl";
|
||||
import UpdateServiceImpl from "./services/UpdateServiceImpl";
|
||||
import { TYPES } from "./types";
|
||||
import FavoriteRepository from "./repository/FavoriteRepository.ts";
|
||||
import VideoRepository from "./repository/VideoRepository.ts";
|
||||
import WebviewService from "./services/WebviewService.ts";
|
||||
import ElectronApp from "./app.ts";
|
||||
import { Controller } from "./interfaces.ts";
|
||||
import { TYPES } from "./types.ts";
|
||||
import MainWindow from "./windows/MainWindow.ts";
|
||||
import BrowserWindow from "./windows/BrowserWindow.ts";
|
||||
import { SniffingHelper } from "./services/SniffingHelperService.ts";
|
||||
import DownloadService from "./services/DownloadService.ts";
|
||||
import ElectronLogger from "./vendor/ElectronLogger.ts";
|
||||
import ElectronUpdater from "./vendor/ElectronUpdater.ts";
|
||||
import TypeORM from "./vendor/TypeORM.ts";
|
||||
import ElectronDevtools from "./vendor/ElectronDevtools.ts";
|
||||
import ElectronStore from "./vendor/ElectronStore.ts";
|
||||
import IpcHandler from "./core/ipc.ts";
|
||||
import ProtocolService from "./core/protocol.ts";
|
||||
import ConversionController from "./controller/ConversionController.ts";
|
||||
import ConversionRepository from "./repository/ConversionRepository.ts";
|
||||
|
||||
const container = new Container({
|
||||
skipBaseClassChecks: true,
|
||||
defaultScope: "Singleton",
|
||||
autoBindInjectable: true,
|
||||
});
|
||||
container
|
||||
.bind<MainWindowService>(TYPES.MainWindowService)
|
||||
.to(MainWindowServiceImpl);
|
||||
container
|
||||
.bind<BrowserWindowService>(TYPES.BrowserWindowService)
|
||||
.to(BrowserWindowServiceImpl);
|
||||
container.bind<App>(TYPES.App).to(ElectronApp);
|
||||
container
|
||||
.bind<IpcHandlerService>(TYPES.IpcHandlerService)
|
||||
.to(IpcHandlerServiceImpl);
|
||||
container.bind<ProtocolService>(TYPES.ProtocolService).to(ProtocolServiceImpl);
|
||||
container.bind<UpdateService>(TYPES.UpdateService).to(UpdateServiceImpl);
|
||||
container.bind<LoggerService>(TYPES.LoggerService).to(LoggerServiceImpl);
|
||||
container.bind<StoreService>(TYPES.StoreService).to(StoreServiceImpl);
|
||||
container.bind<DatabaseService>(TYPES.DatabaseService).to(DatabaseServiceImpl);
|
||||
container.bind<WebviewService>(TYPES.WebviewService).to(WebviewServiceImpl);
|
||||
container
|
||||
.bind<DownloadServiceImpl>(TYPES.DownloadService)
|
||||
.to(DownloadServiceImpl);
|
||||
|
||||
// === controller
|
||||
container.bind<ElectronApp>(TYPES.ElectronApp).to(ElectronApp);
|
||||
|
||||
// services
|
||||
container.bind<WebviewService>(TYPES.WebviewService).to(WebviewService);
|
||||
container.bind<DownloadService>(TYPES.DownloadService).to(DownloadService);
|
||||
container.bind<SniffingHelper>(TYPES.SniffingHelper).to(SniffingHelper);
|
||||
|
||||
// windows
|
||||
container.bind<MainWindow>(TYPES.MainWindow).to(MainWindow);
|
||||
container.bind<BrowserWindow>(TYPES.BrowserWindow).to(BrowserWindow);
|
||||
|
||||
// controller
|
||||
container.bind<Controller>(TYPES.Controller).to(HomeController);
|
||||
container.bind<Controller>(TYPES.Controller).to(WebviewController);
|
||||
container.bind<Controller>(TYPES.Controller).to(DownloadController);
|
||||
container.bind<Controller>(TYPES.Controller).to(ConversionController);
|
||||
|
||||
// === repository
|
||||
container.bind<VideoRepository>(TYPES.VideoRepository).to(VideoRepositoryImpl);
|
||||
// repository
|
||||
container.bind<VideoRepository>(TYPES.VideoRepository).to(VideoRepository);
|
||||
container
|
||||
.bind<FavoriteRepository>(TYPES.FavoriteRepository)
|
||||
.to(FavoriteRepositoryImpl);
|
||||
.to(FavoriteRepository);
|
||||
container
|
||||
.bind<ConversionRepository>(TYPES.ConversionRepository)
|
||||
.to(ConversionRepository);
|
||||
|
||||
// vendor
|
||||
container.bind<ElectronDevtools>(TYPES.ElectronDevtools).to(ElectronDevtools);
|
||||
container.bind<TypeORM>(TYPES.TypeORM).to(TypeORM);
|
||||
container.bind<ElectronUpdater>(TYPES.ElectronUpdater).to(ElectronUpdater);
|
||||
container.bind<ElectronLogger>(TYPES.ElectronLogger).to(ElectronLogger);
|
||||
container.bind<ElectronStore>(TYPES.ElectronStore).to(ElectronStore);
|
||||
|
||||
// core
|
||||
container.bind<ProtocolService>(TYPES.ProtocolService).to(ProtocolService);
|
||||
container.bind<IpcHandler>(TYPES.IpcHandlerService).to(IpcHandler);
|
||||
|
||||
export { container };
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { Video } from "electron";
|
||||
import { type Favorite } from "entity/Favorite";
|
||||
import {
|
||||
DownloadItem,
|
||||
DownloadItemPagination,
|
||||
VideoResponse,
|
||||
} from "interfaces";
|
||||
import { Rectangle } from "electron";
|
||||
import { type DownloadType } from "interfaces";
|
||||
import { AppLanguage, AppTheme } from "./types";
|
||||
|
||||
declare interface EnvPath {
|
||||
binPath: string;
|
||||
@@ -14,43 +10,16 @@ declare interface EnvPath {
|
||||
local: string;
|
||||
}
|
||||
|
||||
declare interface ElectronAPI {
|
||||
getEnvPath: () => Promise<EnvPath>;
|
||||
getFavorites: () => Promise<Favorite>;
|
||||
addFavorite: (favorite: Favorite) => Promise<Favorite>;
|
||||
removeFavorite: (id: number) => Promise<void>;
|
||||
setWebviewBounds: (rect: Electron.Rectangle) => Promise<void>;
|
||||
webviewLoadURL: (url?: string) => Promise<void>;
|
||||
webviewGoBack: () => Promise<boolean>;
|
||||
webviewReload: () => Promise<void>;
|
||||
webwiewGoHome: () => Promise<void>;
|
||||
getAppStore: () => Promise<AppStore>;
|
||||
onSelectDownloadDir: () => Promise<string>;
|
||||
setAppStore: (key: keyof AppStore, val: any) => Promise<void>;
|
||||
openDir: (dir: string) => Promise<void>;
|
||||
addDownloadItem: (video: DownloadItem) => Promise<Video>;
|
||||
getDownloadItems: (
|
||||
pagiantion: DownloadItemPagination
|
||||
) => Promise<VideoResponse>;
|
||||
startDownload: (vid: number) => Promise<void>;
|
||||
openUrl: (url: string) => Promise<void>;
|
||||
stopDownload: (id: number) => Promise<void>;
|
||||
onDownloadListContextMenu: (id: number) => Promise<void>;
|
||||
onFavoriteItemContextMenu: (id: number) => Promise<void>;
|
||||
deleteDownloadItem: (id: number) => Promise<void>;
|
||||
convertToAudio: (id: number) => Promise<void>;
|
||||
rendererEvent: (channel: string, funcId: string, listener: any) => void;
|
||||
removeEventListener: (channel: string, funcId: string) => void;
|
||||
showBrowserWindow: () => Promise<void>;
|
||||
webviewHide: () => Promise<void>;
|
||||
webviewShow: () => Promise<void>;
|
||||
downloadNow: (video: DownloadItem) => Promise<void>;
|
||||
combineToHomePage: () => Promise<void>;
|
||||
declare interface BrowserWindowInitialVal {
|
||||
url?: string;
|
||||
sourceList?: WebSource[];
|
||||
}
|
||||
|
||||
declare interface LinkMessage {
|
||||
declare interface WebSource {
|
||||
url: string;
|
||||
title: string;
|
||||
type: DownloadType;
|
||||
name: string;
|
||||
headers?: string;
|
||||
}
|
||||
|
||||
declare interface AppStore {
|
||||
@@ -66,4 +35,26 @@ declare interface AppStore {
|
||||
deleteSegments: boolean;
|
||||
// 新窗口打开浏览器
|
||||
openInNewWindow: boolean;
|
||||
mainBounds?: Rectangle;
|
||||
browserBounds?: Rectangle;
|
||||
blockAds: boolean;
|
||||
// 主题
|
||||
theme: AppTheme;
|
||||
// 使用浏览器插件
|
||||
useExtension: boolean;
|
||||
// 是否使用手机UA
|
||||
isMobile: boolean;
|
||||
// 最大同时下载数
|
||||
maxRunner: number;
|
||||
// 语言
|
||||
language: AppLanguage;
|
||||
// 是否显示终端
|
||||
showTerminal: boolean;
|
||||
// 隐私模式
|
||||
privacy: boolean;
|
||||
}
|
||||
|
||||
declare interface BrowserStore {
|
||||
url: string;
|
||||
sourceList: WebSource[];
|
||||
}
|
||||
|
||||
@@ -1,50 +1,174 @@
|
||||
import { contextBridge, ipcRenderer } from "electron";
|
||||
import { ElectronAPI } from "./main";
|
||||
import { contextBridge, ipcRenderer } from "electron/renderer";
|
||||
import { shell } from "electron/common";
|
||||
import { AppStore, BrowserStore, EnvPath } from "./main.ts";
|
||||
import { type Favorite } from "./entity/Favorite.ts";
|
||||
import {
|
||||
ConversionPagination,
|
||||
ConversionResponse,
|
||||
VideoResponse,
|
||||
type DownloadItem,
|
||||
type DownloadItemPagination,
|
||||
} from "./interfaces.ts";
|
||||
import { Video } from "./entity/Video.ts";
|
||||
import { Conversion } from "./entity/Conversion.ts";
|
||||
|
||||
const apiFunctions: Record<string, any> = {};
|
||||
|
||||
const apiKey = "electron";
|
||||
const handleApi: ElectronAPI = {
|
||||
getEnvPath: () => ipcRenderer.invoke("get-env-path"),
|
||||
getFavorites: () => ipcRenderer.invoke("get-favorites"),
|
||||
addFavorite: (favorite) => ipcRenderer.invoke("add-favorite", favorite),
|
||||
removeFavorite: (id) => ipcRenderer.invoke("remove-favorite", id),
|
||||
setWebviewBounds: (rect) => ipcRenderer.invoke("set-webview-bounds", rect),
|
||||
webviewGoBack: () => ipcRenderer.invoke("webview-go-back"),
|
||||
webviewReload: () => ipcRenderer.invoke("webview-reload"),
|
||||
webviewLoadURL: (url?: string) => ipcRenderer.invoke("webview-load-url", url),
|
||||
webwiewGoHome: () => ipcRenderer.invoke("webview-go-home"),
|
||||
getAppStore: () => ipcRenderer.invoke("get-app-store"),
|
||||
onSelectDownloadDir: () => ipcRenderer.invoke("select-download-dir"),
|
||||
setAppStore: (key, val) => ipcRenderer.invoke("set-app-store", key, val),
|
||||
openDir: (dir) => ipcRenderer.invoke("open-dir", dir),
|
||||
addDownloadItem: (video) => ipcRenderer.invoke("add-download-item", video),
|
||||
getDownloadItems: (p) => ipcRenderer.invoke("get-download-items", p),
|
||||
startDownload: (vid) => ipcRenderer.invoke("start-download", vid),
|
||||
openUrl: (url: string) => ipcRenderer.invoke("open-url", url),
|
||||
stopDownload: (id) => ipcRenderer.invoke("stop-download", id),
|
||||
onDownloadListContextMenu: (id) =>
|
||||
ipcRenderer.invoke("on-download-list-context-menu", id),
|
||||
onFavoriteItemContextMenu: (id) =>
|
||||
ipcRenderer.invoke("on-favorite-item-context-menu", id),
|
||||
deleteDownloadItem: (id) => ipcRenderer.invoke("delete-download-item", id),
|
||||
convertToAudio: (id) => ipcRenderer.invoke("convert-to-audio", id),
|
||||
rendererEvent: (channel, funcId, listener) => {
|
||||
|
||||
export type ElectronApi = typeof electronApi;
|
||||
|
||||
const electronApi = {
|
||||
getEnvPath(): Promise<EnvPath> {
|
||||
return ipcRenderer.invoke("get-env-path");
|
||||
},
|
||||
getFavorites(): Promise<Favorite[]> {
|
||||
return ipcRenderer.invoke("get-favorites");
|
||||
},
|
||||
addFavorite(
|
||||
favorite: Omit<Favorite, "id" | "createdDate" | "updatedDate">
|
||||
): Promise<Favorite> {
|
||||
return ipcRenderer.invoke("add-favorite", favorite);
|
||||
},
|
||||
removeFavorite(id: number): Promise<void> {
|
||||
return ipcRenderer.invoke("remove-favorite", id);
|
||||
},
|
||||
setWebviewBounds(rect: Electron.Rectangle): Promise<void> {
|
||||
return ipcRenderer.invoke("set-webview-bounds", rect);
|
||||
},
|
||||
webviewGoBack(): Promise<boolean> {
|
||||
return ipcRenderer.invoke("webview-go-back");
|
||||
},
|
||||
webviewReload(): Promise<void> {
|
||||
return ipcRenderer.invoke("webview-reload");
|
||||
},
|
||||
webviewLoadURL(url?: string): Promise<void> {
|
||||
return ipcRenderer.invoke("webview-load-url", url);
|
||||
},
|
||||
webviewGoHome(): Promise<void> {
|
||||
return ipcRenderer.invoke("webview-go-home");
|
||||
},
|
||||
getAppStore(): Promise<AppStore> {
|
||||
return ipcRenderer.invoke("get-app-store");
|
||||
},
|
||||
onSelectDownloadDir(): Promise<string> {
|
||||
return ipcRenderer.invoke("select-download-dir");
|
||||
},
|
||||
setAppStore(
|
||||
key: keyof AppStore,
|
||||
val: AppStore[keyof AppStore]
|
||||
): Promise<void> {
|
||||
return ipcRenderer.invoke("set-app-store", key, val);
|
||||
},
|
||||
openDir(dir: string): Promise<void> {
|
||||
return ipcRenderer.invoke("open-dir", dir);
|
||||
},
|
||||
addDownloadItem(video: Omit<DownloadItem, "id">): Promise<Video> {
|
||||
return ipcRenderer.invoke("add-download-item", video);
|
||||
},
|
||||
addDownloadItems(videos: Omit<DownloadItem, "id">[]): Promise<Video[]> {
|
||||
return ipcRenderer.invoke("add-download-items", videos);
|
||||
},
|
||||
getDownloadItems(p: DownloadItemPagination): Promise<VideoResponse> {
|
||||
return ipcRenderer.invoke("get-download-items", p);
|
||||
},
|
||||
startDownload(vid: number): Promise<void> {
|
||||
return ipcRenderer.invoke("start-download", vid);
|
||||
},
|
||||
openUrl(url: string): Promise<void> {
|
||||
return ipcRenderer.invoke("open-url", url);
|
||||
},
|
||||
stopDownload(id: number): Promise<void> {
|
||||
return ipcRenderer.invoke("stop-download", id);
|
||||
},
|
||||
onDownloadListContextMenu(id: number): Promise<void> {
|
||||
return ipcRenderer.invoke("on-download-list-context-menu", id);
|
||||
},
|
||||
onFavoriteItemContextMenu(id: number): Promise<void> {
|
||||
return ipcRenderer.invoke("on-favorite-item-context-menu", id);
|
||||
},
|
||||
deleteDownloadItem(id: number): Promise<void> {
|
||||
return ipcRenderer.invoke("delete-download-item", id);
|
||||
},
|
||||
convertToAudio(id: number): Promise<void> {
|
||||
return ipcRenderer.invoke("convert-to-audio", id);
|
||||
},
|
||||
rendererEvent(channel: string, funcId: string, listener: any): void {
|
||||
const key = `${channel}-${funcId}`;
|
||||
apiFunctions[key] = listener;
|
||||
ipcRenderer.on(channel, listener);
|
||||
},
|
||||
removeEventListener: (channel, funcId) => {
|
||||
removeEventListener(channel: string, funcId: string): void {
|
||||
const key = `${channel}-${funcId}`;
|
||||
const fun = apiFunctions[key];
|
||||
ipcRenderer.removeListener(channel, fun);
|
||||
delete apiFunctions[key];
|
||||
},
|
||||
showBrowserWindow: () => ipcRenderer.invoke("show-browser-window"),
|
||||
webviewHide: () => ipcRenderer.invoke("webview-hide"),
|
||||
webviewShow: () => ipcRenderer.invoke("webview-show"),
|
||||
downloadNow: (video) => ipcRenderer.invoke("download-now", video),
|
||||
combineToHomePage: () => ipcRenderer.invoke("combine-to-home-page"),
|
||||
showBrowserWindow(): Promise<void> {
|
||||
return ipcRenderer.invoke("show-browser-window");
|
||||
},
|
||||
webviewHide(): Promise<void> {
|
||||
return ipcRenderer.invoke("webview-hide");
|
||||
},
|
||||
webviewShow(): Promise<void> {
|
||||
return ipcRenderer.invoke("webview-show");
|
||||
},
|
||||
webviewUrlContextMenu(): Promise<void> {
|
||||
return ipcRenderer.invoke("webview-url-contextmenu");
|
||||
},
|
||||
downloadNow(video: Omit<DownloadItem, "id">): Promise<void> {
|
||||
return ipcRenderer.invoke("download-now", video);
|
||||
},
|
||||
downloadItemsNow(videos: Omit<DownloadItem, "id">[]): Promise<void> {
|
||||
return ipcRenderer.invoke("download-items-now", videos);
|
||||
},
|
||||
editDownloadNow(video: DownloadItem): Promise<void> {
|
||||
return ipcRenderer.invoke("edit-download-now", video);
|
||||
},
|
||||
combineToHomePage(store: BrowserStore): Promise<void> {
|
||||
return ipcRenderer.invoke("combine-to-home-page", store);
|
||||
},
|
||||
editDownloadItem(video: DownloadItem): Promise<void> {
|
||||
return ipcRenderer.invoke("edit-download-item", video);
|
||||
},
|
||||
getLocalIP(): Promise<string> {
|
||||
return ipcRenderer.invoke("get-local-ip");
|
||||
},
|
||||
openBrowser(url: string): Promise<void> {
|
||||
return shell.openExternal(url);
|
||||
},
|
||||
selectFile(): Promise<string> {
|
||||
return ipcRenderer.invoke("select-file");
|
||||
},
|
||||
getSharedState(): Promise<any> {
|
||||
return ipcRenderer.invoke("get-shared-state");
|
||||
},
|
||||
setSharedState(state: any): Promise<void> {
|
||||
return ipcRenderer.invoke("set-shared-state", state);
|
||||
},
|
||||
setUserAgent(isMobile: boolean): Promise<void> {
|
||||
return ipcRenderer.invoke("webview-change-user-agent", isMobile);
|
||||
},
|
||||
getDownloadLog(id: number): Promise<string> {
|
||||
return ipcRenderer.invoke("get-download-log", id);
|
||||
},
|
||||
showDownloadDialog(data: Omit<DownloadItem, "id">[]) {
|
||||
return ipcRenderer.invoke("show-download-dialog", data);
|
||||
},
|
||||
pluginReady() {
|
||||
return ipcRenderer.invoke("plugin-ready");
|
||||
},
|
||||
getConversions(
|
||||
pagination: ConversionPagination
|
||||
): Promise<ConversionResponse> {
|
||||
return ipcRenderer.invoke("get-conversions", pagination);
|
||||
},
|
||||
addConversion(conversion: Omit<Conversion, "id">): Promise<Conversion> {
|
||||
return ipcRenderer.invoke("add-conversion", conversion);
|
||||
},
|
||||
deleteConversion(id: number): Promise<void> {
|
||||
return ipcRenderer.invoke("delete-conversion", id);
|
||||
},
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld(apiKey, handleApi);
|
||||
contextBridge.exposeInMainWorld(apiKey, electronApi);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { inject, injectable } from "inversify";
|
||||
import { ConversionPagination } from "../interfaces.ts";
|
||||
import { TYPES } from "../types.ts";
|
||||
import TypeORM from "../vendor/TypeORM.ts";
|
||||
import { Conversion } from "../entity/Conversion.ts";
|
||||
|
||||
@injectable()
|
||||
export default class ConversionRepository {
|
||||
constructor(
|
||||
@inject(TYPES.TypeORM)
|
||||
private readonly db: TypeORM
|
||||
) {}
|
||||
|
||||
async findConversion(id: number) {
|
||||
const repository = this.db.appDataSource.getRepository(Conversion);
|
||||
const conversion = await repository.findOneBy({ id });
|
||||
|
||||
if (!conversion) {
|
||||
throw new Error("没有找到该转换任务");
|
||||
}
|
||||
|
||||
return conversion;
|
||||
}
|
||||
|
||||
async getConversions(pagination: ConversionPagination) {
|
||||
const { current = 0, pageSize = 50 } = pagination;
|
||||
|
||||
const [items, count] = await this.db.appDataSource
|
||||
.getRepository(Conversion)
|
||||
.findAndCount({
|
||||
order: {
|
||||
createdDate: "ASC",
|
||||
},
|
||||
skip: (current - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
return {
|
||||
total: count,
|
||||
list: items,
|
||||
};
|
||||
}
|
||||
|
||||
async addConversion(conversion: Conversion) {
|
||||
await this.db.appDataSource.getRepository(Conversion).save(conversion);
|
||||
}
|
||||
|
||||
async deleteConversion(id: number) {
|
||||
await this.db.appDataSource.getRepository(Conversion).delete({ id });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { inject, injectable } from "inversify";
|
||||
import { TYPES } from "../types.ts";
|
||||
import { Favorite } from "../entity/Favorite.ts";
|
||||
import TypeORM from "../vendor/TypeORM.ts";
|
||||
|
||||
@injectable()
|
||||
export default class FavoriteRepository {
|
||||
constructor(
|
||||
@inject(TYPES.TypeORM)
|
||||
private readonly db: TypeORM,
|
||||
) {}
|
||||
|
||||
async findFavorites(): Promise<Favorite[]> {
|
||||
return await this.db.manager.find(Favorite, {
|
||||
order: {
|
||||
createdDate: "desc",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async addFavorite(favorite: Favorite): Promise<Favorite> {
|
||||
const exist = await this.db.manager.findOne(Favorite, {
|
||||
where: {
|
||||
url: favorite.url,
|
||||
},
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
throw new Error("网址已经存在");
|
||||
}
|
||||
|
||||
const item = new Favorite();
|
||||
item.title = favorite.title;
|
||||
item.url = favorite.url;
|
||||
item.icon = favorite.icon;
|
||||
return await this.db.manager.save(item);
|
||||
}
|
||||
|
||||
async removeFavorite(id: number): Promise<void> {
|
||||
await this.db.manager.getRepository(Favorite).delete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
import { Video } from "../entity/Video.ts";
|
||||
import { inject, injectable } from "inversify";
|
||||
import {
|
||||
DownloadFilter,
|
||||
DownloadItem,
|
||||
DownloadItemPagination,
|
||||
DownloadStatus,
|
||||
} from "../interfaces.ts";
|
||||
import { TYPES } from "../types.ts";
|
||||
import { In, Not } from "typeorm";
|
||||
import TypeORM from "../vendor/TypeORM.ts";
|
||||
|
||||
@injectable()
|
||||
export default class VideoRepository {
|
||||
constructor(
|
||||
@inject(TYPES.TypeORM)
|
||||
private readonly db: TypeORM
|
||||
) {}
|
||||
|
||||
async addVideo(video: Omit<DownloadItem, "id">) {
|
||||
// 先判断有没有同名的视频
|
||||
const exist = await this.findVideoByName(video.name);
|
||||
if (exist) {
|
||||
throw new Error("视频名称已存在,请更换视频名称");
|
||||
}
|
||||
const item = new Video();
|
||||
item.name = video.name;
|
||||
item.url = video.url;
|
||||
item.type = video.type;
|
||||
video.headers && (item.headers = video.headers);
|
||||
return await this.db.manager.save(item);
|
||||
}
|
||||
|
||||
async addVideos(videos: Omit<DownloadItem, "id">[]) {
|
||||
const items = videos.map((video) => {
|
||||
const item = new Video();
|
||||
item.name = video.name;
|
||||
item.url = video.url;
|
||||
item.type = video.type;
|
||||
video.headers && (item.headers = video.headers);
|
||||
return item;
|
||||
});
|
||||
return await this.db.manager.save(items);
|
||||
}
|
||||
|
||||
// 编辑视频
|
||||
async editVideo(video: DownloadItem) {
|
||||
const item = await this.db.appDataSource
|
||||
.getRepository(Video)
|
||||
.findOneBy({ id: video.id });
|
||||
if (!item) {
|
||||
throw new Error("视频不存在");
|
||||
}
|
||||
item.name = video.name;
|
||||
item.url = video.url;
|
||||
video.headers && (item.headers = video.headers);
|
||||
return await this.db.manager.save(item);
|
||||
}
|
||||
|
||||
// 查找所有视频
|
||||
async findAllVideos() {
|
||||
return await this.db.appDataSource.getRepository(Video).find({
|
||||
order: {
|
||||
createdDate: "DESC",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findVideos(pagination: DownloadItemPagination) {
|
||||
const {
|
||||
current = 0,
|
||||
pageSize = 50,
|
||||
filter = DownloadFilter.list,
|
||||
} = pagination;
|
||||
const filterCondition =
|
||||
filter === DownloadFilter.done
|
||||
? DownloadStatus.Success
|
||||
: Not(DownloadStatus.Success);
|
||||
|
||||
const [items, count] = await this.db.appDataSource
|
||||
.getRepository(Video)
|
||||
.findAndCount({
|
||||
where: {
|
||||
status: filterCondition,
|
||||
},
|
||||
order: {
|
||||
createdDate: "ASC",
|
||||
},
|
||||
skip: (current - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
return {
|
||||
total: count,
|
||||
list: items,
|
||||
};
|
||||
}
|
||||
|
||||
async findVideo(id: number) {
|
||||
const repository = this.db.appDataSource.getRepository(Video);
|
||||
const video = await repository.findOneBy({ id });
|
||||
|
||||
if (!video) {
|
||||
throw new Error("没有找到该视频");
|
||||
}
|
||||
|
||||
return video;
|
||||
}
|
||||
|
||||
async findVideoByName(name: string) {
|
||||
return this.db.appDataSource.getRepository(Video).findOneBy({
|
||||
name,
|
||||
});
|
||||
}
|
||||
|
||||
async changeVideoStatus(id: number | number[], status: DownloadStatus) {
|
||||
const ids = !Array.isArray(id) ? [id] : id;
|
||||
const videoRepository = this.db.appDataSource.getRepository(Video);
|
||||
const videos = await videoRepository.findBy({ id: In(ids) });
|
||||
for (const video of videos) {
|
||||
video.status = status;
|
||||
}
|
||||
await videoRepository.save(videos);
|
||||
}
|
||||
|
||||
async changeVideoIsLive(id: number) {
|
||||
const video = await this.findVideo(id);
|
||||
video.isLive = true;
|
||||
return this.db.manager.save(video);
|
||||
}
|
||||
|
||||
async findWattingAndDownloadingVideos() {
|
||||
return await this.db.appDataSource.getRepository(Video).find({
|
||||
where: {
|
||||
status: In([DownloadStatus.Downloading, DownloadStatus.Watting]),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async deleteDownloadItem(id: number) {
|
||||
return await this.db.appDataSource.getRepository(Video).delete(id);
|
||||
}
|
||||
|
||||
async findVideoByUrl(url: string) {
|
||||
return this.db.appDataSource.getRepository(Video).findOneBy({
|
||||
url,
|
||||
});
|
||||
}
|
||||
|
||||
async appendDownloadLog(id: number, message: string) {
|
||||
const video = await this.findVideo(id);
|
||||
video.log = video.log ? `${video.log}\n${message}` : message;
|
||||
return await this.db.manager.save(video);
|
||||
}
|
||||
|
||||
async getDownloadLog(id: number) {
|
||||
const video = await this.findVideo(id);
|
||||
return video.log;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
import { inject, injectable } from "inversify";
|
||||
import {
|
||||
DatabaseService,
|
||||
FavoriteRepository,
|
||||
LoggerService,
|
||||
} from "../interfaces";
|
||||
import { TYPES } from "../types";
|
||||
import { Favorite } from "entity/Favorite";
|
||||
|
||||
@injectable()
|
||||
export default class FavoriteRepositoryImpl implements FavoriteRepository {
|
||||
constructor(
|
||||
@inject(TYPES.DatabaseService)
|
||||
private readonly dataService: DatabaseService,
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService
|
||||
) {}
|
||||
|
||||
async findFavorites(): Promise<Favorite[]> {
|
||||
return await this.dataService.manager.find(Favorite, {
|
||||
order: {
|
||||
createdDate: "desc",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async addFavorite(favorite: Favorite): Promise<Favorite> {
|
||||
const exist = await this.dataService.manager.findOne(Favorite, {
|
||||
where: {
|
||||
url: favorite.url,
|
||||
},
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
return exist;
|
||||
}
|
||||
|
||||
const item = new Favorite();
|
||||
item.title = favorite.title;
|
||||
item.url = favorite.url;
|
||||
item.icon = favorite.icon;
|
||||
return await this.dataService.manager.save(item);
|
||||
}
|
||||
|
||||
async removeFavorite(id: number): Promise<void> {
|
||||
await this.dataService.manager.getRepository(Favorite).delete(id);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
import { Video } from "../entity/Video";
|
||||
import { inject, injectable } from "inversify";
|
||||
import {
|
||||
DatabaseService,
|
||||
DownloadFilter,
|
||||
DownloadItem,
|
||||
DownloadItemPagination,
|
||||
DownloadStatus,
|
||||
LoggerService,
|
||||
VideoRepository,
|
||||
} from "../interfaces";
|
||||
import { TYPES } from "../types";
|
||||
import { In, Not } from "typeorm";
|
||||
|
||||
@injectable()
|
||||
export default class VideoRepositoryImpl implements VideoRepository {
|
||||
constructor(
|
||||
@inject(TYPES.DatabaseService)
|
||||
private readonly dataService: DatabaseService,
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService
|
||||
) {}
|
||||
|
||||
async addVideo(video: DownloadItem) {
|
||||
const item = new Video();
|
||||
item.name = video.name;
|
||||
item.url = video.url;
|
||||
return await this.dataService.manager.save(item);
|
||||
}
|
||||
|
||||
async findVideos({
|
||||
current = 0,
|
||||
pageSize = 50,
|
||||
filter = DownloadFilter.list,
|
||||
}: DownloadItemPagination) {
|
||||
const filterCondition =
|
||||
filter === DownloadFilter.done
|
||||
? DownloadStatus.Success
|
||||
: Not(DownloadStatus.Success);
|
||||
|
||||
const [items, count] = await this.dataService.appDataSource
|
||||
.getRepository(Video)
|
||||
.findAndCount({
|
||||
where: {
|
||||
status: filterCondition,
|
||||
},
|
||||
order: {
|
||||
createdDate: "DESC",
|
||||
},
|
||||
skip: (current - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
return {
|
||||
total: count,
|
||||
list: items,
|
||||
};
|
||||
}
|
||||
|
||||
async findVideo(id: number) {
|
||||
return this.dataService.appDataSource.getRepository(Video).findOneBy({
|
||||
id,
|
||||
});
|
||||
}
|
||||
|
||||
async changeVideoStatus(id: number | number[], status: DownloadStatus) {
|
||||
const ids = !Array.isArray(id) ? [id] : id;
|
||||
return this.dataService.appDataSource
|
||||
.createQueryBuilder()
|
||||
.update(Video)
|
||||
.set({ status })
|
||||
.where({ id: In(ids) })
|
||||
.execute();
|
||||
}
|
||||
|
||||
async findWattingAndDownloadingVideos() {
|
||||
return await this.dataService.appDataSource.getRepository(Video).find({
|
||||
where: {
|
||||
status: In([DownloadStatus.Downloading, DownloadStatus.Watting]),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async deleteDownloadItem(id: number) {
|
||||
return await this.dataService.appDataSource.getRepository(Video).delete(id);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
import {
|
||||
BrowserWindow,
|
||||
BrowserWindowConstructorOptions,
|
||||
Event,
|
||||
} from "electron";
|
||||
import isDev from "electron-is-dev";
|
||||
import { inject, injectable } from "inversify";
|
||||
import { resolve } from "path";
|
||||
import { TYPES } from "../types";
|
||||
import {
|
||||
BrowserWindowService,
|
||||
LoggerService,
|
||||
StoreService,
|
||||
} from "../interfaces";
|
||||
|
||||
@injectable()
|
||||
export default class BrowserWindowServiceImpl
|
||||
extends BrowserWindow
|
||||
implements BrowserWindowService
|
||||
{
|
||||
private ready = false;
|
||||
|
||||
constructor(
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
@inject(TYPES.StoreService)
|
||||
private readonly storeService: StoreService
|
||||
) {
|
||||
const options: BrowserWindowConstructorOptions = {
|
||||
width: 1100,
|
||||
minWidth: 1100,
|
||||
height: 680,
|
||||
minHeight: 680,
|
||||
show: false,
|
||||
frame: true,
|
||||
webPreferences: {
|
||||
preload: resolve(__dirname, "./preload.js"),
|
||||
},
|
||||
};
|
||||
super(options);
|
||||
}
|
||||
|
||||
init(): void {
|
||||
const url = isDev
|
||||
? "http://localhost:8555/browser"
|
||||
: "mediago://index.html/browser";
|
||||
void this.loadURL(url);
|
||||
|
||||
this.once("ready-to-show", this.readyToShow);
|
||||
this.on("close", (e: Event) => {
|
||||
e.preventDefault();
|
||||
this.hideWindow();
|
||||
});
|
||||
|
||||
this.storeService.onDidChange("openInNewWindow", (newValue) => {
|
||||
// 向所有窗口发送通知
|
||||
if (newValue === false) {
|
||||
this.hideWindow();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
readyToShow = () => {
|
||||
this.ready = true;
|
||||
};
|
||||
|
||||
showWindow = () => {
|
||||
if (!this.ready) {
|
||||
this.logger.error("BrowserWindow is not ready to show.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.show();
|
||||
isDev && this.webContents.openDevTools();
|
||||
};
|
||||
|
||||
hideWindow = () => {
|
||||
this.hide();
|
||||
|
||||
// 关闭开发者工具
|
||||
if (isDev) {
|
||||
this.webContents.closeDevTools();
|
||||
this.getBrowserView()?.webContents.closeDevTools();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import { db } from "../helper/variables";
|
||||
import { inject, injectable } from "inversify";
|
||||
import { DataSource, EntityManager } from "typeorm";
|
||||
import { TYPES } from "../types";
|
||||
import { DatabaseService, LoggerService } from "../interfaces";
|
||||
import { Video } from "../entity/Video";
|
||||
import { Favorite } from "entity/Favorite";
|
||||
|
||||
@injectable()
|
||||
export default class DatabaseServiceImpl implements DatabaseService {
|
||||
appDataSource: DataSource;
|
||||
|
||||
constructor(
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService
|
||||
) {
|
||||
logger.info("数据库地址是: ", db);
|
||||
this.appDataSource = new DataSource({
|
||||
type: "better-sqlite3",
|
||||
database: db,
|
||||
synchronize: true,
|
||||
logging: false,
|
||||
entities: [Video, Favorite],
|
||||
migrations: [],
|
||||
subscribers: [],
|
||||
});
|
||||
}
|
||||
|
||||
async init(): Promise<void> {
|
||||
await this.appDataSource.initialize();
|
||||
}
|
||||
|
||||
get manager(): EntityManager {
|
||||
return this.appDataSource.manager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,401 @@
|
||||
import EventEmitter from "events";
|
||||
import { inject, injectable } from "inversify";
|
||||
import {
|
||||
DownloadParams,
|
||||
DownloadProgress,
|
||||
DownloadStatus,
|
||||
Task,
|
||||
} from "../interfaces.ts";
|
||||
import { TYPES } from "../types.ts";
|
||||
import ElectronLogger from "../vendor/ElectronLogger.ts";
|
||||
import ElectronStore from "../vendor/ElectronStore.ts";
|
||||
import VideoRepository from "../repository/VideoRepository.ts";
|
||||
import {
|
||||
Platform,
|
||||
biliDownloaderBin,
|
||||
m3u8DownloaderBin,
|
||||
} from "../helper/index.ts";
|
||||
import * as pty from "node-pty";
|
||||
import stripAnsi from "strip-ansi";
|
||||
|
||||
interface DownloadContext {
|
||||
// 是否为直播
|
||||
isLive: boolean;
|
||||
// 下载进度
|
||||
percent: string;
|
||||
// 下载速度
|
||||
speed: string;
|
||||
// 是否已经 ready
|
||||
ready: boolean;
|
||||
}
|
||||
|
||||
export interface DownloadOptions {
|
||||
abortSignal: AbortController;
|
||||
encoding?: string;
|
||||
onMessage?: (ctx: DownloadContext, message: string) => void;
|
||||
id: number;
|
||||
}
|
||||
|
||||
interface Schema {
|
||||
args: Record<string, { argsName: string[] | null }>;
|
||||
consoleReg: {
|
||||
percent: string;
|
||||
speed: string;
|
||||
error: string;
|
||||
start: string;
|
||||
isLive: string;
|
||||
};
|
||||
bin: string;
|
||||
platform: string[];
|
||||
type: string;
|
||||
}
|
||||
|
||||
const processList: Schema[] = [
|
||||
{
|
||||
type: "m3u8",
|
||||
platform: [Platform.MacOS, Platform.Linux, Platform.Windows],
|
||||
bin: m3u8DownloaderBin,
|
||||
args: {
|
||||
url: {
|
||||
argsName: null,
|
||||
},
|
||||
localDir: {
|
||||
argsName: ["--tmp-dir", "--save-dir"],
|
||||
},
|
||||
name: {
|
||||
argsName: ["--save-name"],
|
||||
},
|
||||
// headers: {
|
||||
// argsName: ["--headers"],
|
||||
// },
|
||||
deleteSegments: {
|
||||
argsName: ["--del-after-done"],
|
||||
},
|
||||
proxy: {
|
||||
argsName: ["--custom-proxy"],
|
||||
},
|
||||
},
|
||||
consoleReg: {
|
||||
percent: "([\\d.]+)%",
|
||||
speed: "([\\d.]+[GMK]Bps)",
|
||||
error: "ERROR",
|
||||
start: "保存文件名:",
|
||||
isLive: "检测到直播流",
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "bilibili",
|
||||
platform: [Platform.Linux, Platform.MacOS, Platform.Windows],
|
||||
bin: biliDownloaderBin,
|
||||
args: {
|
||||
url: {
|
||||
argsName: null,
|
||||
},
|
||||
localDir: {
|
||||
argsName: ["--work-dir"],
|
||||
},
|
||||
},
|
||||
consoleReg: {
|
||||
speed: "([\\d.]+\\s[GMK]B/s)",
|
||||
percent: "([\\d.]+)%",
|
||||
error: "ERROR",
|
||||
start: "开始下载",
|
||||
isLive: "检测到直播流",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@injectable()
|
||||
export default class DownloadService extends EventEmitter {
|
||||
private queue: Task[] = [];
|
||||
|
||||
private active: Task[] = [];
|
||||
|
||||
private limit: number;
|
||||
|
||||
private signal: Record<number, AbortController> = {};
|
||||
|
||||
constructor(
|
||||
@inject(TYPES.ElectronLogger)
|
||||
private readonly logger: ElectronLogger,
|
||||
@inject(TYPES.VideoRepository)
|
||||
private readonly videoRepository: VideoRepository,
|
||||
@inject(TYPES.ElectronStore)
|
||||
private readonly storeService: ElectronStore,
|
||||
) {
|
||||
super();
|
||||
|
||||
const maxRunner = this.storeService.get("maxRunner");
|
||||
this.limit = maxRunner;
|
||||
|
||||
this.storeService.onDidChange("maxRunner", (maxRunner) => {
|
||||
maxRunner && (this.limit = maxRunner);
|
||||
});
|
||||
}
|
||||
|
||||
async addTask(task: Task) {
|
||||
this.queue.push(task);
|
||||
this.runTask();
|
||||
}
|
||||
|
||||
async stopTask(id: number) {
|
||||
if (this.signal[id]) {
|
||||
this.signal[id].abort();
|
||||
}
|
||||
}
|
||||
|
||||
async execute(task: Task) {
|
||||
try {
|
||||
await this.videoRepository.changeVideoStatus(
|
||||
task.id,
|
||||
DownloadStatus.Downloading,
|
||||
);
|
||||
this.emit("download-start", task.id);
|
||||
|
||||
this.logger.info(`taskId: ${task.id} start`);
|
||||
const controller = new AbortController();
|
||||
this.signal[task.id] = controller;
|
||||
|
||||
const callback = (progress: DownloadProgress) => {
|
||||
if (progress.type === "progress") {
|
||||
this.emit("download-progress", progress);
|
||||
} else if (progress.type === "ready") {
|
||||
this.emit("download-ready-start", progress);
|
||||
if (progress.isLive) {
|
||||
this.removeTask(progress.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const params: DownloadParams = {
|
||||
...task.params,
|
||||
id: task.id,
|
||||
abortSignal: controller,
|
||||
callback,
|
||||
};
|
||||
|
||||
const { proxy, useProxy } = this.storeService.store;
|
||||
if (useProxy) {
|
||||
params.proxy = proxy;
|
||||
}
|
||||
|
||||
await this.process(params);
|
||||
delete this.signal[task.id];
|
||||
this.logger.info(`taskId: ${task.id} success`);
|
||||
|
||||
await this.videoRepository.changeVideoStatus(
|
||||
task.id,
|
||||
DownloadStatus.Success,
|
||||
);
|
||||
this.emit("download-success", task.id);
|
||||
} catch (err: any) {
|
||||
if (err.message === "AbortError") {
|
||||
this.logger.info(`taskId: ${task.id} stopped`);
|
||||
// 下载暂停
|
||||
await this.videoRepository.changeVideoStatus(
|
||||
task.id,
|
||||
DownloadStatus.Stopped,
|
||||
);
|
||||
this.emit("download-stop", task.id);
|
||||
} else {
|
||||
this.logger.info(`taskId: ${task.id} failed`);
|
||||
// 下载失败
|
||||
await this.videoRepository.changeVideoStatus(
|
||||
task.id,
|
||||
DownloadStatus.Failed,
|
||||
);
|
||||
this.emit("download-failed", task.id, err);
|
||||
}
|
||||
} finally {
|
||||
this.removeTask(task.id);
|
||||
|
||||
// 传输完成
|
||||
if (this.queue.length === 0 && this.active.length === 0) {
|
||||
// this.emit("download-finish");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removeTask(id: number) {
|
||||
// 处理当前正在活动的任务
|
||||
const doneId = this.active.findIndex((i) => i.id === id);
|
||||
this.active.splice(doneId, 1);
|
||||
// 处理完成的任务
|
||||
if (this.active.length < this.limit) {
|
||||
this.runTask();
|
||||
}
|
||||
}
|
||||
|
||||
runTask() {
|
||||
while (this.active.length < this.limit && this.queue.length > 0) {
|
||||
const task = this.queue.shift();
|
||||
if (task) {
|
||||
this.active.push(task);
|
||||
this.execute(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _execa(
|
||||
binPath: string,
|
||||
args: string[],
|
||||
params: DownloadOptions,
|
||||
): Promise<void> {
|
||||
const { abortSignal, onMessage, id } = params;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const ptyProcess = pty.spawn(binPath, args, {
|
||||
name: "xterm-color",
|
||||
cols: 500,
|
||||
rows: 500,
|
||||
useConpty: false,
|
||||
});
|
||||
|
||||
if (onMessage) {
|
||||
const ctx: DownloadContext = {
|
||||
ready: false,
|
||||
isLive: false,
|
||||
percent: "",
|
||||
speed: "",
|
||||
};
|
||||
ptyProcess.onData((data) => {
|
||||
try {
|
||||
this.emit("download-message", id, data);
|
||||
onMessage(ctx, stripAnsi(data));
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
abortSignal.signal.addEventListener("abort", () => {
|
||||
ptyProcess.kill();
|
||||
reject(new Error("AbortError"));
|
||||
});
|
||||
|
||||
ptyProcess.onExit(({ exitCode }) => {
|
||||
if (exitCode === 0) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error("未知错误"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async downloader(params: DownloadParams, schema: Schema): Promise<void> {
|
||||
const {
|
||||
id,
|
||||
abortSignal,
|
||||
url,
|
||||
local,
|
||||
name,
|
||||
deleteSegments,
|
||||
headers,
|
||||
callback,
|
||||
proxy,
|
||||
} = params;
|
||||
|
||||
const spawnParams = [];
|
||||
for (const key of Object.keys(schema.args)) {
|
||||
const { argsName } = schema.args[key];
|
||||
if (key === "url") {
|
||||
argsName && spawnParams.push(...argsName);
|
||||
spawnParams.push(url);
|
||||
}
|
||||
if (key === "localDir") {
|
||||
argsName && argsName.forEach((i) => spawnParams.push(i, local));
|
||||
}
|
||||
if (key === "name") {
|
||||
argsName && argsName.forEach((i) => spawnParams.push(i, name));
|
||||
}
|
||||
|
||||
if (key === "headers") {
|
||||
if (headers) {
|
||||
const h: Record<string, unknown> = JSON.parse(headers);
|
||||
Object.entries(h).forEach(([k, v]) => {
|
||||
spawnParams.push("--header", `${k}: ${v}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (key === "deleteSegments" && deleteSegments) {
|
||||
argsName && spawnParams.push(...argsName);
|
||||
}
|
||||
|
||||
if (key === "proxy" && proxy) {
|
||||
argsName && argsName.forEach((i) => spawnParams.push(i, proxy));
|
||||
}
|
||||
}
|
||||
|
||||
const { consoleReg } = schema;
|
||||
const isLiveReg = RegExp(consoleReg.isLive, "g");
|
||||
const startDownloadReg = RegExp(consoleReg.start, "g");
|
||||
const errorReg = RegExp(consoleReg.error, "g");
|
||||
const speedReg = RegExp(consoleReg.speed, "g");
|
||||
const percentReg = RegExp(consoleReg.percent, "g");
|
||||
|
||||
const onMessage = (ctx: DownloadContext, message: string) => {
|
||||
// 解析是否为直播资源
|
||||
if (isLiveReg.test(message)) {
|
||||
ctx.isLive = true;
|
||||
}
|
||||
// 解析下载进度
|
||||
const [, percent] = percentReg.exec(message) || [];
|
||||
if (percent && Number(ctx.percent || 0) < Number(percent)) {
|
||||
ctx.percent = percent;
|
||||
}
|
||||
// 解析下载速度
|
||||
const [, speed] = speedReg.exec(message) || [];
|
||||
if (speed) {
|
||||
ctx.speed = speed;
|
||||
}
|
||||
|
||||
if (startDownloadReg.test(message)) {
|
||||
callback({
|
||||
id,
|
||||
type: "ready",
|
||||
isLive: ctx.isLive,
|
||||
speed: "",
|
||||
percent: "",
|
||||
});
|
||||
ctx.ready = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (errorReg.test(message)) {
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
if (ctx.ready && (ctx.percent || ctx.speed)) {
|
||||
callback({
|
||||
id,
|
||||
type: "progress",
|
||||
percent: ctx.percent || "",
|
||||
speed: ctx.speed || "",
|
||||
isLive: ctx.isLive,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.logger.debug("download params: ", spawnParams.join(" "));
|
||||
await this._execa(schema.bin, spawnParams, {
|
||||
id,
|
||||
abortSignal,
|
||||
onMessage,
|
||||
});
|
||||
}
|
||||
|
||||
async process(params: DownloadParams): Promise<void> {
|
||||
const program = processList
|
||||
.filter((i) => i.platform.includes(process.platform))
|
||||
.filter((i) => i.type === params.type);
|
||||
|
||||
if (program.length === 0) {
|
||||
return Promise.reject(new Error("不支持的下载类型"));
|
||||
}
|
||||
|
||||
const schema = program[0];
|
||||
await this.downloader(params, schema);
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
import EventEmitter from "events";
|
||||
import { inject, injectable } from "inversify";
|
||||
import {
|
||||
DownloadService,
|
||||
DownloadStatus,
|
||||
Task,
|
||||
VideoRepository,
|
||||
} from "../interfaces";
|
||||
import { TYPES } from "../types";
|
||||
import LoggerServiceImpl from "./LoggerServiceImpl";
|
||||
|
||||
@injectable()
|
||||
export default class DownloadServiceImpl
|
||||
extends EventEmitter
|
||||
implements DownloadService
|
||||
{
|
||||
private queue: Task[] = [];
|
||||
|
||||
private active: Task[] = [];
|
||||
|
||||
private limit = 2;
|
||||
|
||||
private debug = process.env.DOWNLOAD_DEBUG;
|
||||
|
||||
private signal: Record<number, AbortController> = {};
|
||||
|
||||
constructor(
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerServiceImpl,
|
||||
@inject(TYPES.VideoRepository)
|
||||
private readonly videoRepository: VideoRepository
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async addTask(task: Task) {
|
||||
this.queue.push(task);
|
||||
this.runTask();
|
||||
}
|
||||
|
||||
async stopTask(id: number) {
|
||||
if (this.signal[id]) {
|
||||
this.log(`taskId: ${id} stop`);
|
||||
this.signal[id].abort();
|
||||
}
|
||||
}
|
||||
|
||||
async execute(task: Task) {
|
||||
try {
|
||||
await this.videoRepository.changeVideoStatus(
|
||||
task.id,
|
||||
DownloadStatus.Downloading
|
||||
);
|
||||
this.emit("download-start", task.id);
|
||||
|
||||
this.log(`taskId: ${task.id} start`);
|
||||
const controller = new AbortController();
|
||||
this.signal[task.id] = controller;
|
||||
await task.process({
|
||||
...task.params,
|
||||
id: task.id,
|
||||
abortSignal: controller,
|
||||
});
|
||||
delete this.signal[task.id];
|
||||
this.log(`taskId: ${task.id} success`);
|
||||
|
||||
await this.videoRepository.changeVideoStatus(
|
||||
task.id,
|
||||
DownloadStatus.Success
|
||||
);
|
||||
this.emit("download-success", task.id);
|
||||
} catch (err: any) {
|
||||
this.log(`taskId: ${task.id} failed`);
|
||||
if (err.name === "AbortError") {
|
||||
// 下载暂停
|
||||
await this.videoRepository.changeVideoStatus(
|
||||
task.id,
|
||||
DownloadStatus.Stopped
|
||||
);
|
||||
this.emit("download-stop", task.id);
|
||||
} else {
|
||||
// 下载失败
|
||||
await this.videoRepository.changeVideoStatus(
|
||||
task.id,
|
||||
DownloadStatus.Failed
|
||||
);
|
||||
this.emit("download-failed", task.id, err);
|
||||
}
|
||||
} finally {
|
||||
// 处理当前正在活动的任务
|
||||
const doneId = this.active.findIndex((i) => i.id === task.id);
|
||||
this.active.splice(doneId, 1);
|
||||
// 处理完成的任务
|
||||
this.runTask();
|
||||
// 传输完成
|
||||
if (this.queue.length === 0 && this.active.length === 0) {
|
||||
// this.emit("download-finish");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runTask() {
|
||||
while (this.active.length < this.limit && this.queue.length > 0) {
|
||||
const task = this.queue.shift();
|
||||
if (task) {
|
||||
this.active.push(task);
|
||||
this.execute(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log(...args: any[]) {
|
||||
if (this.debug) {
|
||||
this.logger.info(`[DownloadService] `, ...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
import { ipcMain } from "electron";
|
||||
import { inject, injectable, multiInject } from "inversify";
|
||||
import { Controller, IpcHandlerService, LoggerService } from "../interfaces";
|
||||
import { TYPES } from "../types";
|
||||
|
||||
@injectable()
|
||||
export default class IpcHandlerServiceImpl implements IpcHandlerService {
|
||||
constructor(
|
||||
@multiInject(TYPES.Controller)
|
||||
private readonly controllers: Controller[],
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService
|
||||
) {}
|
||||
|
||||
private registerIpc(controller: Controller, property: string | symbol): void {
|
||||
const fun = controller[property];
|
||||
const channel: string = Reflect.getMetadata(
|
||||
"ipc-channel",
|
||||
controller,
|
||||
property
|
||||
);
|
||||
const method: "on" | "handle" = Reflect.getMetadata(
|
||||
"ipc-method",
|
||||
controller,
|
||||
property
|
||||
);
|
||||
if (typeof fun === "function" && method && channel) {
|
||||
ipcMain[method](channel, async (...args: any[]) => {
|
||||
try {
|
||||
const handler = fun.bind(controller);
|
||||
let res = handler(...args);
|
||||
if (res.then) {
|
||||
res = await res;
|
||||
}
|
||||
return this.success(res);
|
||||
} catch (e: any) {
|
||||
this.logger.error("处理 ipc 事件时异常: ", e);
|
||||
if (e instanceof Error) {
|
||||
return this.error(e.message);
|
||||
} else if (typeof e === "string") {
|
||||
return this.error(e);
|
||||
} else {
|
||||
return this.error(String(e));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
success(data: any) {
|
||||
return {
|
||||
code: 0,
|
||||
message: "success",
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
error(message = "fail") {
|
||||
return {
|
||||
code: -1,
|
||||
message,
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
private bindIpcMethods(controller: Controller): void {
|
||||
const Class = Object.getPrototypeOf(controller);
|
||||
Object.getOwnPropertyNames(Class).forEach((property) =>
|
||||
this.registerIpc(controller, property as never)
|
||||
);
|
||||
}
|
||||
|
||||
init(): void {
|
||||
this.controllers.forEach((controller) => this.bindIpcMethods(controller));
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
import {
|
||||
BrowserWindow,
|
||||
BrowserWindowConstructorOptions,
|
||||
Menu,
|
||||
Notification,
|
||||
} from "electron";
|
||||
import isDev from "electron-is-dev";
|
||||
import { inject, injectable } from "inversify";
|
||||
import { resolve } from "path";
|
||||
import { TYPES } from "../types";
|
||||
import {
|
||||
DownloadProgress,
|
||||
DownloadService,
|
||||
LoggerService,
|
||||
MainWindowService,
|
||||
StoreService,
|
||||
VideoRepository,
|
||||
} from "../interfaces";
|
||||
import { event } from "helper/utils";
|
||||
|
||||
@injectable()
|
||||
export default class MainWindowServiceImpl
|
||||
extends BrowserWindow
|
||||
implements MainWindowService
|
||||
{
|
||||
constructor(
|
||||
@inject(TYPES.LoggerService)
|
||||
private readonly logger: LoggerService,
|
||||
@inject(TYPES.DownloadService)
|
||||
private readonly downloadService: DownloadService,
|
||||
@inject(TYPES.VideoRepository)
|
||||
private readonly videoRepository: VideoRepository,
|
||||
@inject(TYPES.StoreService)
|
||||
private readonly storeService: StoreService
|
||||
) {
|
||||
const options: BrowserWindowConstructorOptions = {
|
||||
width: 1100,
|
||||
minWidth: 1100,
|
||||
height: 680,
|
||||
minHeight: 680,
|
||||
show: false,
|
||||
frame: true,
|
||||
webPreferences: {
|
||||
preload: resolve(__dirname, "./preload.js"),
|
||||
},
|
||||
};
|
||||
super(options);
|
||||
}
|
||||
|
||||
init(): void {
|
||||
Menu.setApplicationMenu(null);
|
||||
|
||||
const url = isDev ? "http://localhost:8555/" : "mediago://index.html/";
|
||||
void this.loadURL(url);
|
||||
|
||||
this.once("ready-to-show", this.readyToShow);
|
||||
event.on("download-progress", this.onDownloadProgress);
|
||||
this.downloadService.on("download-success", this.onDownloadSuccess);
|
||||
this.downloadService.on("download-failed", this.onDownloadFailed);
|
||||
this.downloadService.on("download-start", this.onDownloadStart);
|
||||
this.downloadService.on("download-stop", this.onDownloadStart);
|
||||
|
||||
this.storeService.onDidAnyChange((store) => {
|
||||
// 向所有窗口发送通知
|
||||
this.webContents.send("store-change", store);
|
||||
});
|
||||
}
|
||||
|
||||
readyToShow = () => {
|
||||
this.show();
|
||||
isDev && this.webContents.openDevTools();
|
||||
};
|
||||
|
||||
onDownloadProgress = (progress: DownloadProgress) => {
|
||||
this.webContents.send("download-progress", progress);
|
||||
};
|
||||
|
||||
onDownloadSuccess = async (id: number) => {
|
||||
const promptTone = this.storeService.get("promptTone");
|
||||
if (promptTone) {
|
||||
const video = await this.videoRepository.findVideo(id);
|
||||
|
||||
new Notification({
|
||||
title: "下载成功",
|
||||
body: `${video?.name} 下载成功`,
|
||||
}).show();
|
||||
}
|
||||
|
||||
this.webContents.send("download-success", id);
|
||||
};
|
||||
|
||||
onDownloadFailed = async (id: number, err: any) => {
|
||||
const promptTone = this.storeService.get("promptTone");
|
||||
if (promptTone) {
|
||||
const video = await this.videoRepository.findVideo(id);
|
||||
|
||||
new Notification({
|
||||
title: "下载失败",
|
||||
body: `${video?.name} 下载失败`,
|
||||
}).show();
|
||||
}
|
||||
this.logger.error("下载失败:", err);
|
||||
this.webContents.send("download-failed", id);
|
||||
};
|
||||
|
||||
onDownloadStart = async (id: number) => {
|
||||
this.webContents.send("download-start", id);
|
||||
};
|
||||
|
||||
onDownloadStop = async (id: number) => {
|
||||
this.webContents.send("download-stop", id);
|
||||
};
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
import { protocol } from "electron";
|
||||
import isDev from "electron-is-dev";
|
||||
import { pathExists, readFile } from "fs-extra";
|
||||
import { injectable } from "inversify";
|
||||
import { extname, join } from "path";
|
||||
import { URL } from "url";
|
||||
import { defaultScheme } from "../helper/variables";
|
||||
import { ProtocolService } from "../interfaces";
|
||||
|
||||
@injectable()
|
||||
export default class ProtocolServiceImpl implements ProtocolService {
|
||||
create(): void {
|
||||
if (isDev) return;
|
||||
|
||||
protocol.registerBufferProtocol(
|
||||
defaultScheme,
|
||||
async (request, callback) => {
|
||||
let pathName = new URL(request.url).pathname;
|
||||
pathName = decodeURI(pathName);
|
||||
|
||||
const filePath = join(__dirname, "../renderer", pathName);
|
||||
const fileExist = await pathExists(filePath);
|
||||
|
||||
if (fileExist) {
|
||||
const data = await readFile(filePath);
|
||||
const extension = extname(pathName).toLowerCase();
|
||||
let mimeType = "";
|
||||
|
||||
if (extension === ".js") {
|
||||
mimeType = "text/javascript";
|
||||
} else if (extension === ".html") {
|
||||
mimeType = "text/html";
|
||||
} else if (extension === ".css") {
|
||||
mimeType = "text/css";
|
||||
} else if (extension === ".svg" || extension === ".svgz") {
|
||||
mimeType = "image/svg+xml";
|
||||
} else if (extension === ".json") {
|
||||
mimeType = "application/json";
|
||||
}
|
||||
|
||||
callback({ mimeType, data });
|
||||
} else {
|
||||
// 如果没有找到文件,直接返回 index.html , react history 模式
|
||||
const filePath = join(__dirname, "../renderer/index.html");
|
||||
const data = await readFile(filePath);
|
||||
callback({ mimeType: "text/html", data });
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
import { inject, injectable } from "inversify";
|
||||
import { DownloadType } from "../interfaces.ts";
|
||||
import { TYPES } from "../types.ts";
|
||||
import ElectronLogger from "../vendor/ElectronLogger.ts";
|
||||
import EventEmitter from "events";
|
||||
import { OnSendHeadersListenerDetails, session } from "electron";
|
||||
import { PERSIST_WEBVIEW, formatHeaders } from "../helper/index.ts";
|
||||
|
||||
export interface SourceParams {
|
||||
url: string;
|
||||
documentURL: string;
|
||||
name: string;
|
||||
type: DownloadType;
|
||||
headers?: string;
|
||||
}
|
||||
|
||||
export interface SourceFilter {
|
||||
hosts?: RegExp[];
|
||||
matches?: RegExp[];
|
||||
type: DownloadType;
|
||||
schema?: Record<string, string>;
|
||||
}
|
||||
|
||||
interface PageInfo {
|
||||
title: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
const filterList: SourceFilter[] = [
|
||||
{
|
||||
matches: [/\.m3u8/],
|
||||
type: DownloadType.m3u8,
|
||||
},
|
||||
{
|
||||
// TODO: 合集、列表、收藏夹
|
||||
hosts: [/^https?:\/\/(www\.)?bilibili.com\/video/],
|
||||
type: DownloadType.bilibili,
|
||||
schema: {
|
||||
name: "title",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@injectable()
|
||||
export class SniffingHelper extends EventEmitter {
|
||||
private pageInfo: PageInfo = { title: "", url: "" };
|
||||
private ready = false;
|
||||
private queue: SourceParams[] = [];
|
||||
|
||||
constructor(
|
||||
@inject(TYPES.ElectronLogger)
|
||||
private readonly logger: ElectronLogger
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
pluginReady() {
|
||||
this.ready = true;
|
||||
this.queue.forEach((item) => {
|
||||
this.emit("source", item);
|
||||
});
|
||||
}
|
||||
|
||||
reset(pageInfo: PageInfo) {
|
||||
this.pageInfo = pageInfo;
|
||||
this.ready = false;
|
||||
this.queue = [];
|
||||
|
||||
listLoop: for (const filter of filterList) {
|
||||
if (filter.hosts) {
|
||||
for (const host of filter.hosts) {
|
||||
if (!host.test(pageInfo.url)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.send({
|
||||
url: pageInfo.url,
|
||||
documentURL: pageInfo.url,
|
||||
name: pageInfo.title,
|
||||
type: filter.type,
|
||||
});
|
||||
break listLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
start() {
|
||||
const viewSession = session.fromPartition(PERSIST_WEBVIEW);
|
||||
viewSession.webRequest.onSendHeaders(this.onSendHeaders);
|
||||
}
|
||||
|
||||
send = (item: SourceParams) => {
|
||||
this.logger.info(`在窗口中捕获视频链接: ${item.url}`);
|
||||
// 等待 DOM 中浮窗加载完成
|
||||
if (this.ready) {
|
||||
this.emit("source", item);
|
||||
} else {
|
||||
this.queue.push(item);
|
||||
}
|
||||
};
|
||||
|
||||
private onSendHeaders = (details: OnSendHeadersListenerDetails): void => {
|
||||
const { url, requestHeaders } = details;
|
||||
const { title, url: documentURL } = this.pageInfo;
|
||||
|
||||
listLoop: for (const filter of filterList) {
|
||||
if (filter.matches) {
|
||||
for (const match of filter.matches) {
|
||||
const u = new URL(url);
|
||||
if (!match.test(u.pathname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.send({
|
||||
url,
|
||||
documentURL,
|
||||
name: title,
|
||||
type: filter.type,
|
||||
headers: formatHeaders(requestHeaders),
|
||||
});
|
||||
break listLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||