Skip to content

Commit

Permalink
Merge pull request #90 from putyy/dev
Browse files Browse the repository at this point in the history
完善资源类型、优化资源类型选择、优化table固定表头等
  • Loading branch information
putyy authored Oct 15, 2024
2 parents 7584156 + 5e63624 commit 1cae714
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 200 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## res-downloader(爱享素材下载器) 【[加入群聊](https://qm.qq.com/q/mfDMSpCxQ4)
## res-downloader
### 爱享素材下载器【[加入群聊](https://qm.qq.com/q/mfDMSpCxQ4)
🎯 基于 [electron-vite-vue](https://github.com/electron-vite/electron-vite-vue.git)
📦 操作简单、可获取不同类型的资源
🖥️ 支持Win10、Win11、Mac
🌐 支持视频、音频、图片、m3u8等网络资源下载
🖥️ 支持Win10、Win11、Mac、Linux
🌐 支持视频、音频、图片、m3u8、直播流等常见网络资源拦截
💪 支持微信视频号、小程序、抖音、快手、小红书、酷狗音乐、qq音乐等网络资源下载
👼 支持设置代理以获取特殊网络下的资源

Expand All @@ -21,7 +22,7 @@
![](public/show.webp)

## 常见问题
下载慢、大视频下载失败
下载慢、大视频下载失败(最新版本以内置aria2下载器)
> 推荐使用如下工具加速下载,视频号可以下载完成后再到对应视频操作项选择 “视频解密(视频号)” 按钮
>> [Neat Download Manager](https://www.neatdownloadmanager.com/index.php/en/)[Motrix](https://motrix.app/download)等软件进行下载
Expand All @@ -39,7 +40,8 @@ Win7无法使用
>> MAC: /Users/你的用户名称/.res-downloader@putyy/res-downloader-installed.lock
>> Win: C:\Users\Admin\.res-downloader@putyy/res-downloader-installed.lock
其他问题请留言 https://github.com/putyy/res-downloader/issues
其他问题
[github](https://github.com/putyy/res-downloader/issues)[爱享论坛](https://s.gowas.cn/d/4089)

## 二次开发
> ps: 打包慢的问题可以参考 https://www.putyy.com/articles/87
Expand All @@ -59,5 +61,8 @@ yarn run build --universal --mac
yarn run build --win
```

## 实现&初衷
通过代理网络抓包拦截响应,筛选出有用的资源, 同fiddler、charles等抓包软件、浏览器F12打开控制也能达到目的,只不过这些软件需要手动进行筛选,对于小白用户上手还是有点难度,本软件对部分资源做了特殊处理,更适合大众用户,所以就有了本项目。

## 免责声明
本软件用于学习研究使用,若因使用本软件造成的一切法律责任均与本人无关!
2 changes: 2 additions & 0 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ function createPreviewWindow(parent: BrowserWindow) {
parent: parent,
width: 600,
height: 400,
minWidth: 600,
minHeight: 400,
show: false,
// paintWhenInitiallyHidden: false,
webPreferences: {
Expand Down
16 changes: 13 additions & 3 deletions electron/main/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {ipcMain, dialog, BrowserWindow, app, shell} from 'electron'
import {startServer} from './proxyServer'
import {installCert, checkCertInstalled} from './cert'
import {decodeWxFile, suffix, getCurrentDateTimeFormatted} from './utils'
import {decodeWxFile, typeSuffix, getCurrentDateTimeFormatted} from './utils'
// @ts-ignore
import {hexMD5} from '../../src/common/md5'
import {Aria2RPC} from './aria2Rpc'
import fs from "fs"
import urlTool from "url";

let win: BrowserWindow
let previewWin: BrowserWindow
Expand Down Expand Up @@ -71,7 +72,16 @@ export default function initIPC() {
resolve(false);
});
}
if (quality !== "-1" && data.decode_key && data.file_format) {
if(quality === "0" && data.decode_key){
const urlInfo = urlTool.parse(down_url, true);
console.log('urlInfo', urlInfo)
if (urlInfo.query["token"] && urlInfo.query["encfilekey"]) {
down_url = urlInfo.protocol + "//" + urlInfo.hostname + urlInfo.pathname.replace("251/20302", "251/20304") +
"?encfilekey=" + urlInfo.query["encfilekey"] +
"&token=" + urlInfo.query["token"]
console.log("down_url:", down_url)
}
} else if (quality !== "-1" && data.decode_key && data.file_format) {
const format = data.file_format.split('#');
const qualityMap = [
format[0],
Expand All @@ -81,7 +91,7 @@ export default function initIPC() {
down_url += "&X-snsvideoflag=" + qualityMap[quality];
}
let fileName = data?.description ? data.description.replace(/[^a-zA-Z0-9\u4e00-\u9fa5]/g, '') : hexMD5(down_url);
fileName = fileName + "_" + getCurrentDateTimeFormatted() + suffix(data.type)
fileName = fileName + "_" + getCurrentDateTimeFormatted() + typeSuffix(data.type)[1]
let save_path_file = `${save_path}/${fileName}`
if (process.platform === 'win32') {
save_path_file = `${save_path}\\${fileName}`
Expand Down
91 changes: 14 additions & 77 deletions electron/main/proxyServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import log from 'electron-log'
import CONFIG from './const'
import {setProxy} from './setProxy'
import * as urlTool from "url"
import {toSize} from "./utils"
import {toSize, typeSuffix} from "./utils"
// @ts-ignore
import {hexMD5} from '../../src/common/md5'
import pkg from '../../package.json'
Expand Down Expand Up @@ -146,87 +146,24 @@ export async function startServer({win, upstreamProxy, setProxyErrorCallback = f
async (req, res) => {
try {
// 拦截响应
const ctype = res?._data?.headers?.['content-type']
const url_sign: string = hexMD5(req.fullUrl())
const res_url = req.fullUrl()
const urlInfo = urlTool.parse(res_url, true)
switch (ctype) {
case "video/mp4":
case "video/webm":
case "video/ogg":
case "video/x-msvideo":
case "video/mpeg":
case "video/quicktime":
case "video/x-ms-wmv":
case "video/x-flv":
case "video/3gpp":
case "video/x-matroska":
if (global.videoList.hasOwnProperty(url_sign) === false) {
global.videoList[url_sign] = res_url
win.webContents.send('on_get_queue', Object.assign({}, resObject, {
url: res_url,
url_sign: url_sign,
platform: urlInfo.hostname,
size: toSize(res?._data?.headers?.['content-length'] ?? 0),
type: ctype,
type_str: 'video',
}))
}
break;
case "image/png":
case "image/webp":
case "image/jpeg":
case "image/jpg":
case "image/svg+xml":
case "image/gif":
case "image/avif":
case "image/bmp":
case "image/tiff":
case "image/x-icon":
case "image/heic":
case "image/vnd.adobe.photoshop":
const contentType = res?._data?.headers?.['content-type']
const [resType, suffix] = typeSuffix(contentType)
if (resType) {
const url_sign: string = hexMD5(req.fullUrl())
const res_url = req.fullUrl()
const urlInfo = urlTool.parse(res_url, true)
const contentLength = res?._data?.headers?.['content-length']
if (global.videoList.hasOwnProperty(url_sign) === false) {
global.videoList[url_sign] = res_url
win.webContents.send('on_get_queue', Object.assign({}, resObject, {
url: res_url,
url_sign: url_sign,
platform: urlInfo.hostname,
size: res?._data?.headers?.['content-length'] ? toSize(res?._data?.headers?.['content-length']) : 0,
type: ctype,
type_str: 'image',
size: toSize(contentLength ? contentLength : 0),
type: contentType,
type_str: resType,
}))
break
case "audio/mpeg":
case "audio/wav":
case "audio/aiff":
case "audio/x-aiff":
case "audio/aac":
case "audio/ogg":
case "audio/flac":
case "audio/midi":
case "audio/x-midi":
case "audio/x-ms-wma":
case "audio/opus":
case "audio/webm":
case "audio/mp4":
win.webContents.send('on_get_queue', Object.assign({}, resObject, {
url: res_url,
url_sign: url_sign,
platform: urlInfo.hostname,
size: res?._data?.headers?.['content-length'] ? toSize(res?._data?.headers?.['content-length']) : 0,
type: ctype,
type_str: 'audio',
}))
break
case "application/vnd.apple.mpegurl":
case "application/x-mpegURL":
win.webContents.send('on_get_queue', Object.assign({}, resObject, {
url: res_url,
url_sign: url_sign,
platform: urlInfo.hostname,
size: res?._data?.headers?.['content-length'] ? toSize(res?._data?.headers?.['content-length']) : 0,
type: ctype,
type_str: 'm3u8',
}))
break
}
}
} catch (e) {
log.log(e.toString())
Expand Down
40 changes: 27 additions & 13 deletions electron/main/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fs from 'fs'
import {Transform } from 'stream'
import {Transform} from 'stream'
import {getDecryptionArray} from '../wxjs/decrypt.js'

const axios = require('axios')

function xorTransform(decryptionArray) {
let processedBytes = 0;
return new Transform({
Expand Down Expand Up @@ -32,7 +33,7 @@ function downloadFile(url, decodeKey, fullFileName, progressCallback) {
},
}

if (url.includes("douyin")){
if (url.includes("douyin")) {
config.headers['Referer'] = url
}

Expand All @@ -57,7 +58,7 @@ function downloadFile(url, decodeKey, fullFileName, progressCallback) {
});
}),
);
}else{
} else {
data.pipe(
fs.createWriteStream(fullFileName).on('finish', () => {
resolve({
Expand Down Expand Up @@ -97,7 +98,7 @@ function toSize(size: number) {
return size + 'b'
}

function suffix(type: string) {
function typeSuffix(type: string) {
switch (type) {
case "video/mp4":
case "video/webm":
Expand All @@ -106,23 +107,25 @@ function suffix(type: string) {
case "video/mpeg":
case "video/quicktime":
case "video/x-ms-wmv":
case "video/x-flv":
case "video/3gpp":
case "video/x-matroska":
return ".mp4";
return ["video", ".mp4"];
case "audio/video":
case "video/x-flv":
return ["live", ".mp4"];
case "image/png":
case "image/webp":
case "image/jpeg":
case "image/jpg":
case "image/svg+xml":
case "image/gif":
case "image/avif":
case "image/bmp":
case "image/tiff":
case "image/x-icon":
case "image/heic":
case "image/x-icon":
case "image/svg+xml":
case "image/vnd.adobe.photoshop":
return ".png";
return ["image", ".png"];
case "audio/mpeg":
case "audio/wav":
case "audio/aiff":
Expand All @@ -136,12 +139,23 @@ function suffix(type: string) {
case "audio/opus":
case "audio/webm":
case "audio/mp4":
return ".mp3";
return ["audio", ".mp3"];
case "application/vnd.apple.mpegurl":
case "application/x-mpegURL":
return ".m3u8";
return ["m3u8", ".m3u8"];
case "application/pdf":
return ["pdf", ".pdf"];
case "application/vnd.ms-powerpoint":
case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
return ["ppt", ".ppt"];
case "application/vnd.ms-excel":
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
return ["xls", ".xls"];
case "application/msword":
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
return ["doc", ".doc"];
}
return ""
return ["", ""]
}

function getCurrentDateTimeFormatted() {
Expand All @@ -157,4 +171,4 @@ function getCurrentDateTimeFormatted() {
return `${year}${month}${day}${hours}${minutes}${seconds}`;
}

export {downloadFile, toSize, decodeWxFile, suffix, getCurrentDateTimeFormatted}
export {downloadFile, toSize, decodeWxFile, typeSuffix, getCurrentDateTimeFormatted}
48 changes: 6 additions & 42 deletions src/components/layout/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,17 @@
import {ipcRenderer} from 'electron'
import pkg from '../../../package.json'
const v = pkg.version
const jump = (scene: number)=>{
switch (scene) {
case 1:
ipcRenderer.invoke('invoke_open_default_browser', {
url: "https://s.gowas.cn/d/4089-quan-ping-tai-zi-yuan-xia-zai-ruan-jian"
})
break;
case 2:
ipcRenderer.invoke('invoke_open_default_browser', {
url: "https://s.gowas.cn"
})
break;
case 3:
ipcRenderer.invoke('invoke_open_default_browser', {
url: "https://i.gowas.cn"
})
break;
case 4:
ipcRenderer.invoke('invoke_open_default_browser', {
url: "https://s.gowas.cn/d/4089-quan-ping-tai-zi-yuan-xia-zai-ruan-jian"
})
break;
case 5:
ipcRenderer.invoke('invoke_open_default_browser', {
url: "https://www.ais.do/ivi/rr2GaZ"
})
break;
case 6:
ipcRenderer.invoke('invoke_open_default_browser', {
url: "https://github.com/putyy/res-downloader"
})
break;
}
const jump = (url: string)=>{
ipcRenderer.invoke('invoke_open_default_browser', {
url: url
})
}
</script>
<template lang="pug">
div.line
a.item 当前版本: {{v}}
a.item 站长邮箱: [email protected]
a.item(@click="jump(1)") 获取更新
a.item(@click="jump(4)") 问题反馈
div.line
a.item 推荐:
a.item(@click="jump(5)") Ai助手(免费)
a.item(@click="jump(2)") 网盘资源
a.item(@click="jump(3)") 图片无损压缩
a.item(@click="jump(6)") 软件源码
a.item(@click="jump('https://s.gowas.cn/d/4089-quan-ping-tai-zi-yuan-xia-zai-ruan-jian')") 获取更新&问题反馈
a.item(@click="jump('https://github.com/putyy/res-downloader')") 软件源码
</template>

<style lang="less" scoped>
Expand Down
9 changes: 7 additions & 2 deletions src/components/layout/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ el-container
keep-alive(v-if="route.meta.keepAlive")
component(:is="Component")
component(v-else :is="Component")
el-footer
Footer
el-footer
Footer
</template>

<style lang="less" scoped>
Expand All @@ -27,4 +27,9 @@ el-container
.el-main {
text-align: center;
}
.el-footer{
margin: unset !important;
padding: unset !important;
height: auto !important;
}
</style>
Loading

0 comments on commit 1cae714

Please sign in to comment.