forked from ilikenwf/plugin.video.rumble.matrix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
1039 lines (744 loc) · 34.1 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
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 -*-
import sys
import re
import os
import xbmc
import xbmcplugin
import xbmcgui
import xbmcaddon
import xbmcvfs
import six
from six.moves import urllib
from lib.general import *
from lib.rumble_user import RumbleUser
from lib.comments import CommentWindow
try:
import json
except ImportError:
import simplejson as json
BASE_URL = 'https://rumble.com'
PLUGIN_URL = sys.argv[0]
PLUGIN_ID = int(sys.argv[1])
PLUGIN_NAME = PLUGIN_URL.replace('plugin://','')
ADDON = xbmcaddon.Addon()
ADDON_ICON = ADDON.getAddonInfo('icon')
ADDON_NAME = ADDON.getAddonInfo('name')
HOME_DIR = 'special://home/addons/' + PLUGIN_NAME
RESOURCE_DIR = HOME_DIR + 'resources/'
MEDIA_DIR = RESOURCE_DIR + 'media/'
DATE_FORMAT = ADDON.getSetting('date_format')
RUMBLE_USER = RumbleUser()
if six.PY2:
favorites = xbmc.translatePath(os.path.join(ADDON.getAddonInfo('profile'), 'favorites.dat'))
else:
favorites = xbmcvfs.translatePath(os.path.join(ADDON.getAddonInfo('profile'), 'favorites.dat'))
def favorites_create():
""" creates favorite directory if doesn't exist """
if six.PY2:
addon_data_path = xbmc.translatePath(ADDON.getAddonInfo('profile'))
else:
addon_data_path = xbmcvfs.translatePath(ADDON.getAddonInfo('profile'))
if os.path.exists(addon_data_path) is False:
os.mkdir(addon_data_path)
xbmc.sleep(1)
def favorites_load( return_string = False ):
""" load favourites from file into variable """
if os.path.exists( favorites ):
fav_str = open( favorites ).read()
if return_string:
return fav_str
if fav_str:
return json.loads( fav_str )
else:
favorites_create()
# nothing to load, return type necessary
if return_string:
return ''
return []
def to_unicode( text, encoding='utf-8', errors='strict' ):
""" Forces text to unicode """
if isinstance(text, bytes):
return text.decode(encoding, errors=errors)
return text
def get_search_string( heading='', message='' ):
""" Ask the user for a search string """
search_string = None
keyboard = xbmc.Keyboard(message, heading)
keyboard.doModal()
if keyboard.isConfirmed():
search_string = to_unicode(keyboard.getText())
return search_string
def home_menu():
""" Creates home menu """
# Search
add_dir( get_string(137), '', 1, { 'thumb': 'search.png' } )
# Favorites
add_dir( get_string(1036), '', 7, { 'thumb': 'favorite.png' } )
if RUMBLE_USER.has_login_details():
# Subscriptions
add_dir( 'Subscriptions', BASE_URL + '/subscriptions', 3, { 'thumb': 'favorite.png' }, {}, 'subscriptions' )
# Following
add_dir( 'Following', BASE_URL + '/followed-channels', 3, { 'thumb': 'favorite.png' }, {}, 'following' )
# Watch Later
add_dir( 'Watch Later', BASE_URL + '/playlists/watch-later', 3, { 'thumb': 'favorite.png' }, {}, 'playlist' )
# Battle Leaderboard
add_dir( get_string(30050), BASE_URL + '/battle-leaderboard/recorded', 3, { 'thumb': 'leader.png' }, {}, 'top' )
# Categories
add_dir( get_string(30051), BASE_URL + '/browse', 3, { 'thumb': 'viral.png' }, {}, 'cat_list' )
# Live Streams
add_dir( get_string(30052), BASE_URL + '/browse/live', 3, { 'thumb': 'viral.png' }, {}, 'live_stream' )
# Settings
add_dir( get_string(5), '', 8, { 'thumb': 'settings.png' } )
xbmcplugin.endOfDirectory( PLUGIN_ID, cacheToDisc=False )
def search_menu():
""" Creates search menu """
# Search Video
add_dir( get_string(30100), BASE_URL + '/search/video?q=', 2, { 'thumb': 'search.png' }, {}, 'video' )
# Search Channel
add_dir( get_string(30101), BASE_URL + '/search/channel?q=', 2, { 'thumb': 'search.png' }, {}, 'channel' )
# Search User
add_dir( get_string(30102), BASE_URL + '/search/channel?q=', 2, { 'thumb': 'search.png' }, {}, 'user' )
xbmcplugin.endOfDirectory(PLUGIN_ID)
def pagination( url, page, cat, search=False ):
""" list directory items then show pagination """
if url > '':
page = int(page)
page_url = url
paginated = True
if page == 1:
if search:
page_url = url + search
elif search and cat == 'video':
page_url = url + search + "&page=" + str( page )
elif cat in {'channel', 'cat_video', 'user', 'other', 'subscriptions', 'live_stream' }:
page_url = url + "?page=" + str( page )
if cat in { 'following', 'top', 'cat_list' }:
paginated = False
amount = list_rumble( page_url, cat )
if paginated and amount > 15 and page < 10:
# for next page
page = page + 1
name = get_string(30150) + " " + str( page )
list_item = xbmcgui.ListItem(name)
link_params = {
'url': url,
'mode': '3',
'name': name,
'page': str( page ),
'cat': cat,
}
link = build_url( link_params )
if search and cat == 'video':
link = link + "&search=" + urllib.parse.quote_plus(search)
xbmcplugin.addDirectoryItem(PLUGIN_ID, link, list_item, True)
xbmcplugin.endOfDirectory(PLUGIN_ID)
def get_image( data, image_id ):
""" method to get an image from scraped page's CSS from the image ID """
image_re = re.compile(
"i.user-image--img--id-" + str( image_id ) + ".+?{\s*background-image: url(.+?);",
re.MULTILINE|re.DOTALL|re.IGNORECASE
).findall(data)
if image_re != []:
image = str(image_re[0]).replace('(', '').replace(')', '')
else:
image = ''
return image
def list_rumble( url, cat ):
""" Method to get and display items from Rumble """
amount = 0
headers = None
if 'subscriptions' in url or cat == 'following':
# make sure there is a session
# result is stored in a cookie
RUMBLE_USER.has_session()
data = request_get(url, None, headers)
# Fix for favorites & search
if cat in { 'other', 'channel' } and '/c/' in url:
cat = 'channel_video'
if 'search' in url:
if cat == 'video':
amount = dir_list_create( data, cat, 'video', True, 1 )
else:
amount = dir_list_create( data, cat, 'channel', True )
elif cat in { 'subscriptions', 'cat_video', 'live_stream', 'playlist' }:
amount = dir_list_create( data, cat, cat, False, 2 )
elif cat in { 'channel', 'top', 'other' }:
amount = dir_list_create( data, cat, 'video', False, 2 )
elif cat in { 'channel_video', 'user' }:
amount = dir_list_create( data, cat, 'channel_video', False, 2 )
elif cat == 'following':
amount = dir_list_create( data, cat, 'following', False, 2 )
elif cat == 'cat_list':
amount = dir_list_create( data, cat, cat, False )
return amount
def dir_list_create( data, cat, video_type='video', search = False, play=0 ):
""" create and display dir list based upon type """
amount = 0
one_line_titles = ADDON.getSetting('one_line_titles') == 'true'
if video_type == 'video':
videos = re.compile(r'href=\"([^\"]+)\"><div class=\"(?:[^\"]+)\"><img\s*class=\"video-item--img\"\s*src=\"([^\"]+)\"\s*alt=\"(?:[^\"]+)\"\s*>(?:<span class=\"video-item--watching\">[^\<]+</span>)?(?:<div class=video-item--overlay-rank>(?:[0-9]+)</div>)?</div><(?:[^\>]+)></span></a><div class=\"video-item--info\"><time class=\"video-item--meta video-item--time\" datetime=(.+?)-(.+?)-(.+?)T(?:.+?) title\=\"(?:[^\"]+)\">(?:[^\<]+)</time><h3 class=video-item--title>(.+?)</h3><address(?:[^\>]+)><a rel=author class=\"(?:[^\=]+)=(.+?)><div class=ellipsis-1>(.+?)</div>', re.MULTILINE|re.DOTALL|re.IGNORECASE).findall(data)
if videos:
amount = len(videos)
for link, img, year, month, day, title, channel_link, channel_name in videos:
info_labels = {}
if '<svg' in channel_name:
channel_name = channel_name.split('<svg')[0] + " (Verified)"
info_labels[ 'year' ] = year
video_title = '[B]' + clean_text( title ) + '[/B]'
video_title += ' - ' if one_line_titles else '\n'
video_title += '[COLOR gold]' + channel_name + '[/COLOR] - [COLOR lime]' + get_date_formatted( DATE_FORMAT, year, month, day ) + '[/COLOR]'
images = { 'thumb': str(img), 'fanart': str(img) }
#open get url and open player
add_dir( video_title, BASE_URL + link, 4, images, info_labels, cat, False, True, play, { 'name' : channel_link, 'subscribe': True } )
elif video_type in { 'cat_video', 'subscriptions', 'live_stream', 'channel_video', 'playlist' }:
if video_type == 'live_stream':
videos_regex = r'<div class=\"thumbnail__grid\"\s*role=\"list\">(.*)<nav class=\"paginator\">'
elif video_type == 'playlist':
videos_regex = r'<ol\s*class=\"videostream__list\"(?:[^>]+)>(.*)</ol>'
else:
videos_regex = r'<ol\s*class=\"thumbnail__grid\">(.*)</ol>'
videos = re.compile(videos_regex, re.DOTALL|re.IGNORECASE).findall(data)
if videos:
if video_type == 'playlist':
videos = videos[0].split('"videostream videostream__list-item')
else:
videos = videos[0].split('"videostream thumbnail__grid-')
videos.pop(0)
amount = len(videos)
for video in videos:
video_title = ''
images = {}
info_labels = {}
subscribe_context = False
title = re.compile(r'<h3(?:[^\>]+)?>(.*)</h3>', re.DOTALL|re.IGNORECASE).findall(video)
link = re.compile(r'<a\sclass="videostream__link link"\sdraggable="false"\shref="([^\"]+)">', re.DOTALL|re.IGNORECASE).findall(video)
img = re.compile(r'<img\s*class=\"thumbnail__image\"\s*draggable=\"false\"\s*src=\"([^\"]+)\"', re.DOTALL|re.IGNORECASE).findall(video)
if title:
video_title = '[B]' + clean_text( title[0] ) + '[/B]'
if 'videostream__status--live' in video:
video_title += ' [COLOR red](Live)[/COLOR]'
if 'videostream__status--upcoming' in video:
video_title += ' [COLOR yellow](Upcoming)[/COLOR]'
channel_name = re.compile(r'<span\sclass="channel__name(?:[^\"]+)" title="(?:[^\"]+)">([^\<]+)</span>(\s*<svg class=channel__verified)?', re.DOTALL|re.IGNORECASE).findall(video)
channel_link = re.compile(r'<a\s*rel=\"author\"\s*class=\"channel__link\slink\s(?:[^\"]+)\"\s*href=\"([^\"]+)\"\s*>', re.DOTALL|re.IGNORECASE).findall(video)
if channel_name:
video_title += ' - ' if one_line_titles else '\n'
video_title += '[COLOR gold]' + clean_text( channel_name[0][0] )
if channel_name[0][1]:
video_title += " (Verified)"
video_title += '[/COLOR]'
if channel_link:
subscribe_context = { 'name' : channel_link[0], 'subscribe': True }
date_time = re.compile(r'<time\s*class=\"(?:[^\"]+)\"\s*datetime=\"(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})-(\d{2}):(\d{2})\"', re.DOTALL|re.IGNORECASE).findall(video)
if date_time:
info_labels[ 'year' ] = date_time[0][0]
video_title += ' - [COLOR lime]' + get_date_formatted( DATE_FORMAT, date_time[0][0], date_time[0][1], date_time[0][2] ) + '[/COLOR]'
if img:
images = { 'thumb': str(img[0]), 'fanart': str(img[0]) }
duration = re.compile(r'videostream__status--duration\"\s*>([^<]+)</div>', re.DOTALL|re.IGNORECASE).findall(video)
if duration:
info_labels[ 'duration' ] = duration_to_secs( duration[0].strip() )
#open get url and open player
add_dir( video_title, BASE_URL + link[0], 4, images, info_labels, cat, False, True, play, subscribe_context )
return amount
elif video_type == 'cat_list':
cat_list = re.compile(r'<a\s*class=\"category__link link\"\s*href=\"([^\"]+)\"\s*>\s*<img\s*class=\"category__image\"\s*src=\"([^\"]+)\"\s*alt=(?:[^\>]+)>\s*<strong class=\"category__title\">([^\<]+)</strong>', re.DOTALL|re.IGNORECASE).findall(data)
if cat_list:
amount = len(cat_list)
for link, img, title in cat_list:
cat = 'channel_video'
images = { 'thumb': str(img), 'fanart': str(img) }
#open get url and open player
add_dir( clean_text( title ), BASE_URL + link.strip() + '/videos', 3, images, {}, cat )
elif video_type == 'following':
videos_regex = r'<ol\s*class=\"followed-channels__list\">(.*)</ol>'
videos = re.compile(videos_regex, re.DOTALL|re.IGNORECASE).findall(data)
if videos:
videos = videos[0].split('"followed-channel flex items-')
videos.pop(0)
amount = len(videos)
for video in videos:
video_title = ''
images = {}
title = re.compile(r'<span\s*class=\"line-clamp-2\">([^<]+)<\/span>', re.DOTALL|re.IGNORECASE).findall(video)
followers = re.compile(r'<div\s*class=\"followed-channel__followers(?:[^\"]+)\">([^<]+)</div>', re.DOTALL|re.IGNORECASE).findall(video)
link = re.compile(r'<a\s*class=\"(?:[^\"]+)\"\s*href=\"(\/(?:c|user)\/[^\"]+)\"\s*>', re.DOTALL|re.IGNORECASE).findall(video)
img = re.compile(r'<(?:img|span)\s*class=\"channel__avatar([^\"]+)\"\s*(?:src=\"([^\"]+)\")?', re.DOTALL|re.IGNORECASE).findall(video)
if title:
video_title = '[B]' + clean_text( title[0] ) + '[/B]'
if '<use href="#channel_verified" />' in video:
video_title += ' [COLOR gold](Verified)[/COLOR]'
link = link[0] if link else ""
if img:
if 'channel__letter' in img[0][0]:
if title:
image_url = MEDIA_DIR + 'letters/' + title[0][0].lower() + '.png'
else:
image_url = ''
else:
image_url = img[0][1]
images = { 'thumb': str(image_url), 'fanart': str(image_url) }
if 'channel__live' in img[0][0]:
video_title += ' [COLOR red](Live)[/COLOR]'
if followers:
video_title += ' - ' if one_line_titles else '\n'
video_title += '[COLOR green]' + followers[0].strip() + '[/COLOR]'
cat = 'user'
if '/user/' not in link:
cat = 'channel_video'
#open get url and open player
add_dir( video_title, BASE_URL + link, 3, images, {}, cat, True, True, play, { 'name' : link, 'subscribe': False } )
else:
channels_regex = r'<div class="main-and-sidebar">(.*)<nav class="paginator">'
channels = re.compile(channels_regex, re.DOTALL|re.IGNORECASE).findall(data)
if channels:
channels = channels[0].split('<article')
channels.pop(0)
amount = len(channels)
for channel in channels:
link = re.compile(r'<a\shref=([^\s]+)\sclass=\"(?:[^\"]+)\">', re.DOTALL|re.IGNORECASE).findall(channel)
link = link[0] if link else ""
xbmc.log( json.dumps(link), xbmc.LOGWARNING )
# split channel and user
if search:
if cat == 'channel':
if '/c/' not in link:
continue
else:
if '/user/' not in link:
continue
images = {}
channel_name = re.compile(r'<span\sclass=\"block\struncate\">([^<]+)<\/span>', re.DOTALL|re.IGNORECASE).findall(channel)
channel_name = channel_name[0] if channel_name else ""
is_verified = re.compile(r'<title>Verified</title>', re.DOTALL|re.IGNORECASE).findall(channel)
is_verified = True if is_verified else False
followers = re.compile(r'<span\sclass=\"(?:[^\"]+)\">\s+([^&]+) Follower(?:s)?\s+</span>', re.DOTALL|re.IGNORECASE).findall(channel)
followers = followers[0] if followers else "0"
img_id = re.compile(r'user-image--img--id-([^\s]+)\s', re.DOTALL|re.IGNORECASE).findall(channel)
img_id = img_id[0] if img_id else ""
if img_id:
img = str( get_image( data, img_id ) )
else:
img = MEDIA_DIR + 'letters/' + channel_name[0] + '.png'
images = { 'thumb': str(img), 'fanart': str(img) }
video_title = '[B]' + channel_name + '[/B]'
if is_verified:
video_title += ' [COLOR gold](Verified)[/COLOR]'
video_title += ' - ' if one_line_titles else '\n'
video_title += '[COLOR palegreen]' + followers + '[/COLOR] [COLOR yellow]' + get_string(30156) + '[/COLOR]'
#open get url and open player
add_dir( video_title, BASE_URL + link, 3, images, {}, cat, True, True, play, { 'name' : link, 'subscribe': True } )
return amount
def get_video_id( url ):
"""
gets a video id from a URL
helps in resolving
"""
data = request_get(url)
# gets embed id from embed url
video_id = re.compile(
',\"embedUrl\":\"' + BASE_URL + '/embed/(.*?)\/\",',
re.MULTILINE|re.DOTALL|re.IGNORECASE
).findall(data)
if video_id:
return video_id[0]
return False
def get_playlist_video_id( url ):
"""
gets a playlist video id from a URL
helps in adding video to playlist
"""
data = request_get(url)
# gets embed id from embed url
video_id = re.compile(
'data-id=\"([0-9]+)\"',
re.MULTILINE|re.DOTALL|re.IGNORECASE
).findall(data)
if video_id:
return video_id[0]
return False
def resolver( url ):
""" Resolves a URL for rumble & returns resolved link to video """
# playback options - 0: high auto, 1: low auto, 2: quality select
playback_method = int( ADDON.getSetting('playbackMethod') )
media_url = False
if playback_method > 0:
urls = []
video_id = get_video_id( url )
if video_id:
# use site api to get video urls
# TODO: use as dict / array instead of using regex to get URLs
data = request_get(BASE_URL + '/embedJS/u3/?request=video&ver=2&v=' + video_id)
sizes = [ '1080', '720', '480', '360', 'hls' ]
for quality in sizes:
# get urls for quality
matches = re.compile(
'"' + quality + '".+?url.+?:"(.*?)"',
re.MULTILINE|re.DOTALL|re.IGNORECASE
).findall(data)
if matches:
if playback_method > 0:
urls.append(( quality, matches[0] ))
else:
media_url = matches[0]
break
# if not automatically selecting highest quality
if int( playback_method ) > 0:
# m3u8 check
if len( urls ) == 1 and '.m3u8' in urls[0][1]:
from lib.m3u8 import m3u8
m3u8_handler = m3u8()
urls = m3u8_handler.process( request_get( urls[0][1] ) )
# reverses array - small to large
if playback_method == 1:
urls = urls[::-1]
media_url = urls[0][1]
# quality select
elif playback_method == 2:
if len(urls) > 0:
if len(urls) == 1:
# if only one available, no point asking
selected_index = 0
else:
selected_index = xbmcgui.Dialog().select(
'Select Quality', [(sourceItem[0] or '?') for sourceItem in urls]
)
if selected_index != -1:
media_url = urls[selected_index][1]
if media_url:
media_url = media_url.replace('\/', '/')
return media_url
def play_video( name, url, thumb, play=2 ):
""" method to play video """
# get video link
url = resolver(url)
if url:
# Use HTTP
if ADDON.getSetting('useHTTP') == 'true':
url = url.replace('https://', 'http://', 1)
list_item = xbmcgui.ListItem(name, path=url)
list_item.setArt({'icon': thumb, 'thumb': thumb})
info_labels={ 'Title': name, 'plot': '' }
item_set_info( list_item, info_labels )
if play == 1:
xbmc.Player().play(item=url, listitem=list_item)
elif play == 2:
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, list_item)
else:
xbmcgui.Dialog().ok( 'Error', 'Video not found' )
def search_items( url, cat ):
""" Searches rumble """
search_str = get_search_string(heading="Search")
if not search_str:
return
title = urllib.parse.quote_plus(search_str)
pagination( url, 1, cat, title )
def favorites_show():
""" Displays favorites """
data = favorites_load()
try:
amount = len(data)
if amount > 0:
for i in data:
name = i[0]
url = i[1]
mode = i[2]
images = { 'thumb': str(i[3]), 'fanart': str(i[4]) }
info_labels = { 'plot': str(i[5]) }
cat = i[6]
folder = ( i[7] == 'True' )
play = i[8]
add_dir( name, url, mode, images, info_labels, cat, folder, True, int(play) )
xbmcplugin.endOfDirectory(PLUGIN_ID)
else:
xbmcgui.Dialog().ok( get_string(14117), get_string(30155) )
except Exception:
xbmcplugin.endOfDirectory(PLUGIN_ID)
def favorite_add(name, url, fav_mode, thumb, fanart, plot, cat, folder, play):
""" add favorite from name """
data = favorites_load()
data.append((name, url, fav_mode, thumb, fanart, plot, cat, folder, play))
fav_file = open( favorites, 'w' )
fav_file.write(json.dumps(data))
fav_file.close()
notify( get_string(30152), name, thumb )
def favorite_remove( name ):
""" remove favorite from name """
# TODO: remove via something more unique instead
# TODO: remove via a method that doesn't require to loop through all favorites
data = favorites_load()
if data:
for index in range(len(data)):
if data[index][0] == name:
del data[index]
fav_file = open( favorites, 'w' )
fav_file.write(json.dumps(data))
fav_file.close()
break
notify( get_string(30154), name )
def favorites_import():
""" Due to plugin name change from original fork, the favorites will need to be imported """
if not xbmcgui.Dialog().yesno(
'Import Favorites',
'This will replace the favorites with the plugin.video.rumble.matrix version.\nProceed?',
nolabel = 'Cancel',
yeslabel = 'Ok'
):
return
# no point trying to run this as it didn't exist for python 2
if six.PY2:
notify( 'Favorites Not Found' )
return
# make sure path exists
favorites_create()
#load matrix favourites
rumble_matrix_dir = xbmcvfs.translatePath(os.path.join('special://home/userdata/addon_data/plugin.video.rumble.matrix', 'favorites.dat'))
if os.path.exists(rumble_matrix_dir):
rumble_matrix = open( rumble_matrix_dir ).read()
if rumble_matrix:
fav_file = open( favorites, 'w' )
fav_file.write(rumble_matrix)
fav_file.close()
notify( 'Imported Favorites' )
return
notify( 'Favorites Not Found' )
def login_session_reset():
""" Forces a rumble session reset """
RUMBLE_USER.reset_session_details()
# Session Reset
notify( get_string(30200) )
def login_test():
""" Method that resets session, then tests the login """
RUMBLE_USER.reset_session_details()
if RUMBLE_USER.has_login_details():
if RUMBLE_USER.login():
# Login Success
notify( get_string(30201) )
else:
# Login Failed
notify( get_string(30202) )
else:
# No details detected
notify( get_string(30203) )
def subscribe( name, action ):
""" Attempts to (un)subscribe to rumble channel """
# make sure we have a session
if RUMBLE_USER.has_session():
action_type = False
if '/user/' in name:
name = name.replace( '/user/', '' )
action_type = 'user'
elif '/c/' in name:
name = name.replace( '/c/', '' )
action_type = 'channel'
if action_type:
# subscribe to action
data = RUMBLE_USER.subscribe( action, action_type, name )
if data:
# Load data from JSON
data = json.loads(data)
# make sure everything looks fine
if data.get( 'user', False ) and data.get( 'data', False ) \
and data[ 'user' ][ 'logged_in' ] and data[ 'data' ][ 'thumb' ]:
if action == 'subscribe':
notify( 'Subscribed to ' + name, None, data[ 'data' ][ 'thumb' ] )
else:
notify( 'Unubscribed to ' + name, None, data[ 'data' ][ 'thumb' ] )
return True
notify( 'Unable to to perform action' )
return False
def add_dir( name, url, mode, images = {}, info_labels = {}, cat = '', folder=True, fav_context=False, play=0, subscribe_context=False ):
""" Adds directory items """
art_dict = {
'thumb': images.get( 'thumb', HOME_DIR + 'icon.png' ),
'fanart': images.get( 'fanart', HOME_DIR + 'fanart.jpg' ),
}
# set default image location to MEDIA_DIR
for art_type, art_loc in art_dict.items():
if art_loc:
if not art_loc.startswith( HOME_DIR ) and \
not art_loc.startswith( 'http' ) and \
not art_loc.startswith( '\\' ):
art_dict[ art_type ] = MEDIA_DIR + art_dict[ art_type ]
link_params = {
'url': url,
'mode': str( mode ),
'name': name,
'thumb': art_dict[ 'thumb' ],
'fanart': art_dict[ 'fanart' ],
'plot': info_labels.get( 'plot', '' ),
'cat': cat,
}
context_menu = []
if play:
link_params['play'] = str( play )
link = build_url( link_params )
list_item = xbmcgui.ListItem( name )
if folder:
list_item.setArt({'icon': 'DefaultFolder.png', 'thumb': art_dict[ 'thumb' ]})
else:
list_item.setArt({'icon': 'DefaultVideo.png', 'thumb': art_dict[ 'thumb' ]})
xbmcplugin.setContent(PLUGIN_ID, 'videos')
if play == 2 and mode == 4:
list_item.setProperty('IsPlayable', 'true')
context_menu.append((get_string(30158), 'Action(Queue)'))
if RUMBLE_USER.has_login_details():
# need to get current
params=get_params()
current_url = params.get( 'url', None )
if '/playlists/watch-later' in current_url:
# delete watch later context
context_menu.append(('Delete from Watch Later','RunPlugin(%s)' % build_url( {'mode': '12','url': url, 'cat':'delete'} )))
else:
# add watch later context
context_menu.append(('Add to Watch Later','RunPlugin(%s)' % build_url( {'mode': '12','url': url, 'cat':'add'} )))
info_labels['title'] = name
if play:
# adds information context menu
info_labels['mediatype'] = 'tvshow'
item_set_info( list_item, info_labels )
list_item.setProperty( 'fanart_image', art_dict[ 'fanart' ] )
if RUMBLE_USER.has_login_details():
if subscribe_context:
if subscribe_context['subscribe']:
context_menu.append(('Subscribe to ' + subscribe_context['name'],'RunPlugin(%s)' % build_url( {'mode': '11','name': subscribe_context['name'], 'cat': 'subscribe'} )))
else:
context_menu.append(('Unsubscribe to ' + subscribe_context['name'],'RunPlugin(%s)' % build_url( {'mode': '11','name': subscribe_context['name'], 'cat': 'unsubscribe'} )))
if play == 2 and mode == 4:
context_menu.append(('Comments','RunPlugin(%s)' % build_url( {'mode': '13','url': url} )))
if fav_context:
favorite_str = favorites_load( True )
try:
name_fav = json.dumps(name)
except Exception:
name_fav = name
try:
# checks fav name via string (I do not like how this is done, so will redo in future)
if name_fav in favorite_str:
context_menu.append((get_string(30153),'RunPlugin(%s)' % build_url( {'mode': '6','name': name} )))
else:
fav_params = {
'url': url,
'mode': '5',
'name': name,
'thumb': art_dict[ 'thumb' ],
'fanart': art_dict[ 'fanart' ],
'plot': info_labels.get( 'plot', '' ),
'cat': cat,
'folder': str(folder),
'fav_mode': str(mode),
'play': str(play),
}
context_menu.append((get_string(30151),'RunPlugin(%s)' %build_url( fav_params )))
except Exception:
pass
if context_menu:
list_item.addContextMenuItems(context_menu)
xbmcplugin.addDirectoryItem(handle=PLUGIN_ID, url=link, listitem=list_item, isFolder=folder)
def playlist_manage( url, action="add" ):
""" Adds to Rumble's Playlist """
video_id = get_playlist_video_id( url )
if video_id:
if action == "add":
RUMBLE_USER.playlist_add_video( video_id )
message = "Added to playlist"
else:
RUMBLE_USER.playlist_delete_video( video_id )
message = "Deleted from playlist"
else:
if action == "add":
message = "Cannot add to playlist"
else:
message = "Cannot delete from playlist"
notify( message, "Playlist" )
def comments_show( url ):
""" Retrieves and shows video's comments in a modal """
video_id = get_video_id( url )
if video_id:
win = CommentWindow(
'addon-rumble-comments.xml',
ADDON.getAddonInfo('path'),
'default',
video_id=video_id
)
win.doModal()
del win
else:
notify( "Cannot find comments", "Comments" )
def main():
""" main method to start plugin """
params=get_params()
mode=int(params.get( 'mode', 0 ))
page=int(params.get( 'page', 1 ))
play=int(params.get( 'play', 0 ))
fav_mode=int(params.get( 'fav_mode', 0 ))
url = params.get( 'url', None )
if url:
url=urllib.parse.unquote_plus(url)
name = params.get( 'name', None )
if name:
name = urllib.parse.unquote_plus(name)
thumb=params.get( 'thumb', None )
if thumb:
thumb=urllib.parse.unquote_plus(thumb)
fanart=params.get( 'fanart', None )
if fanart:
fanart=urllib.parse.unquote_plus(fanart)
plot=params.get( 'plot', None )
if plot:
plot=urllib.parse.unquote_plus(plot)
subtitle=params.get( 'subtitle', None )
if subtitle:
subtitle=urllib.parse.unquote_plus(subtitle)
cat=params.get( 'cat', None )
if cat:
cat=urllib.parse.unquote_plus(cat)
search=params.get( 'search', None )
if search:
search=urllib.parse.unquote_plus(search)
folder=params.get( 'folder', None )
if folder:
folder=urllib.parse.unquote_plus(folder)
folder=params.get( 'folder', None )
if folder:
folder=urllib.parse.unquote_plus(folder)
if mode==0:
home_menu()