Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
format-cli/geshi.py at main · rolte789/format-cli · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
rolte789
format-cli
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
format-cli
/
geshi.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
92 lines (74 loc) · 3.08 KB
main
Breadcrumbs
format-cli
/
geshi.py
Copy path
Top
File metadata and controls
Code
Blame
92 lines (74 loc) · 3.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
os
import
shutil
import
subprocess
import
sys
import
re
if
not
shutil
.
which
(
"ffmpeg"
):
print
(
'当前系统未安装ffmpeg,请下载变将 ffmpeg.exe 放在当前目录下
\n
下载地址
\n
https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.7z'
)
input
(
"按回车退出"
)
sys
.
exit
()
root
=
os
.
getcwd
()
filepath
=
root
cfg
=
os
.
path
.
join
(
root
,
'cfg.txt'
)
sext
=
[
'mp3'
,
'flac'
,
'mp4'
,
'mpeg'
,
'aac'
,
'mkv'
,
'avi'
]
ext
=
'wav'
if
os
.
path
.
exists
(
cfg
):
with
open
(
cfg
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
for
line
in
f
.
readlines
():
it
=
line
.
strip
()
if
it
:
it
=
it
.
replace
(
','
,
','
).
split
(
'='
)
length
=
len
(
it
)
if
length
==
2
:
if
it
[
0
].
lower
()
==
'source_ext'
:
sext
=
[
x
.
lower
().
strip
()
for
x
in
it
[
1
].
split
(
","
)]
elif
it
[
0
].
lower
()
==
'target_ext'
:
ext
=
it
[
1
].
lower
().
strip
().
split
(
','
)[
0
].
strip
()
elif
it
[
0
]
==
'dir'
and
os
.
path
.
exists
(
it
[
1
])
and
os
.
path
.
isdir
(
it
[
1
]):
filepath
=
it
[
1
]
print
(
f"""
将把当前目录下
{
","
.
join
(
sext
)
}
格式的文件转为
{
ext
}
格式
你也可以修改 cfg.txt 里 source_ext 后的扩展名列表,改变需要被转换的格式
修改 target_ext 改变要转换到的格式
"""
)
yes
=
input
(
"如果确认开始转换,请输入y
\n
或者输入 待转换格式->转换到的格式
\n
例如输入 avi->mp4 将把 avi 视频转换 mp4 视频: "
)
yes
=
yes
.
strip
()
if
not
yes
:
sys
.
exit
()
if
len
(
yes
)
==
1
and
yes
.
lower
()
!=
'y'
:
sys
.
exit
()
if
len
(
yes
)
>
1
:
m
=
re
.
match
(
r'([a-zA-Z0-9]+)->([a-zA-Z0-9]+)'
,
yes
,
re
.
I
)
if
not
m
or
len
(
m
.
groups
())
!=
2
:
print
(
'输入错误,如果想输入 旧格式转为新格式,请按照 avi->mp4 格式输入'
)
sys
.
exit
()
m
=
m
.
groups
()
sext
=
m
[
0
].
lower
()
ext
=
m
[
1
].
lower
()
files
=
[]
for
it
in
os
.
listdir
(
filepath
):
if
it
.
split
(
'.'
)[
-
1
].
lower
()
in
sext
:
files
.
append
(
it
)
if
len
(
files
)
<
1
:
print
(
f'
\n
没有需要转换的文件'
)
else
:
ok
=
0
err
=
[]
for
i
,
it
in
enumerate
(
files
):
try
:
cmd
=
[
'ffmpeg'
,
"-hide_banner"
,
"-ignore_unknown"
,
'-y'
,
'-i'
,
os
.
path
.
normpath
(
os
.
path
.
join
(
filepath
,
it
)) ]
if
ext
.
lower
()
==
'mp4'
:
cmd
.
extend
([
'-c:v'
,
'libx264'
,
'-c:a'
,
'aac'
])
cmd
.
append
(
os
.
path
.
normpath
(
os
.
path
.
join
(
filepath
,
f'
{
it
}
.
{
ext
}
'
)))
print
(
f'
\n
[
{
i
+
1
}
]. 开始转换
{
it
}
\n
可能需要一些时间,结束后将有提示,请耐心等待
\n
'
)
p
=
subprocess
.
run
(
cmd
,
check
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
if
p
.
returncode
!=
0
:
input
(
str
(
p
.
stderr
))
sys
.
exit
()
print
(
f'[OK]
{
it
}
转换成功'
)
ok
+=
1
except
Exception
as
e
:
err
.
append
(
it
)
print
(
f'[Error]
{
it
}
转换失败
{
str
(
e
)
}
'
)
print
(
f"
\n
转换完毕,
{
ok
}
个成功,
{
len
(
err
)
}
个失败,
{
err
if
len
(
err
)
>
0
else
''
}
\n
"
)
input
(
"
\n
按回车退出"
)
You can’t perform that action at this time.