-
-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy path_utiles.py
126 lines (100 loc) · 2.53 KB
/
_utiles.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
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
"""
ffmpeg_streaming.streams
~~~~~~~~~~~~
Useful methods
:copyright: (c) 2020 by Amin Yazdanpanah.
:website: https://www.aminyazdanpanah.com
:email: [email protected]
:license: MIT, see LICENSE for more details.
"""
import logging
import os
import re
import time
import warnings
from sys import platform
def get_path_info(path):
"""
@TODO: add documentation
"""
dirname = os.path.dirname(path)
name = str(os.path.basename(path).rsplit('.', 1)[0])
return dirname, name
def mkdir(dirname: str) -> None:
"""
@TODO: add documentation
"""
try:
os.makedirs(dirname)
except OSError as exc:
logging.info(exc)
def rm(path: str) -> None:
"""
@TODO: add documentation
"""
try:
os.remove(path)
except OSError as exc:
logging.info(exc)
def clean_args(args: list) -> list:
"""
@TODO: add documentation
"""
clean_args_ = []
for arg in args:
if " " in arg:
arg = '"' + arg + '"'
clean_args_.append(arg.replace("\\", "/").replace("__COLON__", ":"))
return clean_args_
def convert_to_sec(time):
"""
@TODO: add documentation
"""
h, m, s = time.split(":")
return int(h) * 3600 + int(m) * 60 + int(s)
def get_time(key, string, default):
"""
@TODO: add documentation
"""
time = re.search('(?<={})\w+:\w+:\w+'.format(key), string)
return convert_to_sec(time.group(0)) if time else default
def time_left(start_time, unit, total):
"""
@TODO: add documentation
"""
if unit != 0:
diff_time = time.time() - start_time
return total * diff_time / unit - diff_time
else:
return 0
def deprecated(func):
"""
@TODO: add documentation
"""
def deprecated_fun(*args, **kwargs):
warnings.warn('The {} method is deprecated and will be removed in a future release'.format(func.__name__)
, DeprecationWarning, stacklevel=2)
return func(*args, **kwargs)
return deprecated_fun
def get_os():
"""
@TODO: add documentation
"""
if platform in ["linux", "linux2"]:
return 'linux'
elif platform == "darwin":
return 'os_x'
elif platform in ["win32", "Windows"]:
return 'windows'
else:
return 'unknown'
def cnv_options_to_args(options: dict):
"""
@TODO: add documentation
"""
args = []
for k, v in options.items():
args.append('-{}'.format(k))
if v is not None:
args.append('{}'.format(v))
return args