forked from MikeWent/webm2mp4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
71 lines (56 loc) · 2.1 KB
/
utils.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
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
import json
import os
import random
import string
from hurry.filesize import alternative, size
def bytes2human(raw):
return size(raw, system=alternative)
def filesize(filename):
return os.stat(filename).st_size
def load_config_vars():
config = {"telegram_token": "",
"ffmpeg_threads": 2,
"temp_path": "/tmp/",
"ffmpeg_timelimit": 900,
"ffmpeg_preset": "slow"}
# Loading ENV Vars from Docker
telegram_token = os.getenv('TELEGRAM_TOKEN') or ''
ffmpeg_threads = os.getenv('FFMPEG_THREADS') or ''
temp_path = os.getenv('TMP_PATH') or ''
ffmpeg_timelimit = os.getenv('FFMPEG_TIMELIMIT') or ''
ffmpeg_preset = os.getenv('FFMPEG_PRESET') or ''
print('Using the following Parameters: FFMPEG Timelimit: ' + str(ffmpeg_timelimit) + ', FFMPEG Preset: ' + str(ffmpeg_preset) + ', FFMPEG Threads: ' + str(ffmpeg_threads) + ', Temp Path: ' + str(temp_path) + ', Telegram Bot Token: ' + str(telegram_token) + '.')
for variable in ["telegram_token", "ffmpeg_threads", "temp_path", "ffmpeg_timelimit", "ffmpeg_preset"]:
config[variable] = eval(variable)
return config
def load_config(filename):
# Default config
# config_json = {"telegram_token": "",
# "ffmpeg_threads": 2,
# "temp_path": "/tmp/",
# "ffmpeg_timelimit": 900,
# "ffmpeg_preset": "veryfast"}
try:
with open(filename, "r") as f:
config.update(json.load(f))
return config
except FileNotFoundError:
with open(filename, "w") as f:
json.dump(config, f, indent=4)
return config
except:
print(f"Unable to parse {filename}, is it corrupted?")
exit(1)
def rm(filename):
"""Delete file"""
try:
os.remove(filename)
except Exception as e:
print(f"Unable to rm {filename}: {e}")
def random_string(length=12):
"""Random string of uppercase ASCII and digits"""
return "".join(
random.choice(string.ascii_uppercase + string.digits) for _ in range(length)
)
def ci_cd(text):
print(str(text))