-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.py
131 lines (95 loc) · 3.96 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os
from datetime import datetime
import xbmc
import xbmcvfs
import xbmcaddon
from addon import addict, main, utils
ADDON = xbmcaddon.Addon()
ADDON_ID = os.path.join(ADDON.getAddonInfo('id'))
PROFILE_DIR = xbmcvfs.translatePath(os.path.join(
ADDON.getAddonInfo('profile')))
class Monitor(xbmc.Monitor):
def __init__(self):
addon = xbmcaddon.Addon()
self._quality = addon.getSettingInt('aa.quality')
def onSettingsChanged(self):
addon = xbmcaddon.Addon()
if addon.getSettingInt('aa.quality') != self._quality:
utils.logd('Quality setting changed.')
quality_id = utils.get_quality_id(main.TEST_LOGIN_NETWORK)
for network in addict.NETWORKS.keys():
aa = addict.AudioAddict(PROFILE_DIR, network)
if aa.is_premium:
utils.logd('Updating preferred quality for:', network)
aa.preferred_quality(quality_id)
self._quality = addon.getSettingInt('aa.quality')
def monitor_live(skip_shows=None):
if not skip_shows:
skip_shows = []
now = addict.datetime_now()
addon = xbmcaddon.Addon()
for network in addict.NETWORKS.keys():
aa = addict.AudioAddict.get(PROFILE_DIR, network)
if not aa.is_active or not aa.network['has_shows']:
continue
followed = [s.get('slug') for s in aa.get_shows_followed()]
shows = aa.get_live_shows()
live_show_ids = [s.get('id') for s in shows]
# Remove shows which are not live anymore
skip_shows = [i for i in skip_shows if i in live_show_ids]
for show in shows:
if show.get('id') in skip_shows:
continue
end_at = addict.parse_datetime(show.get('end_at'))
if end_at < now:
continue
skip_shows.append(show.get('id'))
_show = show.get('show')
if _show.get('slug') in followed and addon.getSettingBool(
'addon.notify_live'):
utils.notify('[B]{}[/B] is live!'.format(_show.get('name')))
if addon.getSettingBool('addon.tune_in_live'):
filename = xbmc.getInfoLabel('Player.Filenameandpath')
if not filename:
continue
playing = utils.get_playing()
if not playing:
continue
chan = _show.get('channels', [])[0]
if (playing['network'] != network
or playing['channel'] != chan.get('key')):
utils.logd(
'Different network/channel playing, not tuning in.')
continue
if playing['live']:
utils.logd('Live stream already playing.')
break
time_left = (end_at - now).seconds
if time_left < 2:
utils.log('Less than 2 minutes left, not tuning in.')
break
utils.log('Tuning in to live stream...')
xbmc.executebuiltin('RunPlugin({})'.format(
utils.build_path('play', network, playing['channel'],
live=True)))
return skip_shows
def hourly():
# Clean up cache
for network in addict.NETWORKS.keys():
utils.logd('Invalidating cache for {}'.format(network))
aa = addict.AudioAddict.get(PROFILE_DIR, network)
aa.invalidate_cache()
# Update user information (like premium status etc.)
utils.logd('Updating user information')
aa = addict.AudioAddict.get(PROFILE_DIR, main.TEST_LOGIN_NETWORK)
aa.get_member_session()
if __name__ == '__main__':
monitor = Monitor()
skip_shows = []
while not monitor.abortRequested():
now = datetime.utcnow()
if monitor.waitForAbort(60 - now.second):
break
skip_shows = monitor_live(skip_shows)
if now.minute == 0:
hourly()