-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
service.py
54 lines (43 loc) · 1.55 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
import xbmc
import xbmcgui
from resources.lib.proxy import Proxy
from resources.lib.addon import *
from resources.lib.log import LOG
from resources.lib.cache import Cache
def export_epg():
from datetime import datetime, timedelta
def needs_update(filename):
if os.path.exists(filename):
file_modification_time = datetime.fromtimestamp(os.path.getmtime(filename))
return datetime.now() - file_modification_time > timedelta(hours=6)
return True
channels_filename = os.path.join(profile_dir, 'channels.m3u8')
epg_filename = os.path.join(profile_dir, 'epg.xml')
LOG('channels filename: {}'.format(channels_filename))
LOG('epg filename: {}'.format(epg_filename))
channels_needs_update = needs_update(channels_filename)
epg_needs_update = needs_update(epg_filename)
LOG('channels_needs_update: {} epg_needs_update: {}'.format(channels_needs_update, epg_needs_update))
if channels_needs_update or epg_needs_update:
xbmc.executebuiltin('RunPlugin(plugin://plugin.video.movistarplus/?action=export_epg_now)')
if __name__ == '__main__':
LOG('Service started')
proxy = Proxy()
proxy.start()
LOG('proxy_address: {}'.format(proxy.proxy_address))
cache = Cache(profile_dir)
cache.save_file('proxy.txt', proxy.proxy_address)
if addon.getSettingBool('export_epg'):
try:
export_epg()
except:
pass
monitor = xbmc.Monitor()
while not monitor.abortRequested():
if monitor.waitForAbort(1):
break
proxy.stop()