forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffmpeg.py
68 lines (49 loc) · 1.66 KB
/
ffmpeg.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
"""
Component that will help set the ffmpeg component.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/ffmpeg/
"""
import logging
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
DOMAIN = 'ffmpeg'
REQUIREMENTS = ["ha-ffmpeg==0.12"]
_LOGGER = logging.getLogger(__name__)
CONF_INPUT = 'input'
CONF_FFMPEG_BIN = 'ffmpeg_bin'
CONF_EXTRA_ARGUMENTS = 'extra_arguments'
CONF_OUTPUT = 'output'
CONF_RUN_TEST = 'run_test'
DEFAULT_BINARY = 'ffmpeg'
DEFAULT_RUN_TEST = True
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Optional(CONF_FFMPEG_BIN, default=DEFAULT_BINARY): cv.string,
vol.Optional(CONF_RUN_TEST, default=DEFAULT_RUN_TEST): cv.boolean,
}),
}, extra=vol.ALLOW_EXTRA)
FFMPEG_CONFIG = {}
FFMPEG_TEST_CACHE = {}
def setup(hass, config):
"""Setup the FFmpeg component."""
global FFMPEG_CONFIG
FFMPEG_CONFIG = config.get(DOMAIN)
return True
def get_binary():
"""Return ffmpeg binary from config."""
return FFMPEG_CONFIG.get(CONF_FFMPEG_BIN)
def run_test(input_source):
"""Run test on this input. TRUE is deactivate or run correct."""
from haffmpeg import Test
if FFMPEG_CONFIG.get(CONF_RUN_TEST):
# if in cache
if input_source in FFMPEG_TEST_CACHE:
return FFMPEG_TEST_CACHE[input_source]
# run test
test = Test(get_binary())
if not test.run_test(input_source):
_LOGGER.error("FFmpeg '%s' test fails!", input_source)
FFMPEG_TEST_CACHE[input_source] = False
return False
FFMPEG_TEST_CACHE[input_source] = True
return True