Passed
Push — master ( 671d58...c8c24d )
by Amin
03:46
created

ffmpeg_streaming.utiles.round_to_even()   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
"""
2
ffmpeg_streaming.streams
3
~~~~~~~~~~~~
4
5
Useful methods
6
7
8
:copyright: (c) 2019 by Amin Yazdanpanah.
9
:website: https://www.aminyazdanpanah.com
10
:email: [email protected]
11
:license: MIT, see LICENSE for more details.
12
"""
13
14
import os
15
import tempfile
16
import warnings
17
from urllib.parse import urlparse
18
19
20
def round_to_even(num):
21
    num = int(num) if ((int(num) % 2) == 0) else int(num) + 1
22
    return num
23
24
25
def clear_tmp_file(filename):
26
    if filename is not None and filename.startswith(tempfile.gettempdir()) and filename.endswith('_py_ff_vi_st.tmp'):
27
        os.remove(filename)
28
29
30
def get_path_info(path):
31
    dirname = os.path.dirname(path).replace("\\", "/")
32
    name = str(os.path.basename(path).split('.')[0])
33
34
    if not is_url(path) and not os.path.exists(dirname):
35
        os.makedirs(dirname)
36
37
    return dirname, name
38
39
40
def is_url(url):
41
    try:
42
        parsed_url = urlparse(url)
43
        return all([parsed_url.scheme, parsed_url.netloc, parsed_url.path])
44
    except:
45
        return False
46
47
48
def convert_to_sec(time):
49
    h, m, s = time.split(":")
50
    return int(h) * 3600 + int(m) * 60 + int(s)
51
52
53
def deprecated(func):
54
    def deprecated_fun(*args, **kwargs):
55
        warnings.warn('The {} method is deprecated and will be removed in a future release'.format(func.__name__)
56
                      , DeprecationWarning, stacklevel=2)
57
        return func(*args, **kwargs)
58
    return deprecated_fun
59