forked from Pati/plugin.video.tvnow.de
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.py
64 lines (52 loc) · 1.6 KB
/
service.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
# -*- coding: utf-8 -*-
# Created on: 21.10.2019
"""Kodi plugin for Tvnow (https://tvnow.de)"""
import sys
import threading
import traceback
import xbmc
import resources.lib.manifestServer as manifestServer
class TvNowService(object):
"""
TvNowService addon service
"""
def __init__(self):
self.server = {
'class': manifestServer.ManifestServer,
'instance': None,
'thread': None}
self.init_server()
def init_server(self):
self.server['class'].allow_reuse_address = True
self.server['instance'] = self.server['class'](
('127.0.0.1', 42467))
self.server['thread'] = threading.Thread(
target=self.server['instance'].serve_forever)
def start_services(self):
"""
Start the background services
"""
self.server['instance'].server_activate()
self.server['instance'].timeout = 1
self.server['thread'].start()
def shutdown(self):
"""
Stop the background services
"""
self.server['instance'].server_close()
self.server['instance'].shutdown()
self.server['instance'] = None
self.server['thread'].join()
self.server['thread'] = None
def run(self):
"""Main loop. Runs until xbmc.Monitor requests abort"""
try:
self.start_services()
except Exception as exc:
return
monitor = xbmc.Monitor()
while not monitor.abortRequested():
monitor.waitForAbort(1)
self.shutdown()
if __name__ == '__main__':
TvNowService().run()