-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgui.py
More file actions
8779 lines (7332 loc) · 364 KB
/
gui.py
File metadata and controls
8779 lines (7332 loc) · 364 KB
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# GNU General Public License
# m-TVGuide KODI Addon
# Copyright (C) 2020 Mariusz89B
# Copyright (C) 2018 primaeval
# Copyright (C) 2016 Andrzej Mleczko
# Copyright (C) 2014 Krzysztof Cebulski
# Copyright (C) 2013 Szakalit
# Copyright (C) 2013 Tommy Winther
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see https://www.gnu.org/licenses.
# MIT License
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from __future__ import unicode_literals
import sys
if sys.version_info[0] > 2:
PY3 = True
else:
PY3 = False
if sys.version_info[0] < 3:
from future.utils import bytes_to_native_str as native
if PY3:
import configparser
else:
import ConfigParser
import re, os, datetime, time, platform, threading, shutil
import xbmc, xbmcgui, xbmcvfs, xbmcaddon
import source as src
from unidecode import unidecode
from notification import Notification
from groups import *
from strings import *
import strings as strings2
import streaming
import playService
import requests
import json
from vosd import VideoOSD
from recordService import RecordService
from settingsImportExport import SettingsImp
from skins import Skin
from source import Program, Channel
import collections
from contextlib import contextmanager
MODE_EPG = 'EPG'
MODE_TV = 'TV'
ACTION_LEFT = 1
ACTION_RIGHT = 2
ACTION_UP = 3
ACTION_DOWN = 4
ACTION_PAGE_UP = 5
ACTION_PAGE_DOWN = 6
ACTION_SELECT_ITEM = 7
ACTION_PARENT_DIR = 9
ACTION_PREVIOUS_MENU = 10
ACTION_SHOW_INFO = 11
ACTION_STOP = 13
ACTION_NEXT_ITEM = 14
ACTION_PREV_ITEM = 15
ACTION_GESTURE_SWIPE_LEFT = 511
ACTION_GESTURE_SWIPE_RIGHT = 521
ACTION_GESTURE_SWIPE_UP = 531
ACTION_GESTURE_SWIPE_DOWN = 541
ACTION_TOUCH_TAP = 401
ACTION_MOUSE_LEFT_CLICK = 100
ACTION_MOUSE_RIGHT_CLICK = 101
ACTION_MOUSE_MIDDLE_CLICK = 102
ACTION_MOUSE_WHEEL_UP = 104
ACTION_MOUSE_WHEEL_DOWN = 105
ACTION_MOUSE_MOVE = 107
KEY_NAV_BACK = 92
KEY_CONTEXT_MENU = 117
KEY_HOME = 159
KEY_END = 160
ACTION_GUIDE = 777
ACTION_CLOSE = 1000
KEY_CODEC_INFO = 0
if PY3:
config = configparser.RawConfigParser()
else:
config = ConfigParser.RawConfigParser()
config.read(os.path.join(Skin.getSkinPath(), 'settings.ini'))
ini_chan = config.getint("Skin", "CHANNELS_PER_PAGE")
ini_info = config.getboolean("Skin", "USE_INFO_DIALOG")
try:
skin_separate_category = config.getboolean("Skin", "program_category_separated")
except:
skin_separate_category = False
try:
skin_separate_episode = config.getboolean("Skin", "program_episode_separated")
except:
skin_separate_episode = False
try:
skin_separate_allowed_age_icon = config.getboolean("Skin", "program_allowed_age_icon")
except:
skin_separate_allowed_age_icon = False
try:
skin_separate_director = config.getboolean("Skin", "program_director_separated")
except:
skin_separate_director = False
try:
skin_separate_year_of_production = config.getboolean("Skin", "program_year_of_production_separated")
except:
skin_separate_year_of_production = False
try:
skin_separate_program_progress = config.getboolean("Skin", "program_show_progress_bar")
except:
skin_separate_program_progress = False
try:
skin_separate_program_progress_epg = config.getboolean("Skin", "program_show_progress_bar_epg")
except:
skin_separate_program_progress_epg = False
try:
skin_separate_program_actors = config.getboolean("Skin", "program_show_actors")
except:
skin_separate_program_actors = False
try:
skin_separate_rating = config.getboolean("Skin", "program_show_rating")
except:
skin_separate_rating = False
try:
skin_resolution = config.get("Skin", "resolution")
except:
skin_resolution = '720p'
try:
cell_height = config.get("Skin", "cell_height")
except:
cell_height = ''
try:
cell_width = config.get("Skin", "cell_width")
except:
cell_width = ''
try:
skin_font = config.get("Skin", "font")
except:
skin_font = 'NoFont'
try:
skin_font_colour = config.get("Skin", "font_colour")
except:
skin_font_colour = ''
try:
skin_font_focused_colour = config.get("Skin", "font_focused_colour")
except:
skin_font_focused_colour = ''
try:
skin_timebarback_colour = config.get("Skin", "timebarback_colour")
except:
skin_timebarback_colour = ''
try:
skin_timebar_colour = config.get("Skin", "timebar_colour")
except:
skin_timebar_colour = ''
try:
skin_catchup_size = config.get("Skin", "skin_catchup_size")
except:
skin_catchup_size = 'Default'
try:
KEY_INFO = int(ADDON.getSetting('info_key'))
except:
KEY_INFO = 0
try:
KEY_STOP = int(ADDON.getSetting('stop_key'))
except:
KEY_STOP = 0
try:
KEY_PP = int(ADDON.getSetting('pp_key'))
except:
KEY_PP = 0
try:
KEY_PM = int(ADDON.getSetting('pm_key'))
except:
KEY_PM = 0
try:
KEY_VOL_UP = int(ADDON.getSetting('volume_up_key'))
except:
KEY_VOL_UP = -1
try:
KEY_VOL_DOWN = int(ADDON.getSetting('volume_down_key'))
except:
KEY_VOL_DOWN = -1
try:
KEY_HOME2 = int(ADDON.getSetting('home_key'))
except:
KEY_HOME2 = 0
try:
KEY_CONTEXT = int(ADDON.getSetting('context_key'))
except:
KEY_CONTEXT = -1
try:
KEY_RECORD = int(ADDON.getSetting('record_key'))
except:
KEY_RECORD = -1
try:
KEY_LIST = int(ADDON.getSetting('list_key'))
except:
KEY_LIST = -1
try:
KEY_SWITCH_TO_LAST = int(ADDON.getSetting('switch_to_last_key'))
except:
KEY_SWITCH_TO_LAST = -1
CHANNELS_PER_PAGE = ini_chan
HALF_HOUR = datetime.timedelta(minutes=30)
AUTO_OSD = 666
REFRESH_STREAMS_TIME = 14400
def category_formatting(label):
label = re.sub('^0$', '1.png', label)
label = re.sub('^1$', '2.png', label)
label = re.sub('^2$', '3.png', label)
label = re.sub('^3$', '4.png', label)
label = re.sub('^4$', '5.png', label)
label = re.sub('^5$', '6.png', label)
label = re.sub('^6$', '7.png', label)
label = re.sub('^7$', '8.png', label)
label = re.sub('^8$', '9.png', label)
return label
def background_formatting(label):
label = re.sub('^0$', '9.png', label)
return label
def focus_formatting(label):
label = re.sub('^0$', '10.png', label)
label = re.sub('^1$', '13.png', label)
label = re.sub('^2$', '14.png', label)
label = re.sub('^3$', '15.png', label)
label = re.sub('^4$', '16.png', label)
return label
def notifications_formatting(label):
label = re.sub('^0$', '11.png', label)
label = re.sub('^1$', '13.png', label)
label = re.sub('^2$', '14.png', label)
label = re.sub('^3$', '15.png', label)
return label
def recordings_formatting(label):
label = re.sub('^0$', '12.png', label)
label = re.sub('^1$', '13.png', label)
label = re.sub('^2$', '14.png', label)
label = re.sub('^3$', '15.png', label)
return label
def replace_formatting(label):
label = re.sub(r"\s\$ADDON\[script.mtvguide.*?\]\.", '', label)
label = re.sub(r"\$ADDON\[script.mtvguide.*?\]", '[B]N/A', label)
return label
def timedelta_total_seconds(timedelta):
return (timedelta.microseconds + 0.0 + (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) // 10 ** 6
def timebarAdjust():
timebar_adjust = ADDON.getSetting('timebar_adjust')
if timebar_adjust == '' or timebar_adjust is None:
timebar_adjust = 0
return timebar_adjust
def getDistro():
if xbmc.getCondVisibility('System.HasAddon(service.coreelec.settings)'):
return "CoreElec"
elif xbmc.getCondVisibility('System.HasAddon(service.libreelec.settings)'):
return "LibreElec"
elif xbmc.getCondVisibility('System.HasAddon(service.osmc.settings)'):
return "OSMC"
else:
return "Kodi"
def formatFileSize(size):
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
if size < 1024.0:
return "%3.1f %s" % (size, x)
size /= 1024.0
return size
class proxydt(datetime.datetime):
@staticmethod
def strptime(date_string, format):
import time
try:
res = datetime.datetime.strptime(date_string, format)
except:
res = datetime.datetime(*(time.strptime(date_string, format)[0:6]))
return res
datetime.proxydt = proxydt
class Point(object):
def __init__(self):
self.x = self.y = 0
def __repr__(self):
return 'Point(x={}, y={})'.format(self.x, self.y)
class EPGView(object):
def __init__(self):
self.top = self.left = self.right = self.bottom = self.width = self.cellHeight = 0
class ControlAndProgram(object):
def __init__(self, control, program):
self.control = control
self.program = program
class Event:
def __init__(self):
self.handlers = set()
def handle(self, handler):
self.handlers.add(handler)
return self
def unhandle(self, handler):
try:
self.handlers.remove(handler)
except:
raise ValueError("Handler is not handling this event, so cannot unhandle it.")
return self
def fire(self, *args, **kargs):
for handler in self.handlers:
handler(*args, **kargs)
def getHandlerCount(self):
return len(self.handlers)
__iadd__ = handle
__isub__ = unhandle
__call__ = fire
__len__ = getHandlerCount
class epgTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = threading.Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
def is_alive(self):
self._timer.is_alive()
class VideoPlayerStateChange(xbmc.Player):
def __init__(self, *args, **kwargs):
deb("################ Starting control VideoPlayer events ################")
self.playerStateChanged = Event()
self.updatePositionTimerData = {}
self.recordedFilesPositions = {}
self.updatePositionTimer = None
self.stopped = False
def setPlaylistPositionFile(self, recordedFilesPositions):
self.recordedFilesPlaylistPositions = recordedFilesPositions
def stopplaying(self):
self.updatePositionTimerData['stop'] = True
self.Stop()
def onStateChange(self, state):
self.playerStateChanged(state)
def onPlayBackError(self):
deb("################ PlayBackError ################")
self.updatePositionTimerData['stop'] = True
self.onStateChange("PlayBackError")
ADDON.setSetting('vosd.arg', 'false')
def onPlayBackPaused(self):
deb("################ Im paused ################")
# self.playerStateChanged("Paused")
# threading.Timer(0.3, self.stopplaying).start()
def onPlayBackResumed(self):
deb("################ Im Resumed ################")
# self.onStateChange("Resumed")
def onPlayBackStarted(self):
deb("################ Playback Started ################")
self.updatePositionTimerData['stop'] = True
self.onStateChange("Started")
try:
playedFile = xbmc.Player().getPlayingFile()
if os.path.isfile(playedFile):
try:
playlistFileName = re.sub('_part_\d*.mpeg', '.mpeg', playedFile)
currentPositionInPlaylist = int(xbmc.PlayList(xbmc.PLAYLIST_VIDEO).getposition())
self.recordedFilesPlaylistPositions[playlistFileName] = currentPositionInPlaylist
deb('onPlayBackStarted updating playlist position to: {} file: {}'.format(currentPositionInPlaylist, playlistFileName))
except:
pass
try:
seek = int(self.recordedFilesPositions[playedFile])
deb('onPlayBackStarted seeking file: {}, for {} seconds'.format(playedFile, seek))
time.sleep(1)
xbmc.Player().seekTime(seek)
except:
pass
self.updatePositionTimerData = {'filename': playedFile, 'stop': False}
self.updatePositionTimer = threading.Timer(10, self.updatePosition, [self.updatePositionTimerData])
self.updatePositionTimer.start()
except:
pass
def onPlayBackEnded(self):
xbmc.sleep(100)
deb("################# Playback Ended #################")
self.updatePositionTimerData['stop'] = True
self.onStateChange("Ended")
ADDON.setSetting('vosd.arg', 'false')
def onPlayBackStopped(self):
xbmc.sleep(100)
deb("################# Playback Stopped #################")
self.updatePositionTimerData['stop'] = True
self.onStateChange("Stopped")
ADDON.setSetting('vosd.arg', 'false')
def updatePosition(self, updatePositionTimerData):
try:
fileName = updatePositionTimerData['filename']
while updatePositionTimerData['stop'] == False:
self.recordedFilesPositions[fileName] = xbmc.Player().getTime()
for sleepTime in range(5):
if updatePositionTimerData['stop'] == True:
break
time.sleep(1)
except:
pass
def close(self):
self.updatePositionTimerData['stop'] = True
if self.updatePositionTimer is not None:
self.updatePositionTimer.cancel()
class mTVGuide(xbmcgui.WindowXML):
C_MAIN_DATE = 4000
C_MAIN_TIMEBAR = 4100
C_MAIN_TIMEBAR_BACK = 4101
C_MAIN_LOADING = 4200
C_MAIN_LOADING_BACKGROUND = 4199
C_MAIN_LOADING_PROGRESS = 4201
C_MAIN_LOADING_TIME_LEFT = 4202
C_MAIN_LOADING_CANCEL = 4203
C_MAIN_MOUSEPANEL_CONTROLS = 4300
C_MAIN_MOUSEPANEL_HOME = 4301
C_MAIN_MOUSEPANEL_EPG_PAGE_LEFT = 4302
C_MAIN_MOUSEPANEL_EPG_PAGE_UP = 4303
C_MAIN_MOUSEPANEL_EPG_PAGE_DOWN = 4304
C_MAIN_MOUSEPANEL_EPG_PAGE_RIGHT = 4305
C_MAIN_MOUSEPANEL_EXIT = 4306
C_MAIN_MOUSEPANEL_CURSOR_UP = 4307
C_MAIN_MOUSEPANEL_CURSOR_DOWN = 4308
C_MAIN_MOUSEPANEL_CURSOR_LEFT = 4309
C_MAIN_MOUSEPANEL_CURSOR_RIGHT = 4310
C_MAIN_MOUSEPANEL_SETTINGS = 4311
C_MAIN_BACKGROUND = 4600
C_MAIN_EPG = 5000
C_MAIN_EPG_VIEW_MARKER = 5001
C_MAIN_INFO = 7000
C_MAIN_LIVE = 4944
C_CHANNEL_LABEL_START_INDEX_SHORTCUT = 4010
C_CHANNEL_IMAGE_START_INDEX_SHORTCUT = 4110
C_CHANNEL_NUMBER_START_INDEX_SHORTCUT = 4410
C_CHANNEL_LABEL_START_INDEX = 4510
C_CHANNEL_IMAGE_START_INDEX = 4210
C_DYNAMIC_COLORS = 4500
C_MAIN_CATEGORY = 7900
C_MAIN_CALC_TIME_EPG = 4232
C_MAIN_DAY = 4960
C_MAIN_REAL_DATE = 4961
C_MAIN_CALC_TIME_EPG = 4232
C_MAIN_SLIDE = 4975
C_MAIN_SLIDE_CLICK = 4976
def __new__(cls):
return super(mTVGuide, cls).__new__(cls, 'script-tvguide-main.xml', Skin.getSkinBasePath(), Skin.getSkinName(), defaultRes=skin_resolution)
def __init__(self):
deb('')
deb('###################################################################################')
deb('')
deb('m-TVGuide __init__ System: {}, ARH: {}, python: {}, version: {}, kodi: {}'.format(platform.system(),
platform.machine(),
platform.python_version(),
ADDON.getAddonInfo(
'version'),
xbmc.getInfoLabel(
'System.BuildVersion')))
deb('')
deb('###################################################################################')
deb('')
super(mTVGuide, self).__init__()
self.database = None
self.notification = None
self.infoDialog = None
self.currentChannel = None
self.lastChannel = None
self.program = None
self.onFocusTimer = None
self.updateTimebarTimer = None
self.rssFeed = None
self.timer = None
self.initialized = False
self.redrawingEPG = False
self.isClosing = False
self.redrawagain = False
self.info = False
self.osd = None
self.timebar = None
self.timebarBack = None
self.dontBlockOnAction = False
self.playingRecordedProgram = False
self.blockInputDueToRedrawing = False
self.channelIdx = 0
self.focusPoint = Point()
self.epgView = EPGView()
self.a = {}
self.mode = MODE_EPG
self.channel_number_input = False
self.channel_number = ADDON.getSetting('channel.arg')
self.current_channel_id = None
self.controlAndProgramList = []
self.ignoreMissingControlIds = []
self.recordedFilesPlaylistPositions = {}
self.streamingService = streaming.StreamsService()
self.playService = playService.PlayService()
self.recordService = RecordService(self)
self.settingsImp = SettingsImp()
self.predefinedCategories = []
self.getListLenght = []
self.catchupChannels = None
self.context = False
# find nearest half hour
self.viewStartDate = datetime.datetime.today() + datetime.timedelta(minutes=int(timebarAdjust()))
self.viewStartDate -= datetime.timedelta(minutes=self.viewStartDate.minute % 30, seconds=self.viewStartDate.second)
self.start = 0
self.end = 0
self.played = 0
self.lastKeystroke = datetime.datetime.now()
self.lastCloseKeystroke = datetime.datetime.now()
# monitorowanie zmiany stanu odtwarzacza
threading.Timer(0.3, self.playerstate).start()
self.autoUpdateCid = ADDON.getSetting('AutoUpdateCid')
self.archiveService = ''
self.archivePlaylist = ''
self.ignoreMissingControlIds.append(C_MAIN_CHAN_NAME)
self.ignoreMissingControlIds.append(C_MAIN_CHAN_PLAY)
self.ignoreMissingControlIds.append(C_MAIN_PROG_PLAY)
self.ignoreMissingControlIds.append(C_MAIN_TIME_PLAY)
self.ignoreMissingControlIds.append(C_MAIN_NUMB_PLAY)
self.ignoreMissingControlIds.append(self.C_MAIN_CALC_TIME_EPG)
self.ignoreMissingControlIds.append(self.C_MAIN_CATEGORY)
self.ignoreMissingControlIds.append(self.C_DYNAMIC_COLORS)
if PY3:
try:
self.profilePath = xbmcvfs.translatePath(ADDON.getAddonInfo('profile'))
except:
self.profilePath = xbmcvfs.translatePath(ADDON.getAddonInfo('profile')).decode('utf-8')
else:
try:
self.profilePath = xbmc.translatePath(ADDON.getAddonInfo('profile'))
except:
self.profilePath = xbmc.translatePath(ADDON.getAddonInfo('profile')).decode('utf-8')
if PY3:
self.kodiPath = xbmcvfs.translatePath("special://home/")
self.kodiPathMain = xbmcvfs.translatePath("special://xbmc/")
self.kodiSkinPath = xbmcvfs.translatePath("special://skin/")
else:
self.kodiPath = xbmc.translatePath("special://home/")
self.kodiPathMain = xbmc.translatePath("special://xbmc/")
self.kodiSkinPath = xbmc.translatePath("special://skin/")
if ADDON.getSetting('refresh_streams') == 'true':
self.refreshStreamsTimer = threading.Timer(REFRESH_STREAMS_TIME, self.refreshStreamsLoop)
self.refreshStreamsTimer.start()
else:
self.refreshStreamsTimer = None
if ADDON.getSetting('skin_fontpack') == 'true':
self.skinsFix()
self.changeFonts()
self.loadSettings()
self.tutorialExec()
self.cat_index = 0
self.interval = 0
def restartKodi(self):
androidOS = xbmc.getCondVisibility('system.platform.android')
iOS = xbmc.getCondVisibility('system.platform.ios')
macOS = xbmc.getCondVisibility('system.platform.osx')
atvOS = xbmc.getCondVisibility('system.platform.atv2')
if androidOS:
xbmc.executebuiltin("Quit")
else:
if getDistro() == 'Kodi':
xbmc.executebuiltin("RestartApp")
else:
xbmc.executebuiltin("Reboot")
def exitAddon(self):
exit()
def tutorialGetEPG(self):
res = xbmcgui.Dialog().select(strings(59940), [strings(59906), strings(59908)])
if res < 0:
res = xbmcgui.Dialog().yesno(strings(59924), strings(59938))
if res:
ADDON.setSetting('m-TVGuide', 'https://')
ADDON.setSetting('xmltv_file', '')
ADDON.setSetting('tutorial', 'true')
self.exitAddon()
else:
self.tutorialGetEPG()
if res == 0:
ADDON.setSetting('source', '1')
self.tutorialGetCountryUrl()
elif res == 1:
ADDON.setSetting('source', '0')
self.tutorialGetCountryFile()
def tutorialGetCountryUrl(self):
with self.busyDialog():
progExec = self.settingsImp.countryUrlPicker(execute=ADDON, options=False)
if progExec:
self.tutorialGetService(epgType=0)
else:
self.tutorialGetEPG()
def tutorialGetCountryFile(self):
with self.busyDialog():
progExec = self.settingsImp.countryFilePicker(execute=ADDON, options=False)
if progExec:
self.tutorialGetService(epgType=1)
else:
self.tutorialGetEPG()
def tutorialGetService(self, epgType):
progExec = False
res = xbmcgui.Dialog().multiselect(strings(59946), [strings(59947), strings(59948)])
if not res:
resBack = xbmcgui.Dialog().yesno(strings(59924), strings(59938), yeslabel=strings(59939), nolabel=strings(30308))
if resBack:
if epgType == 0:
self.tutorialGetCountryUrl()
elif epgType == 1:
self.tutorialGetCountryFile()
else:
ADDON.setSetting('tutorial', 'true')
self.exitAddon()
for p in res:
if p == 0:
res = xbmcgui.Dialog().multiselect(strings(59949), ['C More', 'Ipla', 'nc+ GO', 'PlayerPL', 'Polsat GO', 'Polsat GO Box', 'TVP GO', 'Telia Play', 'WP Pilot'])
if not res:
resBack = xbmcgui.Dialog().yesno(strings(59924), strings(59938), yeslabel=strings(59939), nolabel=strings(30308))
if resBack:
self.tutorialGetService(epgType)
else:
ADDON.setSetting('tutorial', 'true')
self.exitAddon()
for s in res:
if s == 0:
label = 'C More'
xbmcgui.Dialog().ok(label, strings(59950).format(label))
ADDON.setSetting('cmore_enabled', 'true')
response = xbmcgui.Dialog().yesno(label, strings(59951))
if response:
ADDON.setSetting('cmore_tv_provider_login', 'true')
progExec = True
else:
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59952) + ' ({})'.format(label))
kb.setHiddenInput(False)
kb.doModal()
login = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if login == '': login = self.tutorialGetService(epgType)
if login != '':
ADDON.setSetting('cmore_username', login)
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59953) + ' ({})'.format(label))
kb.setHiddenInput(True)
kb.doModal()
pswd = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if pswd == '': pswd = self.tutorialGetService(epgType)
ADDON.setSetting('cmore_password', pswd)
if pswd != '':
progExec = True
else:
ADDON.setSetting('cmore_enabled', 'false')
self.tutorialGetService(epgType)
else:
ADDON.setSetting('cmore_enabled', 'false')
self.tutorialGetService(epgType)
if s == 1:
label = 'Ipla'
xbmcgui.Dialog().ok(label, strings(59950).format(label))
ADDON.setSetting('ipla_enabled', 'true')
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59952) + ' ({})'.format(label))
kb.setHiddenInput(False)
kb.doModal()
login = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if login == '': login = self.tutorialGetService(epgType)
if login != '':
ADDON.setSetting('ipla_username', login)
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59953) + ' ({})'.format(label))
kb.setHiddenInput(True)
kb.doModal()
pswd = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if pswd == '': pswd = self.tutorialGetService(epgType)
ADDON.setSetting('ipla_password', pswd)
if pswd != '':
progExec = True
res = xbmcgui.Dialog().select(strings(95014), ['Ipla', 'Cyfrowy Polsat'])
if res < 0:
ADDON.setSetting('ipla_enabled', 'false')
self.tutorialGetService(epgType)
if res == 0:
ADDON.setSetting('ipla_client', 'Ipla')
elif res == 1:
ADDON.setSetting('ipla_client', 'Cyfrowy Polsat')
else:
ADDON.setSetting('ipla_enabled', 'false')
self.tutorialGetService(epgType)
else:
ADDON.setSetting('ipla_enabled', 'false')
self.tutorialGetService(epgType)
if s == 2:
label = 'nc+ GO'
xbmcgui.Dialog().ok(label, strings(59950).format(label))
ADDON.setSetting('ncplusgo_enabled', 'true')
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59952) + ' ({})'.format(label))
kb.setHiddenInput(False)
kb.doModal()
login = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if login == '': login = self.tutorialGetService(epgType)
if login != '':
ADDON.setSetting('ncplusgo_username', login)
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59953) + ' ({})'.format(label))
kb.setHiddenInput(True)
kb.doModal()
pswd = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if pswd == '': pswd = self.tutorialGetService(epgType)
ADDON.setSetting('ncplusgo_password', pswd)
if pswd != '':
progExec = True
else:
ADDON.setSetting('ncplusgo_enabled', 'false')
self.tutorialGetService(epgType)
else:
ADDON.setSetting('ncplusgo_enabled', 'false')
self.tutorialGetService(epgType)
if s == 3:
label = 'PlayerPL'
xbmcgui.Dialog().ok(label, label + ' ' + strings(30733).lower())
ADDON.setSetting('playerpl_enabled', 'true')
progExec = True
if s == 4:
label = 'Polsat GO'
xbmcgui.Dialog().ok(label, strings(59950).format(label))
ADDON.setSetting('polsatgo_enabled', 'true')
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59952) + ' ({})'.format(label))
kb.setHiddenInput(False)
kb.doModal()
login = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if login == '': login = self.tutorialGetService(epgType)
if login != '':
ADDON.setSetting('polsatgo_username', login)
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59953) + ' ({})'.format(label))
kb.setHiddenInput(True)
kb.doModal()
pswd = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if pswd == '': pswd = self.tutorialGetService(epgType)
ADDON.setSetting('polsatgo_password', pswd)
if pswd != '':
progExec = True
res = xbmcgui.Dialog().select(strings(95014), ['Ipla', 'Polsat Box'])
if res < 0:
ADDON.setSetting('polsatgo_enabled', 'false')
self.tutorialGetService(epgType)
elif res == 0:
ADDON.setSetting('polsatgo_client', 'Ipla')
elif res == 1:
ADDON.setSetting('polsatgo_client', 'Polsat Box')
else:
ADDON.setSetting('polsatgo_enabled', 'false')
self.tutorialGetService(epgType)
else:
ADDON.setSetting('polsatgo_enabled', 'false')
self.tutorialGetService(epgType)
if s == 5:
label = 'Polsat GO Box'
xbmcgui.Dialog().ok(label, strings(59950).format(label))
ADDON.setSetting('pgobox_enabled', 'true')
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59952) + ' ({})'.format(label))
kb.setHiddenInput(False)
kb.doModal()
login = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if login == '': login = self.tutorialGetService(epgType)
if login != '':
ADDON.setSetting('pgobox_username', login)
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59953) + ' ({})'.format(label))
kb.setHiddenInput(True)
kb.doModal()
pswd = kb.getText() if kb.isConfirmed() else self.tutorialGetService(epgType)
if pswd == '': pswd = self.tutorialGetService(epgType)
ADDON.setSetting('pgobox_password', pswd)
if pswd != '':
progExec = True
res = xbmcgui.Dialog().select(strings(95014), ['Cyfrowy Polsat', 'Ipla', 'Polsat Box'])
if res < 0:
ADDON.setSetting('pgobox_enabled', 'false')
self.tutorialGetService(epgType)
if res == 0:
ADDON.setSetting('pgobox_client', 'Cyfrowy Polsat')
elif res == 1:
ADDON.setSetting('pgobox_client', 'Ipla')
elif res == 2:
ADDON.setSetting('pgobox_client', 'Polsat Box')
else:
ADDON.setSetting('pgobox_enabled', 'false')
self.tutorialGetService(epgType)
else:
ADDON.setSetting('pgobox_enabled', 'false')
self.tutorialGetService(epgType)
if s == 6:
label = 'TVP GO'
xbmcgui.Dialog().ok(label, label + ' ' + strings(30733).lower())
ADDON.setSetting('tvpgo_enabled', 'true')
progExec = True
if s == 7:
label = 'Telia Play'
xbmcgui.Dialog().ok(label, strings(59950).format(label))
ADDON.setSetting('teliaplay_enabled', 'true')
kb = xbmc.Keyboard('','')
kb.setHeading(strings(59952) + ' ({})'.format(label))
kb.setHiddenInput(False)