forked from oe-mirrors/e2m3u2bouquet-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproviders.py
362 lines (306 loc) · 19.2 KB
/
providers.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
from __future__ import absolute_import, print_function
import os
import xml.etree.cElementTree as ET
import six
from Components.ActionMap import ActionMap
from Components.Button import Button
from Components.config import ConfigEnableDisable, ConfigPassword, ConfigSelection, ConfigText, ConfigYesNo, getConfigListEntry
from Components.ConfigList import ConfigListScreen
from Components.Label import Label
from Components.Sources.List import List
from enigma import eTimer
from Screens.MessageBox import MessageBox
from Screens.Screen import Screen
from Tools.Directories import SCOPE_ACTIVE_SKIN, SCOPE_CURRENT_SKIN, resolveFilename
from Tools.LoadPixmap import LoadPixmap
from . import _, e2m3u2bouquet, log
ENIGMAPATH = '/etc/enigma2/'
CFGPATH = os.path.join(ENIGMAPATH, 'e2m3u2bouquet/')
class E2m3u2b_Providers(Screen):
skin = """
<screen position="center,center" size="600,500">
<widget name="key_red" position="0,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
<widget name="key_green" position="140,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
<ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" transparent="1" alphatest="on" />
<ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" transparent="1" alphatest="on" />
<widget source="list" render="Listbox" position="10,50" size="580,430" scrollbarMode="showOnDemand">
<convert type="TemplatedMultiContent">
{"template": [
MultiContentEntryPixmapAlphaTest(pos = (10, 0), size = (32, 32), png = 0),
MultiContentEntryText(pos = (47, 0), size = (400, 30), font=0, flags = RT_HALIGN_LEFT|RT_VALIGN_TOP, text = 1),
MultiContentEntryText(pos = (450, 0), size = (120, 30), font=0, flags = RT_HALIGN_LEFT|RT_VALIGN_TOP, text = 2),
],
"fonts": [gFont("Regular",22)],
"itemHeight": 30
}
</convert>
</widget>
<widget name="pleasewait" position="10,60" size="580,140" font="Regular;18" halign="center" valign="center" transparent="0" zPosition="5"/>
<widget name="no_providers" position="10,50" size="580,430" font="Regular;18" zPosition="4" />
</screen>
"""
def __init__(self, session):
Screen.__init__(self, session)
self.session = session
self.setTitle(_("IPTV Bouquet Maker - Providers"))
self.skinName = ['E2m3u2b_Providers', 'AutoBouquetsMaker_HideSections']
self.drawList = []
self["list"] = List(self.drawList)
self.activityTimer = eTimer()
try:
self.activityTimer_conn = self.activityTimer.timeout.connect(self.prepare)
except:
self.activityTimer.timeout.get().append(self.prepare)
self["actions"] = ActionMap(["ColorActions", "SetupActions", "MenuActions"],
{
'ok': self.openSelected,
'cancel': self.keyCancel,
'red': self.keyCancel,
'green': self.key_add,
'menu': self.keyCancel
}, -2)
self["key_red"] = Button(_("Cancel"))
self["key_green"] = Button(_("Add"))
self["pleasewait"] = Label()
self['no_providers'] = Label()
self['no_providers'].setText(_("No providers please add one (use green button) or create config.xml file"))
self['no_providers'].hide()
self.onLayoutFinish.append(self.populate)
def populate(self):
self["actions"].setEnabled(False)
self["pleasewait"].setText(_('Please wait...'))
self.activityTimer.start(1)
def prepare(self):
self.activityTimer.stop()
self.e2m3u2b_config = e2m3u2bouquet.Config()
if os.path.isfile(os.path.join(e2m3u2bouquet.CFGPATH, 'config.xml')):
self.e2m3u2b_config.read_config(os.path.join(CFGPATH, 'config.xml'))
self.refresh()
self["pleasewait"].hide()
self["actions"].setEnabled(True)
def keyCancel(self):
self.close()
def key_add(self):
provider = e2m3u2bouquet.ProviderConfig()
provider.name = 'New'
provider.enabled = True
self.e2m3u2b_config.providers[provider.name] = provider
self.session.openWithCallback(self.provider_add_callback, E2m3u2b_Providers_Config, self.e2m3u2b_config, provider)
def openSelected(self):
provider_name = self['list'].getCurrent()[1]
self.session.openWithCallback(self.provider_config_callback, E2m3u2b_Providers_Config, self.e2m3u2b_config, self.e2m3u2b_config.providers[provider_name])
def buildListEntry(self, provider):
if provider.enabled:
try:
pixmap = LoadPixmap(cached=True, path=resolveFilename(SCOPE_ACTIVE_SKIN, 'icons/lock_on.png'))
except:
pixmap = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'skin_default/icons/lock_on.png'))
else:
try:
pixmap = LoadPixmap(cached=True, path=resolveFilename(SCOPE_ACTIVE_SKIN, 'icons/lock_off.png'))
except:
pixmap = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'skin_default/icons/lock_off.png'))
return (pixmap, str(provider.name), '')
def refresh(self):
self.drawList = []
for key, provider in six.iteritems(self.e2m3u2b_config.providers):
self.drawList.append(self.buildListEntry(provider))
self['list'].setList(self.drawList)
if not self.e2m3u2b_config.providers:
self['no_providers'].show()
else:
self['no_providers'].hide()
def provider_config_callback(self):
self.refresh()
def provider_add_callback(self):
if 'New' in self.e2m3u2b_config.providers:
self.e2m3u2b_config.providers.pop('New', None)
self.refresh()
class E2m3u2b_Providers_Config(ConfigListScreen, Screen):
skin = """
<screen position="center,center" size="600,500">
<ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" transparent="1" alphatest="on" />
<ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" transparent="1" alphatest="on" />
<ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" transparent="1" alphatest="on" />
<widget name="key_red" position="0,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
<widget name="key_green" position="140,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
<widget name="key_yellow" position="280,0" size="140,40" valign="center" halign="center" zPosition="4" foregroundColor="white" font="Regular;20" transparent="1" shadowColor="background" shadowOffset="-2,-2" />
<widget name="config" position="10,60" size="590,330" scrollbarMode="showOnDemand" />
<widget name="description" position="10,410" size="590,80" font="Regular;18" halign="center" valign="top" transparent="0" zPosition="1"/>
<widget name="pleasewait" position="10,60" size="590,350" font="Regular;18" halign="center" valign="center" transparent="0" zPosition="2"/>
</screen>"""
def __init__(self, session, providers_config, provider):
Screen.__init__(self, session)
self.session = session
self.e2m3u2b_config = providers_config
self.provider = provider
self.setup_title = _('Provider Configure - {}').format(provider.name)
self.setTitle(self.setup_title)
self.skinName = ["E2m3u2b_Providers_Config", "AutoBouquetsMaker_ProvidersSetup"]
self.onChangedEntry = []
self.list = []
ConfigListScreen.__init__(self, self.list, session=self.session, on_change=self.changedEntry)
self.activityTimer = eTimer()
try:
self.activityTimer_conn = self.activityTimer.timeout.connect(self.prepare)
except:
self.activityTimer.timeout.get().append(self.prepare)
self['actions'] = ActionMap(['SetupActions', 'ColorActions', 'VirtualKeyboardActions', 'MenuActions'],
{
'ok': self.keySave,
'cancel': self.keyCancel,
'red': self.keyCancel,
'green': self.keySave,
'yellow': self.key_delete,
'menu': self.keyCancel,
}, -2)
self['key_red'] = Button(_('Cancel'))
self['key_green'] = Button(_('Save'))
self['key_yellow'] = Button(_('Delete'))
self['description'] = Label()
self['pleasewait'] = Label()
self["config"].onSelectionChanged.append(self.selectionChanged)
self.onLayoutFinish.append(self.populate)
def getCurrentDescription(self):
return self["config"].getCurrent() and len(self["config"].getCurrent()) > 2 and self["config"].getCurrent()[2] or ""
def selectionChanged(self):
if self["config"]:
self["description"].text = self.getCurrentDescription()
def populate(self):
self['actions'].setEnabled(False)
self['pleasewait'].setText(_("Please wait..."))
self.activityTimer.start(1)
def prepare(self):
self.activityTimer.stop()
self.provider_delete = ConfigYesNo(default=False)
self.provider_enabled = ConfigYesNo(default=False)
self.provider_enabled.value = self.provider.enabled
self.provider_name = ConfigText(default='', fixed_size=False, visible_width=20)
self.provider_name.value = self.provider.name if self.provider.name != 'New' else ''
self.provider_settings_level = ConfigSelection(default='simple', choices=[('simple', _('simple')), ('expert', _('expert'))])
self.provider_settings_level.value = self.provider.settings_level
self.provider_m3u_url = ConfigText(default='', fixed_size=False, visible_width=20)
self.provider_m3u_url.value = self.provider.m3u_url
self.provider_epg_url = ConfigText(default='', fixed_size=False, visible_width=20)
self.provider_epg_url.value = self.provider.epg_url
self.provider_username = ConfigText(default='', fixed_size=False)
self.provider_username.value = self.provider.username
self.provider_password = ConfigPassword(default='', fixed_size=False)
self.provider_password.value = self.provider.password
self.provider_multi_vod = ConfigEnableDisable(default=False)
self.provider_multi_vod.value = self.provider.multi_vod
self.provider_picons = ConfigYesNo(default=False)
self.provider_picons.value = self.provider.picons
self.provider_bouquet_pos = ConfigSelection(default='bottom', choices=[('bottom', _('bottom')), ('top', _('top'))])
if self.provider.bouquet_top:
self.provider_bouquet_pos.value = 'top'
self.provider_all_bouquet = ConfigYesNo(default=False)
self.provider_all_bouquet.value = self.provider.all_bouquet
self.provider_iptv_types = ConfigEnableDisable(default=False)
self.provider_iptv_types.value = self.provider.iptv_types
self.provider_streamtype_tv = ConfigSelection(default='', choices=[' ', '1', '4097', '5001', '5002'])
self.provider_streamtype_tv.value = self.provider.streamtype_tv
self.provider_streamtype_vod = ConfigSelection(default='', choices=[' ', '4097', '5001', '5002'])
self.provider_streamtype_vod.value = self.provider.streamtype_vod
# n.b. first option in stream type choice lists is an intentional single space
self.provider_sref_override = ConfigEnableDisable(default=False)
self.provider_sref_override.value = self.provider.sref_override
self.provider_bouquet_download = ConfigEnableDisable(default=False)
self.provider_bouquet_download.value = self.provider.bouquet_download
self.create_setup()
self['pleasewait'].hide()
self['actions'].setEnabled(True)
def create_setup(self):
self.editListEntry = None
self.list = []
indent = '- '
self.list.append(getConfigListEntry(_('Name:'), self.provider_name, _('Provider name')))
self.list.append(getConfigListEntry(_('Delete:'), self.provider_delete, _('Delete provider {}').format(self.provider.name)))
if not self.provider_delete.value:
self.list.append(getConfigListEntry(_('Enabled:'), self.provider_enabled, _('Enable provider {}').format(self.provider.name)))
if self.provider_enabled.value:
self.list.append(getConfigListEntry(_('Setup mode:'), self.provider_settings_level, _('Choose level of settings. Expert shows all options')))
if not self.provider.provider_hide_urls:
self.list.append(getConfigListEntry('M3U url:', self.provider_m3u_url, _('Providers M3U url. USERNAME & PASSWORD will be replaced by values below')))
self.list.append(getConfigListEntry('EPG url:', self.provider_epg_url, _('Providers EPG url. USERNAME & PASSWORD will be replaced by values below')))
self.list.append(getConfigListEntry(_('Username:'), self.provider_username, _('If set will replace USERNAME placeholder in urls')))
self.list.append(getConfigListEntry(_('Password:'), self.provider_password, _('If set will replace PASSWORD placeholder in urls')))
self.list.append(getConfigListEntry('Multi VOD:', self.provider_multi_vod, _('Enable to create multiple VOD bouquets rather than single VOD bouquet')))
self.list.append(getConfigListEntry('Picons:', self.provider_picons, _('Automatically download Picons')))
self.list.append(getConfigListEntry(_("IPTV bouquet position"), self.provider_bouquet_pos, _('Select where to place IPTV bouquets ')))
self.list.append(getConfigListEntry(_('Create all channels bouquet:'), self.provider_all_bouquet, _('Create a bouquet containing all channels')))
if self.provider_settings_level.value == 'expert':
self.list.append(getConfigListEntry(_('All IPTV type:'), self.provider_iptv_types, _('Normally should be left disabled. Setting to enabled may allow recording on some boxes. If you playback issues (e.g. stuttering on channels) set back to disabled')))
self.list.append(getConfigListEntry(_('TV Stream Type:'), self.provider_streamtype_tv, _('Stream type for TV services')))
self.list.append(getConfigListEntry(_('VOD Stream Type:'), self.provider_streamtype_vod, _('Stream type for VOD services')))
self.list.append(getConfigListEntry(_("Override service refs"), self.provider_sref_override, _('Should be left disabled unless you need to use the override.xml to override service refs (e.g. for DVB to IPTV EPG mapping)')))
self.list.append(getConfigListEntry(_("Check providers bouquet"), self.provider_bouquet_download, _('Enable this option to check and use providers custom service refs')))
self['config'].list = self.list
self['config'].setList(self.list)
def changedEntry(self):
self.item = self['config'].getCurrent()
for x in self.onChangedEntry:
# for summary desc
x()
try:
# if an option is changed that has additional config options show or hide these options
if isinstance(self['config'].getCurrent()[1], ConfigYesNo) or isinstance(self['config'].getCurrent()[1], ConfigSelection):
self.create_setup()
except:
pass
def keySave(self):
previous_name = self.provider.name
# if delete is set to true or empty name show message box to confirm deletion
if self.provider_name.value == '' or self.provider_delete.value:
self.session.openWithCallback(self.delete_confirm, MessageBox, _('Confirm deletion of provider {}').format(previous_name))
self.provider.enabled = self.provider_enabled.value
self.provider.name = self.provider_name.value
self.provider.settings_level = self.provider_settings_level.value
self.provider.m3u_url = self.provider_m3u_url.value
self.provider.epg_url = self.provider_epg_url.value
self.provider.username = self.provider_username.value
self.provider.password = self.provider_password.value
self.provider.multi_vod = self.provider_multi_vod.value
self.provider.picons = self.provider_picons.value
if self.provider_bouquet_pos.value == 'top':
self.provider.bouquet_top = True
else:
self.provider.bouquet_top = False
self.provider.all_bouquet = self.provider_all_bouquet.value
self.provider.iptv_types = self.provider_iptv_types.value
self.provider.streamtype_tv = self.provider_streamtype_tv.value.strip()
self.provider.streamtype_vod = self.provider_streamtype_vod.value.strip()
self.provider.sref_override = self.provider_sref_override.value
self.provider.bouquet_download = self.provider_bouquet_download.value
# disable provider if no m3u url
if not self.provider_m3u_url.value:
self.provider.enabled = False
if self.provider_name.value != '' and self.provider_name.value != previous_name:
# update provider dict key if name changed
self.e2m3u2b_config.providers[self.provider_name.value] = self.e2m3u2b_config.providers.pop(previous_name)
print('[e2m3u2b] Provider {} updated'.format(self.provider_name.value), file=log)
# save xml config
self.e2m3u2b_config.write_config()
self.close()
def cancelConfirm(self, result):
if not result:
return
for x in self['config'].list:
x[1].cancel()
self.close()
def keyCancel(self):
self.close()
# TODO detect if provider config screen is closed without saving
#if self['config'].isChanged():
# self.session.openWithCallback(self.cancelConfirm, MessageBox, 'Really close without saving settings?')
#else:
# self.close()
def key_delete(self):
self.session.openWithCallback(self.delete_confirm, MessageBox, _('Confirm deletion of provider {}').format(self.provider.name))
def delete_confirm(self, result):
if not result:
return
print('[e2m3u2b] Provider {} delete'.format(self.provider.name), file=log)
self.e2m3u2b_config.providers.pop(self.provider.name, None)
self.e2m3u2b_config.write_config()
self.close()