-
Notifications
You must be signed in to change notification settings - Fork 28
/
functions.py
70 lines (52 loc) · 1.98 KB
/
functions.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
# -*- coding: utf-8 -*-
"""Functions code"""
from __future__ import absolute_import, division, unicode_literals
import logging
from resources.lib import kodilogging, kodiutils
from resources.lib.modules.addon import Addon
from resources.lib.modules.contextmenu import ContextMenu
from resources.lib.modules.iptvsimple import IptvSimple
_LOGGER = logging.getLogger(__name__)
def setup_iptv_simple():
"""Setup IPTV Simple"""
reply = kodiutils.yesno_dialog(message=kodiutils.localize(30700)) # Are you sure...
if reply:
if IptvSimple.setup():
kodiutils.ok_dialog(message=kodiutils.localize(30701)) # The configuration of IPTV Simple is completed!
else:
kodiutils.ok_dialog(message=kodiutils.localize(30702)) # The configuration of IPTV Simple has failed!
# Open settings again
kodiutils.open_settings()
def refresh():
"""Refresh the channels and EPG"""
Addon.refresh(True)
# Open settings again
kodiutils.open_settings()
def play_from_contextmenu():
"""Play an item from the Context Menu in Kodi 18"""
stream = ContextMenu.get_direct_uri()
if stream is None:
kodiutils.ok_dialog(message=kodiutils.localize(30706))
return
_LOGGER.debug('Playing using direct URI: %s', stream)
kodiutils.execute_builtin('PlayMedia', stream)
def open_settings():
"""Open the settings for IPTV Manager"""
kodiutils.open_settings()
def run(args):
"""Run the function"""
kodilogging.config()
function = args[1]
function_map = {
'setup-iptv-simple': setup_iptv_simple,
'refresh': refresh,
'play_from_contextmenu': play_from_contextmenu,
'open_settings': open_settings,
}
try:
# TODO: allow to pass *args to the function so we can also pass arguments
_LOGGER.debug('Routing to function: %s', function)
function_map.get(function)()
except (TypeError, IndexError):
_LOGGER.error('Could not route to %s', function)
raise