-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebp-auto-convert.py
39 lines (28 loc) · 953 Bytes
/
webp-auto-convert.py
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
import os
import sys
import json
import subprocess
CREATE_NO_WINDOW = 0x08000000
def main():
if len(sys.argv) != 2:
raise Exception("No input file specified")
sys.exit(0)
path = sys.argv[0].replace('webp-auto-convert.exe', '')
fpath = sys.argv[1]
fext = fpath.split('.')[-1]
config = json.load(open(path + 'config.txt'))
output_format = '.'+config['output-format']
c = f'ffmpeg.exe -y -i "{fpath}" "{fpath.replace("."+fext, output_format)}" -hide_banner'
if config['hideconsole']:
subprocess.call(c, creationflags=CREATE_NO_WINDOW)
else:
os.system(c)
if config['remove-on-completion']: os.remove(fpath)
if config['open-on-completion']:
c = f'explorer.exe "{fpath.replace("."+fext, output_format)}"'
if config['hideconsole']:
subprocess.call(c, creationflags=CREATE_NO_WINDOW)
else:
os.system(c)
sys.exit(0)
main()