-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
223 lines (191 loc) · 5.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package main
import (
"fmt"
"log"
"sync"
"time"
tool "github.com/One-Studio/ptools/pkg"
"github.com/cavaliercoder/grab"
)
func test1() {
//ffcommand := "ffmpeg -i ~/movies/演示找A卡驱动.mp4 -c:v libx264 -crf 26 -preset 3 -c:a copy ~/测试.mp4 -y"
ffcommand := "E:/测试/ffmpeg.exe -i E:/测试/测试ff.mp4 -c:v libx264 -crf 26 -preset 3 -c:a copy E:/测试/结果.mp4 -y"
suspend := "C:\\Users\\Purp1e\\go\\src\\github.com\\One-Studio\\ptools\\temp\\pssuspend.exe"
//x264command := "E:/测试/x264.exe E:/测试/测试ff.mp4 --crf 26 --preset slow -output E:/测试/结果.mp4"
a := make(chan rune)
defer close(a)
go func() {
time.Sleep(time.Second * 1)
fmt.Println("触发暂停")
tool.Pause(a)
time.Sleep(time.Second * 2)
fmt.Println("触发继续")
tool.Resume(a)
time.Sleep(time.Second * 2)
fmt.Println("触发结束")
tool.Quit(a)
}()
err := tool.ExecRealtimeControl(ffcommand, func(line string) {
fmt.Println(line)
}, a, suspend)
close(a)
if err != nil {
log.Println(err)
}
}
func testGrab() {
//https://cdn.jsdelivr.net/gh/One-Studio/FFmpeg-Win64@master/download_link
resp, err := grab.Get(".", "https://cdn.jsdelivr.net/gh/One-Studio/FFmpeg-Win64@master/download_link")
if err != nil {
log.Fatal(err)
}
fmt.Println("Download saved to", resp.Filename)
}
func testChan() {
value := ""
var c = make(chan string)
defer close(c)
go func() {
fmt.Println("第一个go routine")
value = "第一个"
c <- "1"
}()
go func() {
fmt.Println("第二个go routine")
value = "第二个"
c <- "2"
}()
fmt.Println("测试结束", <-c)
time.Sleep(time.Second)
fmt.Println("测试结束", <-c)
}
func testWG() {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
fmt.Println("第一件事做完")
}()
wg.Add(1)
go func() {
defer wg.Done()
fmt.Println("第二件事做完")
}()
wg.Wait()
time.Sleep(time.Second)
}
func testCompareVersion() {
fmt.Println(tool.CompareVersion("v1.0.1-alpha", "v1.0.2-aa"))
fmt.Println(tool.CompareVersion("a1.0.1", "v2.0.0-alpha.47"))
fmt.Println(tool.CompareVersion("z1.0.1", "v2.0.0-alpha.47"))
fmt.Println(tool.CompareVersion("v1.2.3", "v1.2.3"))
fmt.Println(tool.CompareVersion("v1.2.3", "v1.2"))
}
func testTool() {
//var t = tool.CreateTool()
var t = tool.Tool{
Name: "hlae",
Path: "./bin/hlae/hlae.exe",
TakeOver: true,
Version: "",
VersionApi: "",
VersionApiCDN: "https://cdn.jsdelivr.net/gh/One-Studio/HLAE-Archive@master/version",
DownloadLink: "",
DownloadLinkCDN: "https://cdn.jsdelivr.net/gh/One-Studio/HLAE-Archive@master/dist/hlae.zip",
VersionRegExp: "",
GithubRepo: "advancedfx/advancedfx",
IsGitHub: true,
IsCLI: false,
KeyWords: []string{"hlae", "zip"},
NonKeyWords: []string{".asc"},
}
fmt.Println(t.Install())
fmt.Println("=====\n当前参数\n", t)
}
func testTool1() {
var t = tool.Tool{
Name: "ffmpeg",
Path: "./bin/ffmpeg/ffmpeg.exe",
TakeOver: true,
Version: "",
VersionApi: "https://www.gyan.dev/ffmpeg/builds/release-version",
VersionApiCDN: "https://cdn.jsdelivr.net/gh/One-Studio/FFmpeg-Win64@master/version",
DownloadLink: "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.7z",
DownloadLinkCDN: "https://cdn.jsdelivr.net/gh/One-Studio/FFmpeg-Win64@master/dist/ffmpeg-release-essentials.7z",
VersionRegExp: "ffmpeg version (\\S+)-essentials_build-www.gyan.dev",
GithubRepo: "",
IsGitHub: false,
IsCLI: true,
Fetch: "",
//Fetch: "ffmpeg.exe",
}
if err := t.Install(); err != nil {
fmt.Println(err)
}
}
func testXMove() {
fmt.Println(tool.XMove("C:\\Users\\Purp1e\\go\\src\\github.com\\One-Studio\\ptools\\bin\\ffmpeg\\ffmpeg-release-essentials\\README.txt",
"C:\\Users\\Purp1e\\Desktop\\"))
}
func testDecomp1() {
//去除顶层文件夹
//_ = os.MkdirAll("./temp/ffmpeg", os.ModePerm)
tempDir := "./bin/"
filename := "你好.7z"
to := "./temp/ffmpeg"
err := tool.SafeDecompress(tempDir+filename, to)
if err != nil {
log.Println(err)
}
//TODO 核心操作
//fmt.Println("得到的exe路径:", tool.GetFilePathFromDir("./temp/hlae", "AfxHook.dat"))
////temp\ffmpeg\AfxHook.dat
//_ = tool.XMove("temp\\hlae\\AfxHook.dat", "D:\\afx.dat")
}
func testTopDir() {
//fetch binary
ok, path := tool.CheckTopDir("./bin/ffmpeg")
if ok {
fmt.Println(path)
}
}
func testConfigDir() {
fmt.Println(tool.ConfigDir())
}
//TODO 测试完这个,win平台的几个工具就能用了
func testFFmpeg() {
command := []string{
"bin\\ffmpeg.exe",
"-i",
"C:\\Users\\Purp1e\\Videos\\sb战术.mp4",
"-vcodec",
"libx264",
"-crf",
"20",
"-preset",
"slow",
"C:\\Users\\Purp1e\\Videos\\sb战术_encode.mp4",
}
if out, err := tool.ExecArgs(command); err != nil {
fmt.Println(err)
} else {
fmt.Println(out)
}
// func(line string) {
// fmt.Println(line)
// }); err != nil {
// fmt.Println(err)
//}
}
func main() {
tool.Test()
//testConfigDir()
//testFFmpeg()
//testChan()
//testWG()
//testTool()
//testTool1()
//testXMove()
//testDecomp1()
//testTopDir()
}