-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddon.py
1808 lines (1468 loc) · 55.5 KB
/
addon.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
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
# -*- coding: utf-8 -*-
"""
Macedonia On Demand XBMC addon.
Watch videos and live streams from Macedonian TV stations, and listen to live radio streams.
Author: Viktor Mladenovski
"""
import urllib,urllib2,re,xbmcplugin,xbmcaddon,xbmcgui,HTMLParser,json
import sys,os,os.path
user_agent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:11.0) Gecko/20100101 Firefox/11.0'
str_accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
ADDON=__settings__ = xbmcaddon.Addon(id='plugin.video.macedoniaondemand')
DIR_USERDATA = xbmc.translatePath(ADDON.getAddonInfo('profile'))
VERSION_FILE = DIR_USERDATA+'version.txt'
VISITOR_FILE = DIR_USERDATA+'visitor.txt'
VOLIMTV_UID = DIR_USERDATA+'volimtvuid.txt'
VOLIMTV_PWD = DIR_USERDATA+'volimtvpwd.txt'
__version__ = ADDON.getAddonInfo("version")
if not os.path.isdir(DIR_USERDATA):
os.makedirs(DIR_USERDATA)
def platformdef():
if xbmc.getCondVisibility('system.platform.osx'):
if xbmc.getCondVisibility('system.platform.atv2'):
log_path = '/var/mobile/Library/Preferences'
log = os.path.join(log_path, 'xbmc.log')
logfile = open(log, 'r').read()
else:
log_path = os.path.join(os.path.expanduser('~'), 'Library/Logs')
log = os.path.join(log_path, 'xbmc.log')
logfile = open(log, 'r').read()
elif xbmc.getCondVisibility('system.platform.ios'):
log_path = '/var/mobile/Library/Preferences'
log = os.path.join(log_path, 'xbmc.log')
logfile = open(log, 'r').read()
elif xbmc.getCondVisibility('system.platform.windows'):
log_path = xbmc.translatePath('special://home')
log = os.path.join(log_path, 'xbmc.log')
logfile = open(log, 'r').read()
elif xbmc.getCondVisibility('system.platform.linux'):
log_path = xbmc.translatePath('special://home/temp')
log = os.path.join(log_path, 'xbmc.log')
logfile = open(log, 'r').read()
else:
logfile='Starting XBMC (Unknown Git:.+?Platform: Unknown. Built.+?'
match=re.compile('Starting XBMC \((.+?) Git:.+?Platform: (.+?)\. Built.+?').findall(logfile)
for build, platform in match:
if re.search('12.0',build,re.IGNORECASE):
build="Frodo"
if re.search('11.0',build,re.IGNORECASE):
build="Eden"
if re.search('13.0',build,re.IGNORECASE):
build="Gotham"
return platform
return "Unknown"
def fread(filename):
ver = ''
h = open(filename, "r")
try:
data = h.read()
finally:
h.close()
return data
def fwrite(filename, data):
h = open(filename, "wb")
try:
h.write(data)
finally:
h.close()
def get_visitorid():
if os.path.isfile(VISITOR_FILE):
visitor_id = fread(VISITOR_FILE)
else:
from random import randint
visitor_id = str(randint(0, 0x7fffffff))
fwrite(VISITOR_FILE, visitor_id)
return visitor_id
__visitor__ = get_visitorid()
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
def setView(content='movies', mode=503):
return 0
# xbmcplugin.setContent(int(sys.argv[1]), content)
# xbmc.executebuiltin("Container.SetViewMode("+str(mode)+")")
# ZULU live
def createZuluListing():
url='http://on.net.mk/zulu_tv.aspx'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('<a href="(.+?)" > *?<img src="(.+?)" class="imgclassresponsive"').findall(link)
#for station, thumb in match:
# print station, thumb
return match
def playZuluStream(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('Zulu Stream', 'Initializing')
pDialog.update(30, 'Fetching video stream')
req = urllib2.Request('http://on.net.mk/'+url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
nextframe = re.compile('<iframe src="(.+?)"').findall(link)
pDialog.update(60, 'Fetching video stream')
req = urllib2.Request('http://on.net.mk/'+nextframe[0])
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link = response.read()
response.close()
streammatch=re.compile('<video .+? src="(.+?)"').findall(link)
pDialog.update(80, 'Playing')
#playurl(streammatch[0].replace('_2/', '_1/'))
playurl(streammatch[0])
return True
# TELEKABEL live
def createTelekabelListing():
url='http://telekabel.com.mk/index.php/mk/%D1%81%D1%82%D1%80%D0%B8%D0%BC%D0%B8%D0%BD%D0%B3?view=featured'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
req.add_header('Accept', str_accept)
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('<li class="level2.+?"><a href=\"(.+?)\".+?<span>(.+?)</span></a></li>').findall(link)
return match
def playTelekabelStream(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('Telekabel Stream', 'Initializing')
req = urllib2.Request('http://telekabel.com.mk'+url)
req.add_header('User-Agent', user_agent)
req.add_header('Accept', str_accept)
pDialog.update(30, 'Fetching video stream 30%')
response = urllib2.urlopen(req)
link = response.read()
response.close()
nextframematch = re.compile('name="iframe"\n\t\tsrc="(.+?)"').findall(link)
req = urllib2.Request('http://telekabel.com.mk'+nextframematch[0])
req.add_header('User-Agent', user_agent)
req.add_header('Accept', str_accept)
pDialog.update(60, 'Fetching video stream 60%')
response = urllib2.urlopen(req)
link = response.read()
streammatch = re.compile("file:'(.+?)'").findall(link)
pDialog.update(80, 'Playing')
playurl(streammatch[0])
pDialog.close()
return True
# OFF NET methods
def createOffnetRadioListing():
url='http://off.net.mk/radio'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('<a class=".+?" data-id=".+?" data-stream="(.+?)" data-frequency="(.*?)">(.+?)</a>').findall(link[link.find('block-views-live-stream-block'):])
#for stream,freq,name in match:
# print freq+" "+name+" "+stream
return match
# 24 Vesti methods
def play24VestiVesti():
pDialog = xbmcgui.DialogProgress()
pDialog.create('24 Vesti', 'Initializing')
url='http://24vesti.mk/video/vesti'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
pDialog.update(50, 'Finding stream')
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('file: "(.+?)"').findall(link)
pDialog.update(80, 'Playing')
playurl('http://24vesti.com.mk'+match[0]+'|Cookie=macedoniaondemand')
pDialog.close()
return True
def create24VestiEmisiiListing(urlpagenr):
if urlpagenr == None or urlpagenr == '':
url = 'http://24vesti.mk/video/emisii'
else:
url = 'http://24vesti.mk/video/emisii?page='+urlpagenr
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('<div class="views-field views-field-field-teaser-image-fid">.+?<a href="(.+?)" .+?><img src="(.+?)" .+? \n .+? \n .+?<a href=".+?">(.+?)</a>.+?').findall(link)
#for u,thumb,title in match:
# print title
return match
def create24VestiVideoSodrzina():
url='http://24vesti.mk/'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('<span class="field-content"><div class="text-wrap">\n <div class="views-field-title"><a href="(.+?)" class="imagecache imagecache-teaser-medium-wide imagecache-linked imagecache-teaser-medium-wide_linked"><img src="(.+?)" .+?\n <div class="video-flag">(.+?)</div>\n <div class="views-field-title"><a href=".+?">(.+?)</a></div>\n</div></span> </div></li>\n').findall(link)
#for u,thumb,title1,title2 in match:
# print title2.strip()
return match
def play24VestiVideo(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('24Vesti Video', 'Initializing')
req = urllib2.Request('http://24vesti.com.mk/'+str(url))
req.add_header('User-Agent', user_agent)
pDialog.update(30, 'Fetching video stream')
response = urllib2.urlopen(req)
link = response.read()
response.close()
filematch = re.compile('<param name="movie" value="(.+?)"').findall(link)
titlematch = re.compile('<title>(.+?)</title>').findall(link)
if filematch[0].__contains__('dailymotion'):
stream = 'plugin://plugin.video.dailymotion_com/?url='+filematch[0].split('/')[-1].split('&')[0]+'&mode=playVideo'
elif filematch[0].__contains__('youtube'):
stream = 'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid='+filematch[0].split('/')[-1].split('&')[0]
else:
stream = filematch[0]
pDialog.update(60, 'Playing')
playurl(stream)
pDialog.close()
return True
# NOVATV methods
def createNovatvListing(page):
url = 'http://novatv.mk/index.php?navig=8&cat='
if page == 'novatv_makedonija':
url += '2'
elif page == 'novatv_evrozum':
url += '9'
elif page == 'novatv_sekulovska':
url += '8'
elif page == 'novatv_dokument':
url += '14'
elif page == 'novatv_studio':
url += '16'
elif page == 'novatv_aktuel':
url += '18'
elif page == 'novatv_globus':
url += '17'
elif page == 'novatv_kultura':
url += '4'
elif page == 'novatv_zanimlivosti':
url += '1'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link = response.read()
response.close()
match=re.compile('<a class="ostanati_wrap" href="(.+?)"> \t \t\r\n \t .+? \r\n \t <img src="(.+?)" .+? />\r\n \t <h2 style="color:black;">(.+?)</h2>\r\n \t <p>(.+?)</p>\r\n \t.+?<div class="more" style=".+?">.+?</div> \r\n \t <div class=".+?" style=".+?">(.+?)</div> </div>\r\n \t </div>\r\n \t </a>').findall(link)
return match
def playNovatvVideo(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('Nova Tv Video', 'Initializing')
req = urllib2.Request('http://novatv.mk/'+str(url))
req.add_header('User-Agent', user_agent)
pDialog.update(30, 'Fetching video stream')
response = urllib2.urlopen(req)
link = response.read()
response.close()
playlist=xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist.clear()
player = xbmc.Player(xbmc.PLAYER_CORE_AUTO)
filematch = re.compile('<iframe style=".+?" title="YouTube video player" class="youtube-player" type="text/html" \r\n\r\nwidth=".+?" height=".+?" src="(.+?)" frameborder="0" allowfullscreen></iframe>').findall(link)
if filematch != []:
titlematch = re.compile('<h2 class="news_title" >(.+?)</h2>').findall(link)
listitem = xbmcgui.ListItem(titlematch[0]);
if filematch[0].__contains__('dailymotion'):
playlist.add('plugin://plugin.video.dailymotion_com/?url='+filematch[0].split('/')[-1]+'&mode=playVideo', listitem)
elif filematch[0].__contains__('youtube'):
playlist.add('plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid='+filematch[0].split('?')[0].split('/')[-1], listitem)
else:
playlist.add(filematch[0], listitem)
filematch = re.compile('<iframe width=".+?" height=".+?" src="(.+?)" frameborder=".+?" allowfullscreen></iframe>').findall(link)
if filematch != []:
titlematch = re.compile('<h2 class="news_title" >(.+?)</h2>').findall(link)
listitem = xbmcgui.ListItem(titlematch[0]);
oldurl=''
for u in filematch:
if u.__contains__('youtube') and u != oldurl:
listitem = xbmcgui.ListItem('video')
#listitem.setProperty("PlayPaty", u)
playlist.add('plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid='+u.split('/')[-1], listitem)
oldurl=u
if playlist.size() != 0:
pDialog.update(60, 'Playing')
player.play(playlist)
pDialog.close()
return True
# RADIOMK methods
def createRadiomkListing():
url = 'http://www.radiomk.com/live/'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link = response.read()
response.close()
match = re.compile('<li><a href="(.+?)" rel="dofollow" ><img src="(.+?)" alt=".+?">(.+?)</a></li>').findall(link)
return match
def playRadiomkstream(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('Radiomk Stream', 'Initializing')
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
pDialog.update(30, 'Fetching radio stream')
response = urllib2.urlopen(req)
link = response.read()
response.close()
titlematch = re.compile('<title>(.+?)</title>').findall(link)
streammatch = re.compile("var stream = '(.+?)'").findall(link)
if streammatch == []:
streammatch = re.compile('file=(.+?);').findall(link)
if streammatch == []:
streammatch = re.compile('<embed src="(.+?)"').findall(link)
pDialog.update(60, 'Playing')
playurl(streammatch[0])
pDialog.close()
return True
# TV SITEL methods
def createSitelVideoListing():
url='http://sitel.com.mk/video'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('href="(.+?)" class="video-priloog clearfix">\n<div class="teaser-image"><div class="icon"></div><img src="(.+?)" width=".+?" height=".+?" alt="" /></div>\n<div class="category">.+?</div>\n<h3 class="title">(.+?)</h3>').findall(link)
return match
def playSitelVideo(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('Sitel Video', 'Initializing')
req = urllib2.Request("http://sitel.com.mk"+str(url))
req.add_header('User-Agent', user_agent)
pDialog.update(50, 'Fetching video stream')
response = urllib2.urlopen(req)
link = response.read()
response.close()
filematch = re.compile('file: "(.+?)"').findall(link)
titlematch = re.compile('<title>(.+?)</title>').findall(link)
if filematch[0].__contains__('rtmp'):
rtmpurl = filematch[0]
app=rtmpurl.split('/')[3]+'/'
apos=rtmpurl.find(app)
y=rtmpurl[apos+len(app):]
stream = rtmpurl[:apos+len(app)]+' app='+app+' pageUrl=http://sitel.com.mk swfUrl=http://sitel.com.mk/sites/all/libraries/jw.player/jwplayer.flash.swf playpath='+y+' swfVfy=true'
else:
stream = filematch[0]
pDialog.update(90, 'Playing')
playurl(stream)
pDialog.close()
return True
def playSitelDnevnik():
playurl('rtmp://video.sitel.com.mk/vod/ app=vod/ pageUrl=http://sitel.com.mk swfUrl=http://sitel.com.mk/sites/all/libraries/jw.player/jwplayer.flash.swf playpath=mp4:default/files/dnevnik/dnevnik/dnevnik.mp4 swfVfy=true')
return True
# MTV methods
def createmrtfrontList():
url = 'http://play.mrt.com.mk/'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile('<li class="">\n <a href="(.+?)">\n (.+?) </a>\t\n </li>').findall(link)
return match
def duration_in_minutes(duration):
split_duration=duration.split(':')
minutes=0
for i in range(0, len(split_duration)-1):
minutes = minutes*60 + int(split_duration[i])
return minutes
def list_mrtchannel(url):
url = 'http://play.mrt.com.mk'+url
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
list=[]
match=re.compile('<div class="col-xs-6 col-sm-3 (.+?) content">\n.+?<a href="(.+?)".+?\n.+?<img src="(.+?)".+?\n.+?\n.+?<span class="title gradient">(.+?)</span>').findall(link)
# extract channels
for type,url,thumb,title in match:
list.append([type,url,thumb,'',title])
match=re.compile('<div class="col-xs-6 col-sm-3 (.+?) content">\n.+?<a href="(.+?)".+?\n.+?<img src="(.+?)".+?\n.+?\n.+?<span class="duration">(.+?)</span>\n.+?<span class="title gradient">(.+?)</span>').findall(link)
# extract latest videos on current channel
for type,url,thumb,duration,title in match:
list.append([type,url,thumb,str(duration_in_minutes(duration)),title])
nextpage=''
nextpagestart = link.find('class="next"')
if nextpagestart != -1:
nextpageend = link.find('</div>', nextpagestart)
nextpagematch = re.compile("url:'(.+?)'").findall(link, nextpagestart, nextpageend)
if nextpagematch != []:
nextpage = nextpagematch[0]
return [list, nextpage]
def list_mrtlive():
url = 'http://play.mrt.com.mk/'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
start=link.find('<ul class="dropdown-menu text-left')
end=link.find('</ul', start)
match=re.compile('<a class="channel" href=".+?" data-href="(.+?)" .+? title="(.+?)">\n.*?<img src="(.+?)"').findall(link[start:end])
return match
def playmrtvideo(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('MRT Play live stream', 'Initializing')
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
pDialog.update(50, 'Fetching video stream')
response = urllib2.urlopen(req)
link = response.read()
response.close()
match2=re.compile('"playlist":\[{"url":"(.+?)"').findall(link)
match1 = re.compile('"baseUrl":"(.+?)"').findall(link)
title = re.compile('<meta property="og:title" content="(.+?)"').findall(link)
if match2 != [] and match1 != []:
stream=match1[0]+"/"+match2[0]
stream=stream[:stream.rfind('/')]+'/master.m3u8'
if title != []:
videotitle = title[0]
else:
videotitle = 'MRT Video'
pDialog.update(70, 'Playing')
playurl(stream)
pDialog.close()
elif match2 != []:
stream=match2[0]
if title != []:
videotitle = title[0]
else:
videotitle = 'MRT Video'
pDialog.update(70, 'Playing')
playurl(stream)
pDialog.close()
return True
# OTHER live streams methods
def createOtherListing():
list=[]
list.append(['Al Jazeera Balkans', 'rtmp://aljazeeraflashlivefs.fplive.net/aljazeeraflashlive-live app=aljazeeraflashlive-live swfUrl=http://www.nettelevizor.com/playeri/player.swf pageUrl=http://ex-yu-tv-streaming.blogspot.se playpath=aljazeera_balkans_high live=true swfVfy=true', 'http://balkans.aljazeera.net/profiles/custom/themes/aljazeera_balkans/images/banner.png'])
return list
# HRT Methods
def createHRTSeriesListing():
url='http://www.hrt.hr/enz/'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
start=link.find('<div class="all_shows">')
end=link.find('</div>', start)
match=re.compile('<li><a.+?href="(.+?)"><span>(.+?)</span></a></li>').findall(link[start:end])
return match
def listHRTEpisodes(url):
list=[]
url = url.replace('&', '&')
if url[0:2] == '//':
url = 'http:'+url
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
try:
response = urllib2.urlopen(req)
link = response.read()
response.close()
except:
return list
match=re.compile('<option selected="selected" value="(.+?)">(.+?)<').findall(link)
for value,title in match:
list.append([title.strip(), url+value])
match=re.compile('option value="(.+?)">(.+?)<').findall(link)
for value,title in match:
list.append([title.strip(), url+value])
return list
def playHRTVideo(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('HRT Video', 'Initializing')
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
pDialog.update(50, 'Fetching video stream')
response = urllib2.urlopen(req)
link = response.read()
response.close()
filematch = re.compile('<video data-.+?="(.+?)"').findall(link)
if filematch == []:
filematch = re.compile('<video src="(.+?)"').findall(link)
titlematch = re.compile('<title>(.+?)</title>').findall(link)
if filematch[0].__contains__('youtu.be'):
url = 'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid='+filematch[0].split('/')[-1].strip()
else:
url = filematch[0]
pDialog.update(90, 'Playing')
playurl(url)
pDialog.close()
return True
# serbiaplus methods
def listSerbiaPlusTVs():
htmltext = readurl('http://www.serbiaplus.com')
match=re.compile('<frame src="(.+?)" ').findall(htmltext)
if match != []:
newurl = match[0]
htmltext = readurl(newurl)
else:
newurl='http://www.serbiaplus.com'
match = re.compile('<iframe name="iFrame1" .+? src="(.+?)"').findall(htmltext)
if newurl[-1] != '/':
newurl += '/'
link = readurl(newurl+match[0])
match=re.compile('<a href="(.+?)".+?target="_blank"><div class="wpmd">\n<div align=center><font face=".+?" class="ws12">(.+?)</font></div>').findall(link)
return [newurl, match]
def playSerbiaPlusStream(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('Serbia Plus', 'Initializing')
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
pDialog.update(40, 'Finding stream')
response = urllib2.urlopen(req)
link=response.read()
response.close()
stream = serbiaplussearchurl(link)
if stream == '':
stream=findSerbiaPlusStream(link)
if stream != '':
if stream.__contains__('youtube.com'):
stream = 'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid='+stream.split('=')[-1].strip()
pDialog.update(80, 'Playing')
playurl(stream)
return True
else:
pDialog.close()
return False
def serbiaplussearchurl(intext):
stream = []
if intext.find("file: \"") != -1 or intext.find("file:\"") != -1:
stream=re.compile('file:.*?"(.+?)"').findall(intext)
if intext.find("\"file\"") != -1:
stream=re.compile(', *?"file":"(.+?)"').findall(intext)
if intext.find("'file':") != -1:
stream=re.compile("'file' *?: *?'(.+?)'").findall(intext)
if intext.find("application/x-vlc-plugin") != -1 or intext.find("application/x-google-vlc-plugin") != -1:
start = intext.find("application/x-vlc-plugin")
if start == -1:
start = intext.find("application/x-google-vlc-plugin")
if start > 200:
start -= 200
else:
start = 0
stream=re.compile('target="(.+?)"').findall(intext, start)
if intext.find("streamer=rtmp://") != -1:
tmp=re.compile('file=(.+?)&streamer=(.+?)&').findall(intext)
if tmp != []:
stream = [tmp[0][1]+tmp[0][0]]
if intext.find('flashvars="src') != -1 or intext.find('flashvars="streamer') != -1:
tmp=re.compile('flashvars=".+?=(.+?)"').findall(intext)
if tmp != []:
stream=[urllib.unquote_plus(tmp[0]).strip()]
stream[0]=stream[0].split(' ')[0]
stream[0]=stream[0].split('&')[0]
if stream != []:
return HTMLParser.HTMLParser().unescape(stream[0])
else:
return ''
def decode_serbiaplus_frame(s, splitconst, appendconst, offsetconst):
r = ""
tmp = s.split(splitconst)
s = urllib.unquote(tmp[0])
k = urllib.unquote(tmp[1]+appendconst)
for i in range(0, len(s)):
r = r + chr((int(k[i%len(k)]) ^ ord(s[i])) + offsetconst)
return r
def findSerbiaPlusStream(htmltext):
start = 0
end = -1
searcharea = htmltext[start:]
if searcharea.find("unescape('")!=-1:
start = searcharea.find("unescape('")
end = searcharea.find("')", start)
encframe = searcharea[start+10:end]
decframe = urllib.unquote(encframe)
frame=decframe
else:
frame=searcharea
if frame.__contains__('split("') and frame.__contains__("charCodeAt"):
splitmatch = re.compile('split\("(.+?)"\);').findall(frame)
appendmatch = re.compile('tmp\[1\].*?"(.+?)"').findall(frame)
offsetmatch = re.compile('charCodeAt\(i\)\)\+(.+?)\)').findall(frame)
payloadstart = searcharea.find("eval(unescape('")
payloadstart = searcharea.find("unescape('", payloadstart+16)
payloadstart = searcharea.find("'", payloadstart+11)
payloadstart = searcharea.find("'", payloadstart+2)
payloadend = searcharea.find("'", payloadstart+1)
decframe = decode_serbiaplus_frame(searcharea[payloadstart+1:payloadend], splitmatch[0], appendmatch[0], int(offsetmatch[0]))
frame = decframe
frame=frame.replace('\n', ' ').replace('\r', ' ')
stream=serbiaplussearchurl(frame)
return stream
# volimtv methods
def setVolimtvMailPass():
currentlogindetails = getVolimtvMailPass()
currentuid=''
currentpwd=''
if currentlogindetails != False:
currentuid = currentlogindetails.get('email')
currentpwd = currentlogindetails.get('pass')
kb = xbmc.Keyboard('', 'volim.tv login', False)
kb.setHeading('Enter volim.tv username/email')
kb.setHiddenInput(False)
kb.setDefault(currentuid)
kb.doModal()
if (kb.isConfirmed()):
email=kb.getText()
kb = xbmc.Keyboard('', 'volim.tv login', True)
kb.setHeading('Enter volim.tv password')
kb.setHiddenInput(True)
kb.setDefault(currentpwd)
kb.doModal()
if (kb.isConfirmed()):
passwd=kb.getText()
fwrite(VOLIMTV_UID, email)
fwrite(VOLIMTV_PWD, passwd)
return True
return False
def getVolimtvMailPass():
if os.path.isfile(VOLIMTV_UID):
volimtv_uid = fread(VOLIMTV_UID)
if os.path.isfile(VOLIMTV_PWD):
volimtv_pwd = fread(VOLIMTV_PWD)
return {'email':volimtv_uid, 'pass':volimtv_pwd}
return False
def listVolimtv():
url='http://www.volim.tv/rts-1'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
req.add_header('Accept', str_accept)
response = urllib2.urlopen(req)
link=response.read()
response.close()
match=re.compile("url\(http://volim.tv/images/design/watchlive.png\);' href='(.+?)'>(.+?)</a></li>").findall(link)
return match
def playvolimtvurl(url):
logindata = getVolimtvMailPass()
if logindata == False:
xbmcgui.Dialog().ok('Macedonia On Demand', 'Wrong username or password.', 'Register on http://volim.tv', 'And edit Settings on this page')
return False
loginurl='http://volim.tv/includes/ajax/login.php'
pDialog = xbmcgui.DialogProgress()
pDialog.create('volim.tv', 'Initializing')
pDialog.update(30, 'Verifying userid and password')
req = urllib2.Request(loginurl)
req.add_header('User-Agent', user_agent)
req.add_header('Accept', str_accept)
req.add_data(urllib.urlencode(logindata))
response = urllib2.urlopen(req)
link=response.read()
response.close()
if link.find('location.reload();') == -1:
pDialog.close()
xbmcgui.Dialog().ok('Macedonia On Demand', 'Wrong username or password.', 'Register on http://volim.tv', 'And edit Settings on this page')
return False
cookiestr = response.info().get('set-cookie')
pDialog.update(50, 'Fetching video stream')
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
req.add_header('Accept', str_accept)
req.add_header('Cookie', cookiestr)
response = urllib2.urlopen(req)
link = response.read()
response.close()
match=re.compile("ipadUrl: '(.+?)'").findall(link)
if match == []:
match = re.compile('"application/x-mpegurl".*?src="(.+?)"').findall(link)
if match != []:
stream_url = match[0]
if stream_url[0:7] != 'http://':
stream_url = 'http://edge3.volim.tv/live/'+stream_url
pDialog.update(90, 'Playing')
playurl(stream_url)
pDialog.close()
return True
# netraja methods
def listNetrajaCategories():
url='http://zabavanet.blogspot.com/'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link=response.read()
response.close()
start = link.find('TV KANALI</a>')
end = link.find('</ul>', start)
match=re.compile("<a href='(.+?)'>(.+?)</a>").findall(link[start:end])
return match
def listNetrajaTvs(url):
category = url.split('/')[-1]
url = 'http://zabavanet.blogspot.com/feeds/posts/summary/-/'+category+'?start-index=1&max-results=200&alt=json'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
data = json.load(response)
response.close()
if data.get('feed'):
t=data['feed']
if t.get('entry'):
return t['entry']
return {}
def playNetrajaStream(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('Netraja', 'Initializing')
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
pDialog.update(50, 'Finding stream')
response = urllib2.urlopen(req)
link = response.read()
response.close()
start = link.find("<div class='post-body entry-content'")
end = link.find("<div style='clear: both;'></div>", start)
stream=serbiaplussearchurl(link[start:end])
if stream == '':
if link[start:end].find("www.youtube.com/embed/") != -1:
match=re.compile('www.youtube.com/embed/(.+?)"').findall(link[start:end])
if match != []:
stream='plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid='+match[0]
if stream != '':
if stream.__contains__('youtube.com'):
stream = 'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid='+stream.split('=')[-1].strip()
pDialog.update(80, 'Playing')
playurl(stream)
pDialog.close()
return True
# rts methods
def playrtsvideo(url):
pDialog = xbmcgui.DialogProgress()
pDialog.create('RTS', 'Initializing')
req = urllib2.Request('http://www.rts.rs'+url)
req.add_header('User-Agent', user_agent)
pDialog.update(30, 'Finding stream')
response = urllib2.urlopen(req)
link = response.read()
response.close()
box = re.compile('<div class=\'boxFull\'>.*?<box box-left (.+?) box>').findall(link)
if box == []:
pDialog.close()
return False
url = 'http://www.rts.rs/boxes/boxBox.jsp?boxId='+box[0]
content = readurl(url)
pDialog.update(60, 'Finding stream')
match = re.compile('src="(.+?)"').findall(content)
stream = ''
if match[0].__contains__('youtube'):
stream = 'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid='+match[0].split('/')[-1].split('?')[0]
if stream != '':
pDialog.update(80, 'Playing')
playurl(stream)
pDialog.close()
return True
pDialog.close()
return False
# prvatv methods
def listPrvaTvCategories():
url = 'http://www.prva.rs/web-tv.html'
req = urllib2.Request(url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link = response.read()
response.close()
link = link.replace('\n', '').replace('\r', '').replace('<span class=" ">', '').replace('</span>', '')
start = link.find('<div class="horizontalSubNavigation fix">')
end = link.find('</div>', start)
match = re.compile('<a href="(.+?)".+?>(.+?)</a>').findall(link[start:end])
return match
def listPrvaTvSeries_old(url):
req = urllib2.Request('http://www.prva.rs'+url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link = response.read()
response.close()
link = link.replace('\n', '').replace('\r', '').replace('<span class=" ">', '').replace('</span>', '')
start = link.find('<li class=" depth3 first">')
if start == -1:
start = link.find('div id="topFullDepth3"')
end = link.find('</div>', start)
match = re.compile('<a href="(.+?)".+?>(.+?)</a>').findall(link[start:end])
return match
def listPrvaTvSeries(url):
req = urllib2.Request('http://www.prva.rs'+url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link = response.read()
response.close()
link = link.replace('\n', '').replace('\r', '').replace('<span class=" ">', '').replace('</span>', '')
start = link.find('div class="primary-content"')
match = re.compile('<div class="children-box hero-item red">.+?<img src="(.+?)".+?>.+?<h3><a href="(.+?)">(.+?)</a>').findall(link[start:])
return match
def listPrvaTvEpisodes(url):
req = urllib2.Request('http://www.prva.rs'+url)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link = response.read()
response.close()
link = link.replace('\n', '').replace('\r', '').replace('<span class=" ">', '').replace('</span>', '')
start = link.find('class="mediaTitle"')
match = re.compile('<a class="mediumThumb fix" href="(.+?)" title="(.+?)">.+?<img src="(.+?)"').findall(link[start:])
return match
def listPrvaTvMode2frontvideos(baseurl):
req = urllib2.Request(baseurl)
req.add_header('User-Agent', user_agent)
response = urllib2.urlopen(req)
link = response.read()
response.close()
link = link.replace('\n', '').replace('\r', '')
match = re.compile('<a class="largeThumb fix" href="(.+?)" title="(.+?)">.+?<img src="(.+?)"').findall(link)