1
|
|
|
""" |
2
|
|
|
ffmpeg_streaming.streams |
3
|
|
|
~~~~~~~~~~~~ |
4
|
|
|
|
5
|
|
|
Useful methods |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
:copyright: (c) 2020 by Amin Yazdanpanah. |
9
|
|
|
:website: https://www.aminyazdanpanah.com |
10
|
|
|
:email: [email protected] |
11
|
|
|
:license: MIT, see LICENSE for more details. |
12
|
|
|
""" |
13
|
|
|
import logging |
14
|
|
|
import os |
15
|
|
|
import re |
16
|
|
|
import warnings |
17
|
|
|
from sys import platform |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def get_path_info(path): |
21
|
|
|
""" |
22
|
|
|
@TODO: add documentation |
23
|
|
|
""" |
24
|
|
|
dirname = os.path.dirname(path) |
25
|
|
|
name = str(os.path.basename(path).split('.')[0]) |
26
|
|
|
|
27
|
|
|
return dirname, name |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
def mkdir(dirname: str) -> None: |
31
|
|
|
""" |
32
|
|
|
@TODO: add documentation |
33
|
|
|
""" |
34
|
|
|
try: |
35
|
|
|
os.makedirs(dirname) |
36
|
|
|
except OSError as exc: |
37
|
|
|
logging.info(exc) |
38
|
|
|
pass |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
def rm(path: str) -> None: |
42
|
|
|
""" |
43
|
|
|
@TODO: add documentation |
44
|
|
|
""" |
45
|
|
|
try: |
46
|
|
|
os.remove(path) |
47
|
|
|
except OSError as exc: |
48
|
|
|
logging.info(exc) |
49
|
|
|
pass |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
def clean_args(args: list) -> list: |
53
|
|
|
""" |
54
|
|
|
@TODO: add documentation |
55
|
|
|
""" |
56
|
|
|
clean_args_ = [] |
57
|
|
|
for arg in args: |
58
|
|
|
if " " in arg: |
59
|
|
|
arg = '"' + arg + '"' |
60
|
|
|
clean_args_.append(arg.replace("\\", "/")) |
61
|
|
|
|
62
|
|
|
return clean_args_ |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
def convert_to_sec(time): |
66
|
|
|
""" |
67
|
|
|
@TODO: add documentation |
68
|
|
|
""" |
69
|
|
|
h, m, s = time.split(":") |
70
|
|
|
return int(h) * 3600 + int(m) * 60 + int(s) |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
def get_time(key, string): |
74
|
|
|
""" |
75
|
|
|
@TODO: add documentation |
76
|
|
|
""" |
77
|
|
|
time = re.search('(?<=' + key + ')\w+:\w+:\w+', string) |
78
|
|
|
if time: |
79
|
|
|
return convert_to_sec(time.group(0)) |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
def deprecated(func): |
83
|
|
|
""" |
84
|
|
|
@TODO: add documentation |
85
|
|
|
""" |
86
|
|
|
def deprecated_fun(*args, **kwargs): |
87
|
|
|
warnings.warn('The {} method is deprecated and will be removed in a future release'.format(func.__name__) |
88
|
|
|
, DeprecationWarning, stacklevel=2) |
89
|
|
|
return func(*args, **kwargs) |
90
|
|
|
return deprecated_fun |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
def get_os(): |
94
|
|
|
""" |
95
|
|
|
@TODO: add documentation |
96
|
|
|
""" |
97
|
|
|
if platform == "linux" or platform == "linux2": |
98
|
|
|
os_name = 'linux' |
99
|
|
|
elif platform == "darwin": |
100
|
|
|
os_name = 'os_x' |
101
|
|
|
elif platform == "win32" or platform == "Windows": |
102
|
|
|
os_name = 'windows' |
103
|
|
|
else: |
104
|
|
|
os_name = 'unknown' |
105
|
|
|
|
106
|
|
|
return os_name |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
def cnv_options_to_args(options: dict): |
110
|
|
|
""" |
111
|
|
|
@TODO: add documentation |
112
|
|
|
""" |
113
|
|
|
args = [] |
114
|
|
|
for k, v in options.items(): |
115
|
|
|
args.append('-{}'.format(k)) |
116
|
|
|
if v is not None: |
117
|
|
|
args.append('{}'.format(v)) |
118
|
|
|
|
119
|
|
|
return args |
120
|
|
|
|