|
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
|
|
|
dirname = os.path.dirname(path) |
|
22
|
|
|
name = str(os.path.basename(path).split('.')[0]) |
|
23
|
|
|
|
|
24
|
|
|
return dirname, name |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
def mkdir(dirname: str) -> None: |
|
28
|
|
|
try: |
|
29
|
|
|
os.makedirs(dirname) |
|
30
|
|
|
except OSError as exc: |
|
31
|
|
|
logging.info(exc) |
|
32
|
|
|
pass |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
def clean_args(args: list) -> list: |
|
36
|
|
|
clean_args_ = [] |
|
37
|
|
|
for arg in args: |
|
38
|
|
|
if " " in arg: |
|
39
|
|
|
arg = '"' + arg + '"' |
|
40
|
|
|
clean_args_.append(arg.replace("\\", "/")) |
|
41
|
|
|
|
|
42
|
|
|
return clean_args_ |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
def convert_to_sec(time): |
|
46
|
|
|
h, m, s = time.split(":") |
|
47
|
|
|
return int(h) * 3600 + int(m) * 60 + int(s) |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
def get_time(key, string): |
|
51
|
|
|
time = re.search('(?<=' + key + ')\w+:\w+:\w+', string) |
|
52
|
|
|
if time: |
|
53
|
|
|
return convert_to_sec(time.group(0)) |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
def deprecated(func): |
|
57
|
|
|
def deprecated_fun(*args, **kwargs): |
|
58
|
|
|
warnings.warn('The {} method is deprecated and will be removed in a future release'.format(func.__name__) |
|
59
|
|
|
, DeprecationWarning, stacklevel=2) |
|
60
|
|
|
return func(*args, **kwargs) |
|
61
|
|
|
return deprecated_fun |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
def get_os(): |
|
65
|
|
|
if platform == "linux" or platform == "linux2": |
|
66
|
|
|
os_name = 'linux' |
|
67
|
|
|
elif platform == "darwin": |
|
68
|
|
|
os_name = 'os_x' |
|
69
|
|
|
elif platform == "win32" or platform == "Windows": |
|
70
|
|
|
os_name = 'windows' |
|
71
|
|
|
else: |
|
72
|
|
|
os_name = 'unknown' |
|
73
|
|
|
|
|
74
|
|
|
return os_name |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
def cnv_options_to_args(options: dict): |
|
78
|
|
|
args = [] |
|
79
|
|
|
for k, v in options.items(): |
|
80
|
|
|
args.append('-{}'.format(k)) |
|
81
|
|
|
if v is not None: |
|
82
|
|
|
args.append('{}'.format(v)) |
|
83
|
|
|
|
|
84
|
|
|
return args |
|
85
|
|
|
|