feat: support configuring whether to download highest quality video by default

This commit is contained in:
ltaoo committed 2025-11-22 12:52:57 +08:00
1 parent 9cf6b13af4
commit 8c3b95f190
11 files changed
+273 -76

No files matched your search

+2
View File
@@ -1,5 +1,7 @@
.DS_Store
*.exe
*.exe~
dist/
wx_video_download*
config.yaml
+1 -1
View File
@@ -199,7 +199,7 @@ sudo ./wx_video_download_darwin_xxx
![视频下载成功](assets/screenshot2.png)
默认会下载原始视频。点开更多,可以下载其他质量的视频(xWT111、xWT126 等)。
默认会下载下拉菜单中第一个质量视频。点开更多,可以下载其他质量的视频,包括原始视频。
![下载不同质量的视频](assets/screenshot13.png)
<br>
+45 -48
View File
@@ -7,14 +7,15 @@ import (
"net/http"
"os"
"os/signal"
"runtime"
"strconv"
"syscall"
"time"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"wx_channel/config"
"wx_channel/internal/application"
"wx_channel/internal/handler"
"wx_channel/pkg/certificate"
@@ -23,12 +24,13 @@ import (
)
var (
Version string
device string
port int
debug bool
version string
files *application.BizFiles
cert_file_name string
cfg *config.Config
)
var root_cmd = &cobra.Command{
@@ -39,23 +41,29 @@ var root_cmd = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
root_command(RootCommandArg{
Device: device,
Port: port,
Debug: debug,
Device: device,
Port: viper.GetInt("proxy.port"),
Debug: debug,
SetSystemProxy: viper.GetBool("proxy.system"),
cfg: cfg,
})
},
}
func init() {
root_cmd.Flags().StringVar(&device, "dev", "", "代理服务器网络设备")
root_cmd.Flags().IntVar(&port, "port", 2023, "代理服务器端口")
root_cmd.Flags().BoolVar(&debug, "debug", false, "是否开启调试")
root_cmd.PersistentFlags().StringVar(&device, "dev", "", "代理服务器网络设备")
root_cmd.PersistentFlags().IntVar(&port, "port", 2023, "代理服务器端口")
root_cmd.PersistentFlags().BoolVar(&debug, "debug", false, "是否开启调试")
viper.BindPFlag("proxy.port", root_cmd.PersistentFlags().Lookup("port"))
}
func Initialize(app_ver string, cert_file string, file *application.BizFiles) {
version = app_ver
func Initialize(app_ver string, cert_file string, file *application.BizFiles, c *config.Config) {
Version = app_ver
cert_file_name = cert_file
files = file
port = c.Port
cfg = c
}
func Execute() error {
cobra.MousetrapHelpText = ""
@@ -67,33 +75,35 @@ func Register(cmd *cobra.Command) {
}
type RootCommandArg struct {
Device string
Port int
Debug bool
Device string
Port int
Debug bool
SetSystemProxy bool
cfg *config.Config
}
func root_command(args RootCommandArg) {
os_env := runtime.GOOS
signal_chan := make(chan os.Signal, 1)
// Notify the signal channel on SIGINT (Ctrl+C) and SIGTERM
signal.Notify(signal_chan, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-signal_chan
fmt.Printf("\n正在关闭服务...%v\n\n", sig)
arg := proxy.ProxySettings{
Device: args.Device,
Hostname: "127.0.0.1",
Port: strconv.Itoa(args.Port),
}
err := proxy.DisableProxy(arg)
if err != nil {
fmt.Printf("⚠️ 关闭系统代理失败: %v\n", err)
if args.SetSystemProxy {
arg := proxy.ProxySettings{
Device: args.Device,
Hostname: "127.0.0.1",
Port: strconv.Itoa(args.Port),
}
err := proxy.DisableProxy(arg)
if err != nil {
fmt.Printf("⚠️ 关闭系统代理失败: %v\n", err)
}
}
os.Exit(0)
}()
fmt.Printf("\nv" + version)
fmt.Printf("\nv" + Version)
fmt.Printf("\n问题反馈 https://github.com/ltaoo/wx_channels_download/issues\n")
existing, err1 := certificate.CheckHasCertificate(cert_file_name)
if err1 != nil {
@@ -111,21 +121,21 @@ func root_command(args RootCommandArg) {
select {}
}
}
biz := application.NewBiz(version, files)
biz := application.NewBiz(Version, files)
echo, err := echo.NewEcho(files.CertFile, files.PrivateKeyFile)
if err != nil {
fmt.Printf("\nERROR %v\n", err.Error())
fmt.Printf("按 Ctrl+C 退出...\n")
select {}
}
echo.SetHTTPHandler(handler.HandleHttpRequestEcho(biz))
echo.SetHTTPHandler(handler.HandleHttpRequestEcho(biz, args.cfg))
// Sunny.SetPort(args.Port).Start()
go func() {
var buf bytes.Buffer
// 为了不在终端输出 http server 的日志
log.SetOutput(&buf)
server := &http.Server{
Addr: "localhost:" + strconv.Itoa(port),
Addr: "localhost:" + strconv.Itoa(args.Port),
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
echo.ServeHTTP(w, r)
}),
@@ -137,25 +147,7 @@ func root_command(args RootCommandArg) {
}
}()
if os_env == "windows" {
// ok := Sunny.OpenDrive(true)
// if !ok {
// fmt.Printf("\nERROR 启动进程代理失败,检查是否以管理员身份运行\n")
// fmt.Printf("按 Ctrl+C 退出...\n")
// select {}
// }
// Sunny.ProcessAddName("WeChatAppEx.exe")
err = proxy.EnableProxy(proxy.ProxySettings{
Device: args.Device,
Hostname: "127.0.0.1",
Port: strconv.Itoa(args.Port),
})
if err != nil {
fmt.Printf("\nERROR 设置代理失败 %v\n", err.Error())
fmt.Printf("按 Ctrl+C 退出...\n")
select {}
}
} else {
if args.SetSystemProxy {
err = proxy.EnableProxy(proxy.ProxySettings{
Device: args.Device,
Hostname: "127.0.0.1",
@@ -167,7 +159,12 @@ func root_command(args RootCommandArg) {
select {}
}
}
color.Green(fmt.Sprintf("\n\n服务已正确启动,请打开需要下载的视频号页面进行下载"))
fmt.Println("\n\n服务正在运行,按 Ctrl+C 退出...")
proxy_server_url := "http://127.0.0.1:" + strconv.Itoa(args.Port)
color.Green(fmt.Sprintf("\n\n服务已正确启动"))
if !args.SetSystemProxy {
color.Green(fmt.Sprintf("当前未设置系统代理,请通过软件将流量转发至 %v", proxy_server_url))
}
color.Green(fmt.Sprintf("打开需要下载的视频号页面进行下载"))
fmt.Println("\n\n服务运行在 " + proxy_server_url + ",按 Ctrl+C 退出...")
select {}
}
+28
View File
@@ -0,0 +1,28 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var version_cmd = &cobra.Command{
Use: "version",
Short: "查看版本",
Long: "查看当前应用版本",
Run: func(cmd *cobra.Command, args []string) {
command := cmd.Name()
if command != "version" {
return
}
version_command()
},
}
func init() {
root_cmd.AddCommand(version_cmd)
}
func version_command() {
fmt.Println(Version)
}
+37
View File
@@ -0,0 +1,37 @@
package config
import (
"fmt"
"github.com/spf13/viper"
)
type Config struct {
DownloadDefaultHighest bool // 默认下载最高画质
ProxySystem bool // 是否设置系统代理
Port int // 代理端口
}
func LoadConfig() (*Config, error) {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath("./")
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return nil, fmt.Errorf("error reading config file: %w", err)
}
}
viper.SetDefault("download.defaultHighest", false)
viper.SetDefault("proxy.system", true)
viper.SetDefault("proxy.port", 2023)
config := &Config{
DownloadDefaultHighest: viper.GetBool("download.defaultHighest"),
ProxySystem: viper.GetBool("proxy.system"),
Port: viper.GetInt("proxy.port"),
}
return config, nil
}
+12 -1
View File
@@ -8,12 +8,23 @@ require (
github.com/andybalholm/brotli v1.1.1
github.com/fatih/color v1.17.0
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.21.0
)
require (
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.28.0 // indirect
)
+43 -1
View File
@@ -1,25 +1,67 @@
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc=
github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY=
github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU=
github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+18 -6
View File
@@ -211,7 +211,6 @@ async function __wx_channels_handle_click_download__(spec) {
_profile.url = profile.url + "&X-snsvideoflag=" + spec.fileFormat;
filename = filename + "_" + spec.fileFormat;
}
// console.log("__wx_channels_handle_click_download__", url);
__wx_log({
msg: `${filename}
${location.href}
@@ -283,7 +282,11 @@ function __wx_channels_handle_print_download_command() {
var _profile = {
...profile,
};
// console.log("__wx_channels_handle_click_download__", url);
var spec = __wx_channels_config__.defaultHighest ? null : profile.spec[0];
if (spec) {
_profile.url = profile.url + "&X-snsvideoflag=" + spec.fileFormat;
filename = filename + "_" + spec.fileFormat;
}
var command = `download --url "${_profile.url}"`;
if (_profile.key) {
command += ` --key ${_profile.key}`;
@@ -344,9 +347,13 @@ var __wx_channels_store__ = {
var __wx_channels_video_download_btn__ = icon_download1();
__wx_channels_video_download_btn__.onclick = () => {
if (!window.__wx_channels_store__.profile) {
__wx_log({
msg: "没有视频数据",
});
return;
}
__wx_channels_handle_click_download__();
var spec = __wx_channels_config__.defaultHighest ? null : window.__wx_channels_store__.profile.spec[0];
__wx_channels_handle_click_download__(spec);
};
async function __insert_download_btn_to_home_page() {
@@ -377,11 +384,12 @@ async function __insert_download_btn_to_home_page() {
__wx_channels_video_download_btn__.onclick = () => {
if (!window.__wx_channels_store__.profile) {
__wx_log({
msg: '没有视频数据',
msg: "没有视频数据",
});
return;
}
__wx_channels_handle_click_download__();
var spec = __wx_channels_config__.defaultHighest ? null : window.__wx_channels_store__.profile.spec[0];
__wx_channels_handle_click_download__(spec);
};
$parent.appendChild(__wx_channels_video_download_btn__);
__wx_log({
@@ -402,9 +410,13 @@ async function insert_download_btn() {
__wx_channels_video_download_btn__ = icon_download1();
__wx_channels_video_download_btn__.onclick = () => {
if (!window.__wx_channels_store__.profile) {
__wx_log({
msg: "没有视频数据",
});
return;
}
__wx_channels_handle_click_download__();
var spec = __wx_channels_config__.defaultHighest ? null : window.__wx_channels_store__.profile.spec[0];
__wx_channels_handle_click_download__(spec);
};
var relative_node = $elm2.children[$elm2.children.length - 1];
if (!relative_node) {
+4 -2
View File
@@ -7,13 +7,13 @@ import (
"regexp"
"strings"
"wx_channel/config"
"wx_channel/internal/application"
"wx_channel/pkg/echo"
"wx_channel/pkg/util"
)
func HandleHttpRequestEcho(biz *application.Biz) func(conn *echo.EchoConn) {
// biz.Debug = true
func HandleHttpRequestEcho(biz *application.Biz, cfg *config.Config) func(conn *echo.EchoConn) {
return func(conn *echo.EchoConn) {
parsed_url, err := conn.URL()
if err != nil {
@@ -100,6 +100,8 @@ func HandleHttpRequestEcho(biz *application.Biz) func(conn *echo.EchoConn) {
script_reg2 := regexp.MustCompile(`href="([^"]{1,})\.js"`)
html = script_reg2.ReplaceAllString(html, `href="$1.js`+v+`"`)
inserted_scripts := fmt.Sprintf(`<script>%s</script>`, biz.Files.JSUtils)
script_config := fmt.Sprintf(`<script>var __wx_channels_config__ = {"defaultHighest":%t};</script>`, cfg.DownloadDefaultHighest)
inserted_scripts += script_config
if biz.Debug {
/** 全局错误捕获 */
script_error := fmt.Sprintf(`<script>%s</script>`, biz.Files.JSError)
+68 -2
View File
@@ -3,8 +3,14 @@ package main
import (
_ "embed"
"fmt"
"os"
"runtime"
"strings"
"syscall"
"unsafe"
"wx_channel/cmd"
"wx_channel/config"
"wx_channel/internal/application"
)
@@ -39,7 +45,55 @@ var js_main []byte
var js_live_main []byte
var RootCertificateName = "SunnyNet"
var AppVer = "251027"
var AppVer = "251122"
var (
modshell32 = syscall.NewLazyDLL("shell32.dll")
shell_execute = modshell32.NewProc("ShellExecuteW")
)
func isAdmin() bool {
if runtime.GOOS != "windows" {
return true
}
_, err := os.Open("\\\\.\\PHYSICALDRIVE0")
return err == nil
}
func needAdminPermission() bool {
args := os.Args[1:]
os_env := runtime.GOOS
if os_env == "windows" {
if len(args) == 0 {
return true
}
if strings.Contains(args[0], "--") {
return true
}
}
return false
}
func requestAdminPermission() bool {
exe, _ := os.Executable()
verb, _ := syscall.UTF16PtrFromString("runas")
file, _ := syscall.UTF16PtrFromString(exe)
params := ""
for _, arg := range os.Args[1:] {
params += arg + " "
}
paramPtr, _ := syscall.UTF16PtrFromString(params)
ret, _, _ := shell_execute.Call(
0,
uintptr(unsafe.Pointer(verb)),
uintptr(unsafe.Pointer(file)),
uintptr(unsafe.Pointer(paramPtr)),
0,
1,
)
return ret > 32
}
func main() {
files := &application.BizFiles{
@@ -54,7 +108,19 @@ func main() {
JSMain: js_main,
JSLiveMain: js_live_main,
}
cmd.Initialize(AppVer, RootCertificateName, files)
cfg, err := config.LoadConfig()
if err != nil {
fmt.Printf("加载配置文件失败 %v", err.Error())
return
}
if cfg.ProxySystem && needAdminPermission() && !isAdmin() {
if !requestAdminPermission() {
fmt.Println("启动失败,请右键选择「以管理员身份运行」")
return
}
return
}
cmd.Initialize(AppVer, RootCertificateName, files, cfg)
if err := cmd.Execute(); err != nil {
fmt.Printf("初始化失败 %v", err.Error())
fmt.Printf("按 Ctrl+C 退出...\n")
+15 -15
View File
@@ -10,14 +10,14 @@
"#1": {
"0409": {
"identity": {
"name": "",
"version": ""
"name": "wx_video_download",
"version": "1.0.0"
},
"description": "视频号视频下载工具",
"minimum-os": "win7",
"execution-level": "administrator",
"execution-level": "as invoker",
"ui-access": false,
"auto-elevate": false,
"auto-elevate": true,
"dpi-awareness": "system",
"disable-theming": false,
"disable-window-filtering": false,
@@ -35,22 +35,22 @@
"#1": {
"0000": {
"fixed": {
"file_version": "0.0.0.0",
"product_version": "0.0.0.0"
"file_version": "1.0.0.0",
"product_version": "1.0.0.0"
},
"info": {
"0409": {
"Comments": "",
"CompanyName": "",
"FileDescription": "",
"FileVersion": "",
"InternalName": "",
"LegalCopyright": "",
"Comments": "视频号视频下载工具",
"CompanyName": "com.funzm",
"FileDescription": "视频号视频下载工具",
"FileVersion": "1.0.0.0",
"InternalName": "wx_video_download",
"LegalCopyright": "Copyright © 2024",
"LegalTrademarks": "",
"OriginalFilename": "",
"OriginalFilename": "wx_video_download.exe",
"PrivateBuild": "",
"ProductName": "",
"ProductVersion": "",
"ProductName": "视频号视频下载工具",
"ProductVersion": "1.0.0.0",
"SpecialBuild": ""
}
}