forked from Pityke1105/plugin.video.sl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
150 lines (131 loc) · 6.74 KB
/
main.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import sys
import inputstreamhelper
import logger
import skylink
import xbmc
import xbmcaddon
import xbmcgui
import xbmcplugin
import replay
import live
import library
import utils
import datetime
_id = int(sys.argv[1])
_addon = xbmcaddon.Addon()
_profile = utils.dec_utf8(xbmc.translatePath(_addon.getAddonInfo('profile')))
_user_name = xbmcplugin.getSetting(_id, 'username')
_password = xbmcplugin.getSetting(_id, 'password')
_provider = 'directone.hu'
_pin_protected_content = 'false' != xbmcplugin.getSetting(_id, 'pin_protected_content')
_a_show_live = 'false' != xbmcplugin.getSetting(_id, 'a_show_live')
_python3 = sys.version_info[0] >= 3
def play_archive(station_id, catchup_id, askpin):
logger.log.info('play archive: ' + station_id + ' catchup_id: ' + str(catchup_id))
sl = skylink.Skylink(_user_name, _password, _profile, _provider)
if askpin != 'False':
pin_ok = utils.ask_for_pin(sl)
if not pin_ok:
xbmcplugin.setResolvedUrl(_id, False, xbmcgui.ListItem())
return
try:
info = utils.call(sl, lambda: sl.replay_info(catchup_id))
except skylink.StreamNotResolvedException as e:
xbmcgui.Dialog().ok(heading=_addon.getAddonInfo('name'), line1=_addon.getLocalizedString(e.id))
xbmcplugin.setResolvedUrl(_id, False, xbmcgui.ListItem())
return
if info:
is_helper = inputstreamhelper.Helper(info['protocol'], drm=info['drm'])
if is_helper.check_inputstream():
playitem = xbmcgui.ListItem(path=info['path'])
if (_python3): # Python 3.x
playitem.setProperty('inputstream', is_helper.inputstream_addon)
else: # Python 2.5+
playitem.setProperty('inputstreamaddon', is_helper.inputstream_addon)
playitem.setProperty('inputstream.adaptive.manifest_type', info['protocol'])
playitem.setProperty('inputstream.adaptive.license_type', info['drm'])
playitem.setProperty('inputstream.adaptive.license_key', info['key'])
xbmcplugin.setResolvedUrl(_id, True, playitem)
def locId_from_time(sl, stationid, utc):
now = datetime.datetime.now()
from_date = now.replace(hour=0, minute=0, second=0, microsecond=0) - datetime.timedelta(days=7)
epg = utils.call(sl, lambda: sl.epg([{'stationid': stationid}], from_date, now, False))
utc = datetime.datetime.fromtimestamp(int(utc))
if epg:
for program in epg[0][stationid]:
start = datetime.datetime.utcfromtimestamp(program['start'])
if start <= utc <= start + datetime.timedelta(minutes=program['duration']):
logger.log.info('loc: ' + program['title'] + ',start: ' + str(start) + ',utc: ' + str(utc))
return program['locId']
def play_archive_utc(station_id, utc, askpin):
logger.log.info('play archive: ' + station_id + 'utc: ' + utc)
sl = skylink.Skylink(_user_name, _password, _profile, _provider)
if askpin != 'False':
pin_ok = utils.ask_for_pin(sl)
if not pin_ok:
xbmcplugin.setResolvedUrl(_id, False, xbmcgui.ListItem())
return
try:
info = utils.call(sl, lambda: sl.replay_info(locId_from_time(sl, station_id, utc)))
except skylink.StreamNotResolvedException as e:
xbmcgui.Dialog().ok(heading=_addon.getAddonInfo('name'), line1=_addon.getLocalizedString(e.id))
xbmcplugin.setResolvedUrl(_id, False, xbmcgui.ListItem())
return
if info:
is_helper = inputstreamhelper.Helper(info['protocol'], drm=info['drm'])
if is_helper.check_inputstream():
playitem = xbmcgui.ListItem(path=info['path'])
playitem.setProperty('inputstreamaddon', is_helper.inputstream_addon)
playitem.setProperty('inputstream.adaptive.manifest_type', info['protocol'])
playitem.setProperty('inputstream.adaptive.license_type', info['drm'])
playitem.setProperty('inputstream.adaptive.license_key', info['key'])
xbmcplugin.setResolvedUrl(_id, True, playitem)
def play(channel_id, askpin):
logger.log.info('play: ' + channel_id)
sl = skylink.Skylink(_user_name, _password, _profile, _provider)
if askpin != 'False':
pin_ok = utils.ask_for_pin(sl)
if not pin_ok:
xbmcplugin.setResolvedUrl(_id, False, xbmcgui.ListItem())
return
try:
info = utils.call(sl, lambda: sl.channel_info(channel_id))
except skylink.StreamNotResolvedException as e:
xbmcgui.Dialog().ok(heading=_addon.getAddonInfo('name'), line1=_addon.getLocalizedString(e.id))
xbmcplugin.setResolvedUrl(_id, False, xbmcgui.ListItem())
return
if info:
is_helper = inputstreamhelper.Helper(info['protocol'], drm=info['drm'])
if is_helper.check_inputstream():
playitem = xbmcgui.ListItem(path=info['path'])
if (_python3): # Python 3.x
playitem.setProperty('inputstream', is_helper.inputstream_addon)
else: # Python 2.5+
playitem.setProperty('inputstreamaddon', is_helper.inputstream_addon)
playitem.setProperty('inputstream.adaptive.manifest_type', info['protocol'])
playitem.setProperty('inputstream.adaptive.license_type', info['drm'])
playitem.setProperty('inputstream.adaptive.license_key', info['key'])
xbmcplugin.setResolvedUrl(_id, True, playitem)
if __name__ == '__main__':
args = utils.parse_qs(sys.argv[2][1:])
if 'id' in args:
play(str(args['id'][0]), str(args['askpin'][0]) if 'askpin' in args else 'False')
elif ('stationid' in args) and ('catchup_id' in args):
play_archive(
str(args['stationid'][0]),
str(args['catchup_id'][0]) if 'catchup_id' in args else None,
str(args['askpin'][0]) if 'askpin' in args else 'False')
elif 'replay' in args:
replay.router(args, skylink.Skylink(_user_name, _password, _profile, _provider, _pin_protected_content))
elif 'live' in args:
live.router(args, skylink.Skylink(_user_name, _password, _profile, _provider, _pin_protected_content))
elif 'library' in args:
library.router(args, skylink.Skylink(_user_name, _password, _profile, _provider, _pin_protected_content))
else:
xbmcplugin.setPluginCategory(_id, '')
xbmcplugin.setContent(_id, 'videos')
if _a_show_live:
xbmcplugin.addDirectoryItem(_id, live.get_url(live='channels'), xbmcgui.ListItem(label=_addon.getLocalizedString(30700)), True)
xbmcplugin.addDirectoryItem(_id, replay.get_url(replay='channels'), xbmcgui.ListItem(label=_addon.getLocalizedString(30600)), True)
xbmcplugin.addDirectoryItem(_id, library.get_url(library='types'), xbmcgui.ListItem(label=_addon.getLocalizedString(30800)), True)
xbmcplugin.endOfDirectory(_id)